microhttpd2.h (396957B)
1 /* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */ 2 /* 3 This file is part of GNU libmicrohttpd. 4 Copyright (C) 2006-2026 Christian Grothoff, Karlson2k (Evgeny Grin) 5 (and other contributing authors) 6 7 GNU libmicrohttpd is free software; you can redistribute it and/or 8 modify it under the terms of the GNU Lesser General Public 9 License as published by the Free Software Foundation; either 10 version 2.1 of the License, or (at your option) any later version. 11 12 GNU libmicrohttpd is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Lesser General Public License for more details. 16 17 Alternatively, you can redistribute GNU libmicrohttpd and/or 18 modify it under the terms of the GNU General Public License as 19 published by the Free Software Foundation; either version 2 of 20 the License, or (at your option) any later version, together 21 with the eCos exception, as follows: 22 23 As a special exception, if other files instantiate templates or 24 use macros or inline functions from this file, or you compile this 25 file and link it with other works to produce a work based on this 26 file, this file does not by itself cause the resulting work to be 27 covered by the GNU General Public License. However the source code 28 for this file must still be made available in accordance with 29 section (3) of the GNU General Public License v2. 30 31 This exception does not invalidate any other reasons why a work 32 based on this file might be covered by the GNU General Public 33 License. 34 35 You should have received copies of the GNU Lesser General Public 36 License and the GNU General Public License along with this library; 37 if not, see <https://www.gnu.org/licenses/>. 38 */ 39 40 /* 41 Main goals for the libmicrohttpd 2.0 API: 42 43 - simplify application callbacks by splitting header/upload/post 44 functionality currently provided by calling the same 45 MHD_AccessHandlerCallback 3+ times into separate callbacks. 46 - keep the API very simple for simple requests, but allow 47 more complex logic to be incrementally introduced 48 (via new struct MHD_Action construction) 49 - avoid repeated scans for URL matches via the new 50 struct MHD_Action construction 51 - better types, in particular avoid varargs for options 52 - make it harder to pass inconsistent options 53 - combine options and flags into more uniform API (at least 54 exterally!) 55 - simplify API use by using sane defaults (benefiting from 56 breaking backwards compatibility) and making all options 57 really optional, and where applicable avoid having options 58 where the default works if nothing is specified 59 - simplify API by moving rarely used http_version into 60 MHD_request_get_info_fixed() 61 - avoid 'int' for MHD_YES/MHD_NO by introducing `enum MHD_Bool` 62 - improve terminology by eliminating confusion between 63 'request' and 'connection'; add 'session' for HTTP2/3; 64 use clear separation between connection and request. Do not mix the kind 65 data in the callbacks. Currently we are mixing things in 66 MHD_AccessHandlerCallback and MHD_RequestCompletedCallback. Instead of 67 pointers to struct MHD_Connection we should use pointers to (new) struct 68 MHD_Request. 69 - prepare API for having multiple TLS backends 70 - use more consistent prefixes for related functions 71 by using MHD_subject_verb_object naming convention, also 72 at the same time avoid symbol conflict with legacy names 73 (so we can have one binary implementing old and new 74 library API at the same time via compatibility layer). 75 - make it impossible to queue a response at the wrong time 76 - make it impossible to suspend a connection/request at the 77 wrong time (improves thread-safety) 78 - make it clear which response status codes are "properly" 79 supported (include the descriptive string) by using an enum; 80 - simplify API for common-case of one-shot responses by 81 eliminating need for destroy response in most cases; 82 - avoid fixed types, like uint32_t. They may not exist on some 83 platforms. Instead use uint_fast32_t. 84 It is also better for future-proof. 85 - check portability for embedded platforms. Some of them support 86 64 bits, but 'int' could be just 16 bits resulting of silently 87 dropping enum values higher than 65535. 88 => in general, more functions, fewer enums for setup 89 - Avoid returning pointers to internal members. It is not thread-safe and 90 even in single thread the value could change over the time. Prefer pointers to 91 app-allocated memory with the size, like MHD_daemon_get_static_info(enum 92 MHD_enum_name info_type, void *buf, size_t buf_size). 93 => Except in cases where zero-copy matters. 94 - Use separate app calls/functions for data the will not change for the 95 lifetime of the object and dynamic data. The only difference should be the 96 name. Like MHD_daemon_get_static_info(enum MHD_enum_name info_type, void *buf, 97 size_t buf_size) MHD_daemon_get_dynamic_info(enum MHD_enum_name info_type, 98 void *buf, size_t buf_size) Examples of static data: listen socket, number of 99 workers, daemon flags. Examples of dynamic data: number of connections, 100 quiesce status. It should give a clear idea whether the data could be changed 101 over the time (could be not obvious for some data) and thus may change the 102 approach how to use the data in app. The same for: library, daemon, 103 connection, request. Not sure that dynamic data makes sense for the library. 104 - Define response code in response object. There are a very little 105 chance that response body designed for 404 or 403 codes will be used with 106 200 code. However, the responses body for 307 and 308 could be the same. So: 107 Add default response code in response object. 108 - Make responses unmodifiable after first use. It is not thread-safe. 109 MHD-generated headers (Date, Connection/Keep-Alive) are again 110 part of the *request* and do not count as part of the "response" here. 111 - Remove "footers" from responses. With unmodifiable responses everything should 112 be "headers". Add footers to *requests* instead. 113 - Add API for adding request-specific response headers and footers. To 114 simplify the things it should just copy the strings (to avoid dealing with 115 complicated deinit of possible dynamic strings). After this change it should 116 be possible to simplify DAuth handling as response could be reused (currently 117 403 responses are modified for each reply). 118 - Control response behaviour mainly by response flags, not by additional 119 headers (like MHD_RF_FORCE_CLOSE instead of "Connection: close"). 120 It is easier&faster for both: app and MHD. 121 - Move response codes from MHD_HTTP_xxx namespace to MHD_HTTP_CODE_xxx 122 namespace. It already may clash with other HTTP values. 123 - Postprocessor is unusable night-mare when doing "stream processing" 124 for tiny values where the application basically has to copy together 125 the stream back into a single compact heap value, just making the 126 parsing highly more complicated (see examples in Challenger) 127 - non-stream processing variant for request bodies, give apps a 128 way to request the full body in one buffer; give apps a way 129 to request a 'large new allocation' for such buffers; give apps 130 a way to specify a global quota for large allocations to ensure 131 memory usage has a hard bound 132 133 - Internals: carefully check where locking is really required. Probably 134 separate locks. Check out-of-thread value reading. Currently code assumes 135 atomic reading of values used in other threads, which mostly true on x86, 136 but not OK on other arches. Probably use read/write locking to minimize 137 the threads interference. 138 - Internals: figure out how to do portable variant of cork/uncork 139 - Internals: remove request data from memory pool when response is queued 140 (IF no callbacks and thus data cannot be used anymore, or IF 141 application permits explicitly per daemon) to get more space 142 for building response; 143 - Internals: Fix TCP FIN graceful closure issue for upgraded 144 connections (API implications?) 145 146 */ 147 148 #ifndef MICROHTTPD2_H 149 #define MICROHTTPD2_H 150 151 #ifndef __cplusplus 152 # define MHD_C_DECLARATIONS_START_HERE_ /* Empty */ 153 # define MHD_C_DECLARATIONS_FINISH_HERE_ /* Empty */ 154 #else /* __cplusplus */ 155 /* *INDENT-OFF* */ 156 # define MHD_C_DECLARATIONS_START_HERE_ extern "C" { 157 # define MHD_C_DECLARATIONS_FINISH_HERE_ } 158 /* *INDENT-ON* */ 159 #endif /* __cplusplus */ 160 161 MHD_C_DECLARATIONS_START_HERE_ 162 163 /** 164 * Current version of the library in packed BCD form. 165 * (For example, version 1.9.30-1 would be 0x01093001) 166 */ 167 #define MHD_VERSION 0x01990001 168 169 #include "microhttpd2_portability.h" 170 171 /* If generic headers do not work on your platform, include headers that 172 define 'va_list', 'size_t', 'uint_least16_t', 'uint_fast32_t', 173 'uint_fast64_t', and 'struct sockaddr', and then 174 add "#define MHD_HAVE_SYS_HEADERS_INCLUDED" before including "microhttpd2.h". 175 When 'MHD_HAVE_SYS_HEADERS_INCLUDED' is defined, the following "standard" 176 includes will not be used (which might be a good idea, especially on 177 platforms where they do not exist). 178 */ 179 #ifndef MHD_HAVE_SYS_HEADERS_INCLUDED 180 # include <stdarg.h> 181 # ifndef MHD_SYS_BASE_TYPES_H 182 /* Headers for uint_fastXX_t, size_t */ 183 # include <stdint.h> 184 # include <stddef.h> 185 # include <sys/types.h> /* This header is actually optional */ 186 # endif 187 # ifndef MHD_SYS_SOCKET_TYPES_H 188 /* Headers for 'struct sockaddr' */ 189 # if ! defined(_WIN32) || defined(__CYGWIN__) 190 # include <sys/socket.h> 191 # else 192 /* Prevent conflict of <winsock.h> and <winsock2.h> */ 193 # if ! defined(_WINSOCK2API_) && ! defined(_WINSOCKAPI_) 194 # ifndef WIN32_LEAN_AND_MEAN 195 /* Do not use unneeded parts of W32 headers. */ 196 # define WIN32_LEAN_AND_MEAN 1 197 # endif /* !WIN32_LEAN_AND_MEAN */ 198 # include <winsock2.h> 199 # endif 200 # endif 201 # endif 202 #endif 203 204 #ifndef MHD_BOOL_DEFINED 205 206 /** 207 * Representation of 'bool' in the public API as stdbool.h may not 208 * always be available and presence of 'bool' keyword may depend on 209 * used C version. 210 * It is always safe to cast 'MHD_Bool' variable to 'bool' and vice versa. 211 * Note: it may be UNSAFE to cast pointers 'MHD_Bool*' to 'bool*' and 212 * vice versa. 213 */ 214 enum MHD_Bool 215 { 216 217 /** 218 * MHD-internal return code for "NO". 219 */ 220 MHD_NO = 0 221 , 222 /** 223 * MHD-internal return code for "YES". All non-zero values 224 * will be interpreted as "YES", but MHD will only ever 225 * return #MHD_YES or #MHD_NO. 226 */ 227 MHD_YES = 1 228 }; 229 230 231 #define MHD_BOOL_DEFINED 1 232 #endif /* ! MHD_BOOL_DEFINED */ 233 234 #ifndef MHD_STRINGS_DEFINED 235 236 237 /** 238 * String with length data. 239 * This type should always have valid @a cstr pointer. 240 */ 241 struct MHD_String 242 { 243 /** 244 * Number of characters in @e str, not counting 0-termination. 245 */ 246 size_t len; 247 248 /** 249 * 0-terminated C-string. 250 * Must not be NULL. 251 */ 252 const char *cstr; 253 }; 254 255 /** 256 * String with length data. 257 * This type of data may have NULL as the @a cstr pointer. 258 */ 259 struct MHD_StringNullable 260 { 261 /** 262 * Number of characters in @e cstr, not counting 0-termination. 263 * If @a cstr is NULL, it must be zero. 264 */ 265 size_t len; 266 267 /** 268 * 0-terminated C-string. 269 * In some cases it could be NULL. 270 */ 271 const char *cstr; 272 }; 273 274 #define MHD_STRINGS_DEFINED 1 275 #endif /* ! MHD_STRINGS_DEFINED */ 276 277 278 #ifndef MHD_INVALID_SOCKET 279 # if ! defined(_WIN32) || defined(_SYS_TYPES_FD_SET) 280 # define MHD_SOCKETS_KIND_POSIX 1 281 /** 282 * MHD_Socket is a type for socket FDs 283 */ 284 typedef int MHD_Socket; 285 # define MHD_INVALID_SOCKET (-1) 286 # else /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */ 287 # define MHD_SOCKETS_KIND_WINSOCK 1 288 /** 289 * MHD_Socket is a type for socket FDs 290 */ 291 typedef SOCKET MHD_Socket; 292 # define MHD_INVALID_SOCKET (INVALID_SOCKET) 293 # endif /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */ 294 #endif /* MHD_INVALID_SOCKET */ 295 296 297 /** 298 * Constant used to indicate unknown size (use when creating a response). 299 * Any possible larger sizes are interpreted as the same value. 300 */ 301 #ifdef UINT64_MAX 302 # define MHD_SIZE_UNKNOWN UINT64_MAX 303 #else 304 # define MHD_SIZE_UNKNOWN \ 305 MHD_STATIC_CAST_ (uint_fast64_t,0xffffffffffffffffU) 306 #endif 307 308 309 /** 310 * Constant used to indicate unlimited wait time. 311 * Any possible larger values are interpreted as this value. 312 */ 313 #ifdef UINT64_MAX 314 # define MHD_WAIT_INDEFINITELY UINT64_MAX 315 #else 316 # define MHD_WAIT_INDEFINITELY \ 317 MHD_STATIC_CAST_ (uint_fast64_t,0xffffffffffffffffU) 318 #endif 319 320 321 /* ********** (a) Core HTTP Processing ************ */ 322 323 324 /** 325 * @brief Handle for a daemon that listens for requests. 326 * 327 * Manages the listen socket, event loop, optional threads and server 328 * settings. 329 * 330 * @defgroup daemon HTTP server handling client connections 331 */ 332 struct MHD_Daemon; 333 334 335 /** 336 * @brief Handle/identifier of a network connection abstraction. 337 * 338 * A single network (i.e. TCP) connection can be used for 339 * a single (in HTTP/1.1) data stream. 340 * 341 * @defgroup connection client connection with streams 342 */ 343 struct MHD_Connection; 344 345 346 /** 347 * @brief Handle/identifier of a data stream over network 348 * connection. 349 * 350 * A data stream may be used for multiple requests, which 351 * in HTTP/1.1 must be processed sequentially. 352 * 353 * @defgroup stream stream of HTTP requests 354 */ 355 struct MHD_Stream; 356 357 /** 358 * @brief Handle representing an HTTP request. 359 * 360 * With HTTP/1.1, multiple requests can be run over the same 361 * stream. However, MHD will only show one request per data 362 * stream to the client at any given time. 363 * 364 * Replaces `struct MHD_Connection` in the API prior to version 2.0.0, 365 * renamed to better reflect what this object truly represents to 366 * the application using MHD. 367 * 368 * @defgroup request HTTP requests 369 */ 370 struct MHD_Request; 371 372 373 /** 374 * @brief Actions are returned by the application when processed client header 375 * to drive the request handling of MHD. 376 * 377 * @defgroup action Request actions 378 */ 379 struct MHD_Action; 380 381 382 /** 383 * @brief Actions are returned by the application when processing client upload 384 * to drive the request handling of MHD. 385 * 386 * @defgroup action Request actions 387 */ 388 struct MHD_UploadAction; 389 390 /** 391 * @defgroup general Primary MHD functions and data 392 */ 393 394 /** 395 * @defgroup specialized Introspection and other special control 396 */ 397 398 /** 399 * @defgroup authentication Digest and other HTTP authentications 400 */ 401 402 403 /** 404 * Status codes returned by API functions, also used for logging. 405 * 406 * As a return value, zero (#MHD_SC_OK) always indicates success. 407 * Values 00001-09999 must be handled explicitly by the application. 408 * Values 10000-19999 are informational events. 409 * Values 20000-29999 indicate successful operations. 410 * Values 30000-39999 indicate unsuccessful but normal operations. 411 * Values 40000-49999 indicate client (or network) errors. 412 * Values 50000-59999 indicate MHD-internal (or platform) errors. 413 * Values 60000-65535 indicate application errors. 414 * 415 * @ingroup general 416 */ 417 enum MHD_FIXED_ENUM_MHD_SET_ MHD_StatusCode 418 { 419 420 /* 00000-level codes are return values the application must handle. 421 The zero code always means success. */ 422 423 /** 424 * Successful operation (not used for logging). 425 * The code is guaranteed to be always zero. 426 */ 427 MHD_SC_OK = 0 428 , 429 430 /* 10000-level codes are purely informational events. */ 431 432 /** 433 * Informational event, MHD started. 434 */ 435 MHD_SC_DAEMON_STARTED = 10000 436 , 437 /** 438 * Informational event, we accepted a connection. 439 */ 440 MHD_SC_CONNECTION_ACCEPTED = 10001 441 , 442 /** 443 * Informational event, thread processing connection terminates. 444 */ 445 MHD_SC_THREAD_TERMINATING = 10002 446 , 447 /** 448 * Informational event, state machine status for a connection. 449 */ 450 MHD_SC_STATE_MACHINE_STATUS_REPORT = 10003 451 , 452 /** 453 * accept() returned transient error. 454 */ 455 MHD_SC_ACCEPT_FAILED_EAGAIN = 10004 456 , 457 /** 458 * Accepted socket is unknown type (probably non-IP). 459 */ 460 MHD_SC_ACCEPTED_UNKNOWN_TYPE = 10040 461 , 462 /** 463 * The sockaddr for the accepted socket does not fit the buffer. 464 * (Strange) 465 */ 466 MHD_SC_ACCEPTED_SOCKADDR_TOO_LARGE = 10041 467 , 468 469 /* 20000-level codes indicate successful operations. */ 470 /* Examples: a connection has been closed normally, the response data 471 generation has been completed. */ 472 473 /** 474 * MHD is closing a connection after the client closed it 475 * (perfectly normal end). 476 */ 477 MHD_SC_CONNECTION_CLOSED = 20000 478 , 479 /** 480 * MHD is closing a connection because the application 481 * logic to generate the response data completed. 482 */ 483 MHD_SC_APPLICATION_DATA_GENERATION_FINISHED = 20001 484 , 485 /** 486 * The request does not contain a particular type of Authentication 487 * credentials 488 */ 489 MHD_SC_AUTH_ABSENT = 20060 490 , 491 492 /* 30000-level codes indicate unsuccessful but normal operations. */ 493 /* Examples: a connections limit has been reached, the accept policy 494 callback has rejected a connection, a memory pool is exhausted. */ 495 496 497 /** 498 * Resource limit in terms of number of parallel connections 499 * hit. 500 */ 501 MHD_SC_LIMIT_CONNECTIONS_REACHED = 30000 502 , 503 /** 504 * The operation failed because the respective 505 * daemon is already too deep inside of the shutdown 506 * activity. 507 */ 508 MHD_SC_DAEMON_ALREADY_SHUTDOWN = 30020 509 , 510 /** 511 * Failed to start new thread because of system limits. 512 */ 513 MHD_SC_CONNECTION_THREAD_SYS_LIMITS_REACHED = 30030 514 , 515 /** 516 * Failed to start a thread. 517 */ 518 MHD_SC_CONNECTION_THREAD_LAUNCH_FAILURE = 30031 519 , 520 /** 521 * The operation failed because we either have no 522 * listen socket or were already quiesced. 523 */ 524 MHD_SC_DAEMON_ALREADY_QUIESCED = 30040 525 , 526 /** 527 * The operation failed because client disconnected 528 * faster than we could accept(). 529 */ 530 MHD_SC_ACCEPT_FAST_DISCONNECT = 30050 531 , 532 /** 533 * Operating resource limits hit on accept(). 534 */ 535 MHD_SC_ACCEPT_SYSTEM_LIMIT_REACHED = 30060 536 , 537 /** 538 * Connection was refused by accept policy callback. 539 */ 540 MHD_SC_ACCEPT_POLICY_REJECTED = 30070 541 , 542 /** 543 * Failed to allocate memory for the daemon resources. 544 * TODO: combine similar error codes for daemon 545 */ 546 MHD_SC_DAEMON_MEM_ALLOC_FAILURE = 30081 547 , 548 /** 549 * We failed to allocate memory for the connection. 550 * (May be transient.) 551 */ 552 MHD_SC_CONNECTION_MEM_ALLOC_FAILURE = 30082 553 , 554 /** 555 * We failed to allocate memory for the connection's memory pool. 556 * (May be transient.) 557 */ 558 MHD_SC_POOL_MEM_ALLOC_FAILURE = 30083 559 , 560 /** 561 * We failed to allocate memory for the HTTP/2 connection's resources. 562 * (May be transient.) 563 */ 564 MHD_SC_H2_CONN_MEM_ALLOC_FAILURE = 30084 565 , 566 /** 567 * We failed to forward data from a Web socket to the 568 * application to the remote side due to the socket 569 * being closed prematurely. (May be transient.) 570 */ 571 MHD_SC_UPGRADE_FORWARD_INCOMPLETE = 30100 572 , 573 /** 574 * Failed to allocate memory from our memory pool for processing 575 * the request. Likely the request fields are too large to leave 576 * enough room. 577 */ 578 MHD_SC_CONNECTION_POOL_NO_MEM_REQ = 30130 579 , 580 /** 581 * Failed to allocate memory from our memory pool to store GET parameter. 582 * Likely the request URI or header fields are too large to leave enough room. 583 */ 584 MHD_SC_CONNECTION_POOL_NO_MEM_GET_PARAM = 30131 585 , 586 /** 587 * Failed to allocate memory from our memory pool to store parsed cookie. 588 */ 589 MHD_SC_CONNECTION_POOL_NO_MEM_COOKIE = 30132 590 , 591 /** 592 * Failed to allocate memory from connection memory pool to store 593 * parsed Authentication data. 594 */ 595 MHD_SC_CONNECTION_POOL_NO_MEM_AUTH_DATA = 30133 596 , 597 /** 598 * Detected jump back of system clock 599 */ 600 MHD_SC_SYS_CLOCK_JUMP_BACK_LARGE = 30140 601 , 602 /** 603 * Detected correctable jump back of system clock 604 */ 605 MHD_SC_SYS_CLOCK_JUMP_BACK_CORRECTED = 30141 606 , 607 /** 608 * Timeout waiting for communication operation for HTTP-Upgraded connection 609 */ 610 MHD_SC_UPGRADED_NET_TIMEOUT = 30161 611 , 612 /** 613 * Not enough system resources 614 */ 615 MHD_SC_NO_SYS_RESOURCES = 30180 616 , 617 618 /* 40000-level errors are caused by the HTTP client or the network. */ 619 620 /** 621 * MHD is closing a connection because parsing the 622 * request failed. 623 */ 624 MHD_SC_CONNECTION_PARSE_FAIL_CLOSED = 40000 625 , 626 /** 627 * MHD is returning an error because the header provided 628 * by the client is too big. 629 */ 630 MHD_SC_CLIENT_HEADER_TOO_BIG = 40020 631 , 632 /** 633 * An HTTP/1.1 request was sent without the "Host:" header. 634 */ 635 MHD_SC_HOST_HEADER_MISSING = 40060 636 , 637 /** 638 * Request has more than one "Host:" header. 639 */ 640 MHD_SC_HOST_HEADER_SEVERAL = 40061 641 , 642 /** 643 * The value of the "Host:" header is invalid. 644 */ 645 MHD_SC_HOST_HEADER_MALFORMED = 40062 646 , 647 /** 648 * The given content length was not a number. 649 */ 650 MHD_SC_CONTENT_LENGTH_MALFORMED = 40065 651 , 652 /** 653 * Request has more than one "Content-Length:" header with the same value. 654 */ 655 MHD_SC_CONTENT_LENGTH_SEVERAL_SAME = 40066 656 , 657 /** 658 * Request has more than one "Content-Length:" header with the different 659 * values. 660 */ 661 MHD_SC_CONTENT_LENGTH_SEVERAL_DIFFERENT = 40067 662 , 663 /** 664 * The BOTH Content-Length and Transfer-Encoding headers are used. 665 */ 666 MHD_SC_CONTENT_LENGTH_AND_TR_ENC = 40068 667 , 668 /** 669 * The Content-Length is too large to be handled. 670 */ 671 MHD_SC_CONTENT_LENGTH_TOO_LARGE = 40069 672 , 673 /** 674 * Transfer encoding in request is unsupported or invalid. 675 */ 676 MHD_SC_TRANSFER_ENCODING_UNSUPPORTED = 40075 677 , 678 /** 679 * "Expect:" value in request is unsupported or invalid. 680 */ 681 MHD_SC_EXPECT_HEADER_VALUE_UNSUPPORTED = 40076 682 , 683 /** 684 * The given uploaded, chunked-encoded body was malformed. 685 */ 686 MHD_SC_CHUNKED_ENCODING_MALFORMED = 40080 687 , 688 /** 689 * The first header line has whitespace at the start 690 */ 691 MHD_SC_REQ_FIRST_HEADER_LINE_SPACE_PREFIXED = 40100 692 , 693 /** 694 * The request target (URI) has whitespace character 695 */ 696 MHD_SC_REQ_TARGET_HAS_WHITESPACE = 40101 697 , 698 /** 699 * Wrong bare CR characters has been replaced with space. 700 */ 701 MHD_SC_REQ_HEADER_CR_REPLACED = 40120 702 , 703 /** 704 * Header line has not colon and skipped. 705 */ 706 MHD_SC_REQ_HEADER_LINE_NO_COLON = 40121 707 , 708 /** 709 * Wrong bare CR characters has been replaced with space. 710 */ 711 MHD_SC_REQ_FOOTER_CR_REPLACED = 40140 712 , 713 /** 714 * Footer line has not colon and skipped. 715 */ 716 MHD_SC_REQ_FOOTER_LINE_NO_COLON = 40141 717 , 718 /** 719 * The request is malformed. 720 */ 721 MHD_SC_REQ_MALFORMED = 40155 722 , 723 /** 724 * The cookie string has been parsed, but it is not fully compliant with 725 * specifications 726 */ 727 MHD_SC_REQ_COOKIE_PARSED_NOT_COMPLIANT = 40160 728 , 729 /** 730 * The cookie string has been parsed only partially 731 */ 732 MHD_SC_REQ_COOKIE_PARSED_PARTIALLY = 40161 733 , 734 /** 735 * The cookie string is ignored, as it is not fully compliant with 736 * specifications 737 */ 738 MHD_SC_REQ_COOKIE_IGNORED_NOT_COMPLIANT = 40162 739 , 740 /** 741 * The cookie string has been ignored as it is invalid 742 */ 743 MHD_SC_REQ_COOKIE_INVALID = 40163 744 , 745 /** 746 * The POST data parsed successfully, but has missing or incorrect 747 * termination. 748 * The last parsed field may have incorrect data. 749 */ 750 MHD_SC_REQ_POST_PARSE_OK_BAD_TERMINATION = 40202 751 , 752 /** 753 * Parsing of the POST data is incomplete because client used incorrect 754 * format of POST encoding. 755 * Some POST data is available or has been provided via callback. 756 */ 757 MHD_SC_REQ_POST_PARSE_PARTIAL_INVALID_POST_FORMAT = 40203 758 , 759 /** 760 * The request does not have "Content-Type:" header and POST data cannot 761 * be parsed 762 */ 763 MHD_SC_REQ_POST_PARSE_FAILED_NO_CNTN_TYPE = 40280 764 , 765 /** 766 * The request has unknown POST encoding specified by "Content-Type:" header 767 */ 768 MHD_SC_REQ_POST_PARSE_FAILED_UNKNOWN_CNTN_TYPE = 40281 769 , 770 /** 771 * The request has "Content-Type: multipart/form-data" header without 772 * "boundary" parameter 773 */ 774 MHD_SC_REQ_POST_PARSE_FAILED_HEADER_NO_BOUNDARY = 40282 775 , 776 /** 777 * The request has "Content-Type: multipart/form-data" header with misformed 778 * data 779 */ 780 MHD_SC_REQ_POST_PARSE_FAILED_HEADER_MISFORMED = 40283 781 , 782 /** 783 * The POST data cannot be parsed because client used incorrect format 784 * of POST encoding. 785 */ 786 MHD_SC_REQ_POST_PARSE_FAILED_INVALID_POST_FORMAT = 40290 787 , 788 /** 789 * The data in Auth request header has invalid format. 790 * For example, for Basic Authentication base64 decoding failed. 791 */ 792 MHD_SC_REQ_AUTH_DATA_BROKEN = 40320 793 , 794 /** 795 * The request cannot be processed. Sending error reply. 796 */ 797 MHD_SC_REQ_PROCCESSING_ERR_REPLY = 41000 798 , 799 /** 800 * MHD is closing a connection because of timeout. 801 */ 802 MHD_SC_CONNECTION_TIMEOUT = 42000 803 , 804 /** 805 * MHD is closing a connection because receiving the 806 * request failed. 807 */ 808 MHD_SC_CONNECTION_RECV_FAIL_CLOSED = 42020 809 , 810 /** 811 * MHD is closing a connection because sending the response failed. 812 */ 813 MHD_SC_CONNECTION_SEND_FAIL_CLOSED = 42021 814 , 815 /** 816 * MHD is closing a connection because remote client shut down its sending 817 * side before full request was sent. 818 */ 819 MHD_SC_CLIENT_SHUTDOWN_EARLY = 42040 820 , 821 /** 822 * MHD is closing a connection because remote client closed connection 823 * early. 824 */ 825 MHD_SC_CLIENT_CLOSED_CONN_EARLY = 42041 826 , 827 /** 828 * MHD is closing a connection connection has been (remotely) aborted. 829 */ 830 MHD_SC_CONNECTION_ABORTED = 42042 831 , 832 /** 833 * MHD is closing a connection because it was reset. 834 */ 835 MHD_SC_CONNECTION_RESET = 42060 836 , 837 /** 838 * MHD is closing a connection connection (or connection socket) has 839 * been broken. 840 */ 841 MHD_SC_CONNECTION_BROKEN = 42061 842 , 843 /** 844 * ALPN in TLS connection selected HTTP/2 (as advertised by the client), 845 * but the client did not send a valid HTTP/2 connection preface. 846 */ 847 MHD_SC_ALPN_H2_NO_PREFACE = 43001 848 , 849 850 /* 50000-level errors are internal MHD or platform failures, 851 not caused by the application (see 60000-level). */ 852 /* Examples: a socket error on a broken connection, a read failure for 853 a file-backed response, an unexpected accept() error. */ 854 855 /** 856 * This build of MHD does not support TLS, but the application 857 * requested TLS. 858 */ 859 MHD_SC_TLS_DISABLED = 50000 860 , 861 /** 862 * The selected TLS backend does not yet support this operation. 863 */ 864 MHD_SC_TLS_BACKEND_OPERATION_UNSUPPORTED = 50004 865 , 866 /** 867 * Failed to setup ITC channel. 868 */ 869 MHD_SC_ITC_INITIALIZATION_FAILED = 50005 870 , 871 /** 872 * File descriptor for ITC cannot be used because the FD number is higher 873 * than the limit set by FD_SETSIZE (if internal polling with select is used) 874 * or by application. 875 */ 876 MHD_SC_ITC_FD_OUTSIDE_OF_SET_RANGE = 50006 877 , 878 /** 879 * The specified value for the NC length is way too large 880 * for this platform (integer overflow on `size_t`). 881 */ 882 MHD_SC_DIGEST_AUTH_NC_LENGTH_TOO_BIG = 50010 883 , 884 /** 885 * We failed to allocate memory for the specified nonce 886 * counter array. The option was not set. 887 */ 888 MHD_SC_DIGEST_AUTH_NC_ALLOCATION_FAILURE = 50011 889 , 890 /** 891 * This build of the library does not support 892 * digest authentication. 893 */ 894 MHD_SC_DIGEST_AUTH_NOT_SUPPORTED_BY_BUILD = 50012 895 , 896 /** 897 * IPv6 requested but not supported by this build. 898 * @sa #MHD_SC_AF_NOT_SUPPORTED_BY_BUILD 899 */ 900 MHD_SC_IPV6_NOT_SUPPORTED_BY_BUILD = 50020 901 , 902 /** 903 * Specified address/protocol family is not supported by this build. 904 * @sa MHD_SC_IPV6_NOT_SUPPORTED_BY_BUILD 905 */ 906 MHD_SC_AF_NOT_SUPPORTED_BY_BUILD = 50021 907 , 908 /** 909 * The requested address/protocol family is rejected by the OS. 910 * @sa #MHD_SC_AF_NOT_SUPPORTED_BY_BUILD 911 */ 912 MHD_SC_AF_NOT_AVAILABLE = 50022 913 , 914 /** 915 * We failed to open the listen socket. 916 */ 917 MHD_SC_FAILED_TO_OPEN_LISTEN_SOCKET = 50040 918 , 919 /** 920 * Failed to enable listen port reuse. 921 */ 922 MHD_SC_LISTEN_PORT_REUSE_ENABLE_FAILED = 50041 923 , 924 /** 925 * Failed to enable listen port reuse. 926 */ 927 MHD_SC_LISTEN_PORT_REUSE_ENABLE_NOT_SUPPORTED = 50042 928 , 929 /** 930 * Failed to enable listen address reuse. 931 */ 932 MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_FAILED = 50043 933 , 934 /** 935 * Enabling listen address reuse is not supported by this platform. 936 */ 937 MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_NOT_SUPPORTED = 50044 938 , 939 /** 940 * Failed to enable exclusive use of listen address. 941 */ 942 MHD_SC_LISTEN_ADDRESS_EXCLUSIVE_ENABLE_FAILED = 50045 943 , 944 /** 945 * Dual stack configuration is not possible for provided sockaddr. 946 */ 947 MHD_SC_LISTEN_DUAL_STACK_NOT_SUITABLE = 50046 948 , 949 /** 950 * Failed to enable or disable dual stack for the IPv6 listen socket. 951 * The OS default dual-stack setting is different from what is requested. 952 */ 953 MHD_SC_LISTEN_DUAL_STACK_CONFIGURATION_REJECTED = 50047 954 , 955 /** 956 * Failed to enable or disable dual stack for the IPv6 listen socket. 957 * The socket will be used in whatever the default is the OS uses. 958 */ 959 MHD_SC_LISTEN_DUAL_STACK_CONFIGURATION_UNKNOWN = 50048 960 , 961 /** 962 * On this platform, MHD does not support explicitly configuring 963 * dual stack behaviour. 964 */ 965 MHD_SC_LISTEN_DUAL_STACK_CONFIGURATION_NOT_SUPPORTED = 50049 966 , 967 /** 968 * Failed to enable TCP FAST OPEN option. 969 */ 970 MHD_SC_LISTEN_FAST_OPEN_FAILURE = 50050 971 , 972 /** 973 * TCP FAST OPEN is not supported by the platform or by this MHD build. 974 */ 975 MHD_SC_FAST_OPEN_NOT_SUPPORTED = 50051 976 , 977 /** 978 * We failed to set the listen socket to non-blocking. 979 */ 980 MHD_SC_LISTEN_SOCKET_NONBLOCKING_FAILURE = 50052 981 , 982 /** 983 * Failed to configure listen socket to be non-inheritable. 984 */ 985 MHD_SC_LISTEN_SOCKET_NOINHERIT_FAILED = 50053 986 , 987 /** 988 * Listen socket FD cannot be used because the FD number is higher than 989 * the limit set by FD_SETSIZE (if internal polling with select is used) or 990 * by application. 991 */ 992 MHD_SC_LISTEN_FD_OUTSIDE_OF_SET_RANGE = 50054 993 , 994 /** 995 * We failed to bind the listen socket. 996 */ 997 MHD_SC_LISTEN_SOCKET_BIND_FAILED = 50055 998 , 999 /** 1000 * Failed to start listening on listen socket. 1001 */ 1002 MHD_SC_LISTEN_FAILURE = 50056 1003 , 1004 /** 1005 * Failed to detect the port number on the listening socket 1006 */ 1007 MHD_SC_LISTEN_PORT_DETECT_FAILURE = 50057 1008 , 1009 /** 1010 * We failed to create control socket for the epoll(). 1011 */ 1012 MHD_SC_EPOLL_CTL_CREATE_FAILED = 50060 1013 , 1014 /** 1015 * We failed to configure control socket for the epoll() 1016 * to be non-inheritable. 1017 */ 1018 MHD_SC_EPOLL_CTL_CONFIGURE_NOINHERIT_FAILED = 50061 1019 , 1020 /** 1021 * The epoll() control FD cannot be used because the FD number is higher 1022 * than the limit set by application. 1023 */ 1024 MHD_SC_EPOLL_CTL_OUTSIDE_OF_SET_RANGE = 50062 1025 , 1026 /** 1027 * Failed to allocate memory for daemon's events data, like fd_sets, 1028 * poll, epoll or kqueue structures. 1029 */ 1030 MHD_SC_EVENTS_MEMORY_ALLOCATE_FAILURE = 50063 1031 , 1032 /** 1033 * Failed to add daemon's FDs (ITC and/or listening) to the internal events 1034 * monitoring 1035 */ 1036 MHD_SC_EVENTS_REG_DAEMON_FDS_FAILURE = 50065 1037 , 1038 /** 1039 * Failed to register daemon's FDs (ITC or listening) in the application 1040 * (external event) monitoring 1041 */ 1042 MHD_SC_EXT_EVENT_REG_DAEMON_FDS_FAILURE = 50066 1043 , 1044 /** 1045 * Failed to create kqueue FD 1046 */ 1047 MHD_SC_KQUEUE_FD_CREATE_FAILED = 50067 1048 , 1049 /** 1050 * Failed to configure kqueue FD to be non-inheritable. 1051 */ 1052 MHD_SC_KQUEUE_FD_SET_NOINHERIT_FAILED = 50068 1053 , 1054 /** 1055 * The kqueue FD cannot be used because the FD number is higher 1056 * than the limit set by application. 1057 */ 1058 MHD_SC_KQUEUE_FD_OUTSIDE_OF_SET_RANGE = 50069 1059 , 1060 /** 1061 * The select() syscall is not available on this platform or in this MHD 1062 * build. 1063 */ 1064 MHD_SC_SELECT_SYSCALL_NOT_AVAILABLE = 50070 1065 , 1066 /** 1067 * The poll() syscall is not available on this platform or in this MHD 1068 * build. 1069 */ 1070 MHD_SC_POLL_SYSCALL_NOT_AVAILABLE = 50071 1071 , 1072 /** 1073 * The epoll syscalls are not available on this platform or in this MHD 1074 * build. 1075 */ 1076 MHD_SC_EPOLL_SYSCALL_NOT_AVAILABLE = 50072 1077 , 1078 /** 1079 * The kqueue syscalls are not available on this platform or in this MHD 1080 * build. 1081 */ 1082 MHD_SC_KQUEUE_SYSCALL_NOT_AVAILABLE = 50073 1083 , 1084 /** 1085 * Failed to obtain our listen port via introspection. 1086 * FIXME: remove? 1087 */ 1088 MHD_SC_LISTEN_PORT_INTROSPECTION_FAILURE = 50080 1089 , 1090 /** 1091 * Failed to obtain our listen port via introspection 1092 * due to unsupported address family being used. 1093 */ 1094 MHD_SC_LISTEN_PORT_INTROSPECTION_UNKNOWN_AF = 50081 1095 , 1096 /** 1097 * Failed to initialise mutex. 1098 */ 1099 MHD_SC_MUTEX_INIT_FAILURE = 50085 1100 , 1101 /** 1102 * Failed to allocate memory for the thread pool. 1103 */ 1104 MHD_SC_THREAD_POOL_MEM_ALLOC_FAILURE = 50090 1105 , 1106 /** 1107 * We failed to allocate mutex for thread pool worker. 1108 */ 1109 MHD_SC_THREAD_POOL_CREATE_MUTEX_FAILURE = 50093 1110 , 1111 /** 1112 * Failed to start the main daemon thread. 1113 */ 1114 MHD_SC_THREAD_MAIN_LAUNCH_FAILURE = 50095 1115 , 1116 /** 1117 * Failed to start the daemon thread for listening. 1118 */ 1119 MHD_SC_THREAD_LISTENING_LAUNCH_FAILURE = 50096 1120 , 1121 /** 1122 * Failed to start the worker thread for the thread pool. 1123 */ 1124 MHD_SC_THREAD_WORKER_LAUNCH_FAILURE = 50097 1125 , 1126 /** 1127 * There was an attempt to upgrade a connection on 1128 * a daemon where upgrades are disallowed. 1129 */ 1130 MHD_SC_UPGRADE_ON_DAEMON_WITH_UPGRADE_DISALLOWED = 50100 1131 , 1132 /** 1133 * Failed to signal via ITC channel. 1134 */ 1135 MHD_SC_ITC_USE_FAILED = 50101 1136 , 1137 /** 1138 * Failed to check for the signal on the ITC channel. 1139 */ 1140 MHD_SC_ITC_CHECK_FAILED = 50102 1141 , 1142 /** 1143 * System reported error conditions on the ITC FD. 1144 */ 1145 MHD_SC_ITC_STATUS_ERROR = 50104 1146 , 1147 /** 1148 * Failed to add a socket to the epoll set. 1149 */ 1150 MHD_SC_EPOLL_CTL_ADD_FAILED = 50110 1151 , 1152 /** 1153 * Socket FD cannot be used because the FD number is higher than the limit set 1154 * by FD_SETSIZE (if internal polling with select is used) or by application. 1155 */ 1156 MHD_SC_SOCKET_OUTSIDE_OF_SET_RANGE = 50111 1157 , 1158 /** 1159 * The daemon cannot be started with the specified settings as no space 1160 * left for the connections sockets within limits set by FD_SETSIZE. 1161 * Consider use another sockets polling syscall (only select() has such 1162 * limitations) 1163 */ 1164 MHD_SC_SYS_FD_SETSIZE_TOO_STRICT = 50112 1165 , 1166 /** 1167 * This daemon was not configured with options that 1168 * would allow us to obtain a meaningful timeout. 1169 */ 1170 MHD_SC_CONFIGURATION_MISMATCH_FOR_GET_TIMEOUT = 50113 1171 , 1172 /** 1173 * This daemon was not configured with options that 1174 * would allow us to run with select() data. 1175 */ 1176 MHD_SC_CONFIGURATION_MISMATCH_FOR_RUN_SELECT = 50114 1177 , 1178 /** 1179 * This daemon was not configured to run with an 1180 * external event loop. 1181 */ 1182 MHD_SC_CONFIGURATION_MISMATCH_FOR_RUN_EXTERNAL = 50115 1183 , 1184 /** 1185 * Encountered an unexpected error from select() 1186 * (should never happen). 1187 */ 1188 MHD_SC_UNEXPECTED_SELECT_ERROR = 50116 1189 , 1190 /** 1191 * Failed to remove a connection socket to the epoll or kqueue monitoring. 1192 */ 1193 MHD_SC_EVENTS_CONN_REMOVE_FAILED = 50117 1194 , 1195 /** 1196 * poll() is not supported. 1197 */ 1198 MHD_SC_POLL_NOT_SUPPORTED = 50120 1199 , 1200 /** 1201 * Encountered a (potentially) recoverable error from poll(). 1202 */ 1203 MHD_SC_POLL_SOFT_ERROR = 50121 1204 , 1205 /** 1206 * Encountered an unrecoverable error from poll(). 1207 */ 1208 MHD_SC_POLL_HARD_ERROR = 50122 1209 , 1210 /** 1211 * Encountered a (potentially) recoverable error from select(). 1212 */ 1213 MHD_SC_SELECT_SOFT_ERROR = 50123 1214 , 1215 /** 1216 * Encountered an unrecoverable error from select(). 1217 */ 1218 MHD_SC_SELECT_HARD_ERROR = 50124 1219 , 1220 /** 1221 * System reported error conditions on the listening socket. 1222 */ 1223 MHD_SC_LISTEN_STATUS_ERROR = 50129 1224 , 1225 /** 1226 * Encountered an unrecoverable error from epoll function. 1227 */ 1228 MHD_SC_EPOLL_HARD_ERROR = 50130 1229 , 1230 /** 1231 * Encountered an unrecoverable error from kevent() function. 1232 */ 1233 MHD_SC_KQUEUE_HARD_ERROR = 50131 1234 , 1235 /** 1236 * We failed to configure accepted socket 1237 * to not use a SIGPIPE. 1238 */ 1239 MHD_SC_ACCEPT_CONFIGURE_NOSIGPIPE_FAILED = 50140 1240 , 1241 /** 1242 * We failed to configure accepted socket 1243 * to be non-inheritable. 1244 */ 1245 MHD_SC_ACCEPT_CONFIGURE_NOINHERIT_FAILED = 50141 1246 , 1247 /** 1248 * We failed to configure accepted socket 1249 * to be non-blocking. 1250 */ 1251 MHD_SC_ACCEPT_CONFIGURE_NONBLOCKING_FAILED = 50142 1252 , 1253 /** 1254 * The accepted socket FD value is too large. 1255 */ 1256 MHD_SC_ACCEPT_OUTSIDE_OF_SET_RANGE = 50143 1257 , 1258 /** 1259 * accept() returned unexpected error. 1260 */ 1261 MHD_SC_ACCEPT_FAILED_UNEXPECTEDLY = 50144 1262 , 1263 /** 1264 * Operating resource limits hit on accept() while 1265 * zero connections are active. Oopsie. 1266 */ 1267 MHD_SC_ACCEPT_SYSTEM_LIMIT_REACHED_INSTANTLY = 50145 1268 , 1269 /** 1270 * The daemon sockets polling mode requires non-blocking sockets. 1271 */ 1272 MHD_SC_NONBLOCKING_REQUIRED = 50146 1273 , 1274 /** 1275 * Encountered an unexpected error from epoll_wait() 1276 * (should never happen). 1277 */ 1278 MHD_SC_UNEXPECTED_EPOLL_WAIT_ERROR = 50150 1279 , 1280 /** 1281 * epoll file descriptor is invalid (strange) 1282 */ 1283 MHD_SC_EPOLL_FD_INVALID = 50151 1284 , 1285 /** 1286 * Unexpected socket error (strange) 1287 */ 1288 MHD_SC_UNEXPECTED_SOCKET_ERROR = 50152 1289 , 1290 /** 1291 * Failed to add IP address to per-IP counter for 1292 * some reason. 1293 */ 1294 MHD_SC_IP_COUNTER_FAILURE = 50160 1295 , 1296 /** 1297 * Application violated our API by calling shutdown 1298 * while having an upgrade connection still open. 1299 */ 1300 MHD_SC_SHUTDOWN_WITH_OPEN_UPGRADED_CONNECTION = 50180 1301 , 1302 /** 1303 * Due to an unexpected internal error with the 1304 * state machine, we closed the connection. 1305 */ 1306 MHD_SC_STATEMACHINE_FAILURE_CONNECTION_CLOSED = 50200 1307 , 1308 /** 1309 * Failed to allocate memory in connection's pool 1310 * to parse the cookie header. 1311 */ 1312 MHD_SC_COOKIE_POOL_ALLOCATION_FAILURE = 50220 1313 , 1314 /** 1315 * MHD failed to build the reply header. 1316 */ 1317 MHD_SC_REPLY_HEADER_GENERATION_FAILED = 50230 1318 , 1319 /** 1320 * Failed to allocate memory in connection's pool for the reply. 1321 */ 1322 MHD_SC_REPLY_POOL_ALLOCATION_FAILURE = 50231 1323 , 1324 /** 1325 * Failed to read the file for file-backed response. 1326 */ 1327 MHD_SC_REPLY_FILE_READ_ERROR = 50232 1328 , 1329 /** 1330 * Failed to generate the nonce for the Digest Auth. 1331 */ 1332 MHD_SC_REPLY_NONCE_ERROR = 50233 1333 , 1334 /** 1335 * Failed to allocate memory in connection's pool for the reply. 1336 */ 1337 MHD_SC_REPLY_ALLOCATION_FAILED = 50250 1338 , 1339 /** 1340 * The request POST data cannot be parsed because stream has not enough 1341 * pool memory free. 1342 */ 1343 MHD_SC_REQ_POST_PARSE_FAILED_NO_POOL_MEM = 50260 1344 , 1345 /** 1346 * The POST data cannot be parsed completely because no "large shared buffer" 1347 * space is available. 1348 * Some POST data may be parsed. 1349 */ 1350 MHD_SC_REQ_POST_PARSE_FAILED_NO_LARGE_BUF_MEM = 50261 1351 , 1352 /** 1353 * The application set POST encoding to "multipart/form-data", but the request 1354 * has no "Content-Type: multipart/form-data" header which is required 1355 * to find "boundary" used in this encoding 1356 */ 1357 MHD_SC_REQ_POST_PARSE_FAILED_HEADER_NOT_MPART = 50284 1358 , 1359 /** 1360 * The feature is not supported by this MHD build (either 1361 * disabled by configure parameters or build platform 1362 * did not support it, because headers are missing or 1363 * so kernel does not have such feature). 1364 * The feature will not be enabled if the same MHD binary 1365 * will be run on another kernel, computer or system 1366 * configuration. 1367 */ 1368 MHD_SC_FEATURE_DISABLED = 50300 1369 , 1370 /** 1371 * The feature is not supported by this platform, while 1372 * supported by MHD build. 1373 * The feature can be enabled by changing the kernel or 1374 * running on another computer or with other system 1375 * configuration. 1376 */ 1377 MHD_SC_FEATURE_NOT_AVAILABLE = 50320 1378 , 1379 /** 1380 * Failed to stop the thread 1381 */ 1382 MHD_SC_DAEMON_THREAD_STOP_ERROR = 50350 1383 , 1384 /** 1385 * Unexpected reasons for thread stop 1386 */ 1387 MHD_SC_DAEMON_THREAD_STOP_UNEXPECTED = 50351 1388 , 1389 /** 1390 * Daemon system data is broken (like listen socket was unexpectedly closed). 1391 * The daemon needs to be closed. 1392 * A new daemon can be started as a replacement after closing the current 1393 * daemon. 1394 */ 1395 MHD_SC_DAEMON_SYS_DATA_BROKEN = 50370 1396 , 1397 /** 1398 * Failed to acquire response mutex lock 1399 */ 1400 MHD_SC_RESP_MUTEX_LOCK_FAILED = 50500 1401 , 1402 /** 1403 * Failed to initialise response mutex 1404 */ 1405 MHD_SC_RESP_MUTEX_INIT_FAILED = 50501 1406 , 1407 /** 1408 * Unable to allocate memory for the response header 1409 */ 1410 MHD_SC_RESP_HEADER_MEM_ALLOC_FAILED = 50540 1411 , 1412 /** 1413 * Failed to switch TCP_NODELAY option for the socket 1414 */ 1415 MHD_SC_SOCKET_TCP_NODELAY_FAILED = 50600 1416 , 1417 /** 1418 * Failed to switch TCP_CORK or TCP_NOPUSH option for the socket 1419 */ 1420 MHD_SC_SOCKET_TCP_CORK_NOPUSH_FAILED = 50601 1421 , 1422 /** 1423 * Failed to force flush the last part of the response header or 1424 * the response content 1425 */ 1426 MHD_SC_SOCKET_FLUSH_LAST_PART_FAILED = 50620 1427 , 1428 /** 1429 * Failed to push buffered data by zero-sized send() 1430 */ 1431 MHD_SC_SOCKET_ZERO_SEND_FAILED = 50621 1432 , 1433 /** 1434 * The HTTP-Upgraded network connection has been closed / disconnected 1435 */ 1436 MHD_SC_UPGRADED_NET_CONN_CLOSED = 50800 1437 , 1438 /** 1439 * The HTTP-Upgraded network connection has been broken 1440 */ 1441 MHD_SC_UPGRADED_NET_CONN_BROKEN = 50801 1442 , 1443 /** 1444 * The TLS communication error on HTTP-Upgraded connection 1445 */ 1446 MHD_SC_UPGRADED_TLS_ERROR = 50802 1447 , 1448 /** 1449 * Unrecoverable sockets communication error on HTTP-Upgraded connection 1450 */ 1451 MHD_SC_UPGRADED_NET_HARD_ERROR = 50840 1452 , 1453 /** 1454 * MHD cannot wait for the data on the HTTP-Upgraded connection, because 1455 * current build or the platform does not support required functionality. 1456 * Communication with zero timeout is fully supported. 1457 */ 1458 MHD_SC_UPGRADED_WAITING_NOT_SUPPORTED = 50860 1459 , 1460 /** 1461 * Global initialisation of MHD library failed 1462 */ 1463 MHD_SC_LIB_INIT_GLOBAL_FAILED = 51000 1464 , 1465 /** 1466 * Failed to initialise TLS context for the daemon 1467 */ 1468 MHD_SC_TLS_DAEMON_INIT_FAILED = 51200 1469 , 1470 /** 1471 * Failed to initialise TLS context for the new connection 1472 */ 1473 MHD_SC_TLS_CONNECTION_INIT_FAILED = 51201 1474 , 1475 /** 1476 * Warning about TLS backend configuration 1477 */ 1478 MHD_SC_TLS_LIB_CONF_WARNING = 51202 1479 , 1480 /** 1481 * Failed to perform TLS handshake 1482 */ 1483 MHD_SC_TLS_CONNECTION_HANDSHAKED_FAILED = 51220 1484 , 1485 /** 1486 * Hashing failed. 1487 * Internal hashing function can never fail (and this code is never returned 1488 * for them). External hashing function (like TLS backend-based) may fail 1489 * for various reasons, like failure of hardware acccelerated hashing. 1490 */ 1491 MHD_SC_HASH_FAILED = 51260 1492 , 1493 /** 1494 * Something wrong in the internal MHD logic. 1495 * This error should be never returned if MHD works as expected. 1496 * If this code is ever returned, please report to MHD maintainers. 1497 */ 1498 MHD_SC_INTERNAL_ERROR = 59900 1499 , 1500 1501 /* 60000-level errors are caused by the application 1502 (callbacks, settings or API misuse). */ 1503 1504 /** 1505 * The application called function too early. 1506 * For example, a header value was requested before the headers 1507 * had been received. 1508 */ 1509 MHD_SC_TOO_EARLY = 60000 1510 , 1511 /** 1512 * The application called this function too late. 1513 * For example, MHD has already started sending reply. 1514 */ 1515 MHD_SC_TOO_LATE = 60001 1516 , 1517 /** 1518 * MHD does not support the requested combination of 1519 * the sockets polling syscall and the work mode. 1520 */ 1521 MHD_SC_SYSCALL_WORK_MODE_COMBINATION_INVALID = 60010 1522 , 1523 /** 1524 * MHD does not support quiescing if ITC was disabled 1525 * and threads are used. 1526 */ 1527 MHD_SC_SYSCALL_QUIESCE_REQUIRES_ITC = 60011 1528 , 1529 /** 1530 * The option provided or function called can be used only with "external 1531 * events" modes. 1532 */ 1533 MHD_SC_EXTERNAL_EVENT_ONLY = 60012 1534 , 1535 /** 1536 * MHD is closing a connection because the application 1537 * logic to generate the response data failed. 1538 */ 1539 MHD_SC_APPLICATION_DATA_GENERATION_FAILURE_CLOSED = 60015 1540 , 1541 /** 1542 * MHD is closing a connection because the application 1543 * callback told it to do so. 1544 */ 1545 MHD_SC_APPLICATION_CALLBACK_ABORT_ACTION = 60016 1546 , 1547 /** 1548 * Application only partially processed upload and did 1549 * not suspend connection. This may result in a hung 1550 * connection. 1551 */ 1552 MHD_SC_APPLICATION_HUNG_CONNECTION = 60017 1553 , 1554 /** 1555 * Application only partially processed upload and did 1556 * not suspend connection and the read buffer was maxxed 1557 * out, so MHD closed the connection. 1558 */ 1559 MHD_SC_APPLICATION_HUNG_CONNECTION_CLOSED = 60018 1560 , 1561 /** 1562 * Attempted to set an option that conflicts with another option 1563 * already set. 1564 */ 1565 MHD_SC_OPTIONS_CONFLICT = 60020 1566 , 1567 /** 1568 * Attempted to set an option that not recognised by MHD. 1569 */ 1570 MHD_SC_OPTION_UNKNOWN = 60021 1571 , 1572 /** 1573 * Parameter specified unknown work mode. 1574 */ 1575 MHD_SC_CONFIGURATION_UNEXPECTED_WM = 60022 1576 , 1577 /** 1578 * Parameter specified unknown Sockets Polling Syscall (SPS). 1579 */ 1580 MHD_SC_CONFIGURATION_UNEXPECTED_SPS = 60023 1581 , 1582 /** 1583 * The size of the provided sockaddr does not match address family. 1584 */ 1585 MHD_SC_CONFIGURATION_WRONG_SA_SIZE = 60024 1586 , 1587 /** 1588 * The number set by #MHD_D_O_FD_NUMBER_LIMIT is too strict to run 1589 * the daemon 1590 */ 1591 MHD_SC_MAX_FD_NUMBER_LIMIT_TOO_STRICT = 60025 1592 , 1593 /** 1594 * The number set by #MHD_D_O_GLOBAL_CONNECTION_LIMIT is too for the daemon 1595 * configuration 1596 */ 1597 MHD_SC_CONFIGURATION_CONN_LIMIT_TOO_SMALL = 60026 1598 , 1599 /** 1600 * The provided configuration parameter is NULL, but it must be non-NULL 1601 */ 1602 MHD_SC_CONFIGURATION_PARAM_NULL = 60027 1603 , 1604 /** 1605 * The size of the provided configuration parameter is too large 1606 */ 1607 MHD_SC_CONFIGURATION_PARAM_TOO_LARGE = 60028 1608 , 1609 /** 1610 * The application requested an unsupported TLS backend to be used. 1611 */ 1612 MHD_SC_TLS_BACKEND_UNSUPPORTED = 60030 1613 , 1614 /** 1615 * The application attempted to setup TLS parameters before 1616 * enabling TLS. 1617 */ 1618 MHD_SC_TLS_BACKEND_UNINITIALIZED = 60031 1619 , 1620 /** 1621 * The application requested a TLS backend which cannot be used due 1622 * to missing TLS dynamic library or backend initialisation problem. 1623 */ 1624 MHD_SC_TLS_BACKEND_UNAVAILABLE = 60032 1625 , 1626 /** 1627 * Provided TLS certificate and/or private key are incorrect 1628 */ 1629 MHD_SC_TLS_CONF_BAD_CERT = 60033 1630 , 1631 /** 1632 * The application requested a daemon setting that cannot be used with 1633 * selected TLS backend 1634 */ 1635 MHD_SC_TLS_BACKEND_DAEMON_INCOMPATIBLE_SETTINGS = 60034 1636 , 1637 /** 1638 * The pointer to the response object is NULL 1639 */ 1640 MHD_SC_RESP_POINTER_NULL = 60060 1641 , 1642 /** 1643 * The response HTTP status code is not suitable 1644 */ 1645 MHD_SC_RESP_HTTP_CODE_NOT_SUITABLE = 60061 1646 , 1647 /** 1648 * The provided MHD_Action is invalid 1649 */ 1650 MHD_SC_ACTION_INVALID = 60080 1651 , 1652 /** 1653 * The provided MHD_UploadAction is invalid 1654 */ 1655 MHD_SC_UPLOAD_ACTION_INVALID = 60081 1656 , 1657 /** 1658 * The provided Dynamic Content Creator action is invalid 1659 */ 1660 MHD_SC_DCC_ACTION_INVALID = 60082 1661 , 1662 /** 1663 * The response must be empty 1664 */ 1665 MHD_SC_REPLY_NOT_EMPTY_RESPONSE = 60101 1666 , 1667 /** 1668 * The "Content-Length" header is not allowed in the reply 1669 */ 1670 MHD_SC_REPLY_CONTENT_LENGTH_NOT_ALLOWED = 60102 1671 , 1672 /** 1673 * The provided reply headers do not fit the connection buffer 1674 */ 1675 MHD_SC_REPLY_HEADERS_TOO_LARGE = 60103 1676 , 1677 /** 1678 * Specified offset in file-backed response is too large and not supported 1679 * by the platform 1680 */ 1681 MHD_SC_REPLY_FILE_OFFSET_TOO_LARGE = 60104 1682 , 1683 /** 1684 * File-backed response has file smaller than specified combination of 1685 * the file offset and the response size. 1686 */ 1687 MHD_SC_REPLY_FILE_TOO_SHORT = 60105 1688 , 1689 /** 1690 * The new connection cannot be used because the FD number is higher than 1691 * the limit set by FD_SETSIZE (if internal polling with select is used) or 1692 * by application. 1693 */ 1694 MHD_SC_NEW_CONN_FD_OUTSIDE_OF_SET_RANGE = 60140 1695 , 1696 /** 1697 * The daemon is being destroyed, while not all HTTP-Upgraded connections 1698 * has been closed. 1699 */ 1700 MHD_SC_DAEMON_DESTROYED_WITH_UNCLOSED_UPGRADED = 60160 1701 , 1702 /** 1703 * The provided pointer to 'struct MHD_UpgradedHandle' is invalid 1704 */ 1705 MHD_SC_UPGRADED_HANDLE_INVALID = 60161 1706 , 1707 /** 1708 * The provided output buffer is too small. 1709 */ 1710 MHD_SC_OUT_BUFF_TOO_SMALL = 60180 1711 , 1712 /** 1713 * The requested type of information is not recognised. 1714 */ 1715 MHD_SC_INFO_GET_TYPE_UNKNOWN = 60200 1716 , 1717 /** 1718 * The information of the requested type is too large to fit into 1719 * the provided buffer. 1720 */ 1721 MHD_SC_INFO_GET_BUFF_TOO_SMALL = 60201 1722 , 1723 /** 1724 * The type of the information is not supported by this MHD build. 1725 * It can be information not supported on the current platform or related 1726 * to feature disabled for this build. 1727 */ 1728 MHD_SC_INFO_GET_TYPE_NOT_SUPP_BY_BUILD = 60202 1729 , 1730 /** 1731 * The type of the information is not available due to configuration 1732 * or state of the object. 1733 */ 1734 MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE = 60203 1735 , 1736 /** 1737 * The type of the information should be available for the object, but 1738 * cannot be provided due to some error or other reasons. 1739 */ 1740 MHD_SC_INFO_GET_TYPE_UNOBTAINABLE = 60204 1741 , 1742 /** 1743 * The type of the Digest Auth algorithm is unknown or not supported. 1744 */ 1745 MHD_SC_AUTH_DIGEST_ALGO_NOT_SUPPORTED = 60240 1746 , 1747 /** 1748 * The Digest Auth QOP value is unknown or not supported. 1749 */ 1750 MHD_SC_AUTH_DIGEST_QOP_NOT_SUPPORTED = 60241 1751 , 1752 /** 1753 * The Digest Auth is not supported due to configuration 1754 */ 1755 MHD_SC_AUTH_DIGEST_UNSUPPORTED = 60242 1756 , 1757 /** 1758 * The application failed to register FD for the external events monitoring 1759 */ 1760 MHD_SC_EXTR_EVENT_REG_FAILED = 60243 1761 , 1762 /** 1763 * The application failed to de-register FD for the external events monitoring 1764 */ 1765 MHD_SC_EXTR_EVENT_DEREG_FAILED = 60244 1766 , 1767 /** 1768 * The application called #MHD_daemon_event_update() with broken data 1769 */ 1770 MHD_SC_EXTR_EVENT_BROKEN_DATA = 60250 1771 , 1772 /** 1773 * The application called #MHD_daemon_event_update() with status that 1774 * has not been requested 1775 */ 1776 MHD_SC_EXTR_EVENT_UNEXPECTED_STATUS = 60251 1777 , 1778 /** 1779 * Unable to clear "reusable" flag. 1780 * Once this flag is set, it cannot be removed for the response lifetime. 1781 */ 1782 MHD_SC_RESP_REUSABLE_CANNOT_CLEAR = 60300 1783 , 1784 /** 1785 * The response header name has forbidden characters or token 1786 */ 1787 MHD_SC_RESP_HEADER_NAME_INVALID = 60320 1788 , 1789 /** 1790 * The response header value has forbidden characters or token 1791 */ 1792 MHD_SC_RESP_HEADER_VALUE_INVALID = 60321 1793 , 1794 /** 1795 * An attempt to add header conflicting with other response header 1796 */ 1797 MHD_SC_RESP_HEADERS_CONFLICT = 60330 1798 , 1799 /** 1800 * The application tried to add second DATE header. 1801 */ 1802 MHD_SC_RESP_HEADER_DATE_DUPLICATE = 60340 1803 , 1804 /** 1805 * The application tried to add second CONNECTION header. 1806 */ 1807 MHD_SC_RESP_HEADER_CONNECTION_DUPLICATE = 60341 1808 }; 1809 1810 /** 1811 * Get text description for the MHD error code. 1812 * 1813 * This function works for @b MHD error codes, not for @b HTTP status codes. 1814 * @param code the MHD code to get description for 1815 * @return the pointer to the text description, 1816 * NULL if MHD code in not known. 1817 * 1818 * @ingroup general 1819 */ 1820 MHD_EXTERN_ const struct MHD_String * 1821 MHD_status_code_to_string (enum MHD_StatusCode code) 1822 MHD_FN_CONST_; 1823 1824 /** 1825 * Get the pointer to the C string for the MHD error code, never NULL. 1826 */ 1827 #define MHD_status_code_to_string_lazy(code) \ 1828 (MHD_status_code_to_string ((code)) ? \ 1829 ((MHD_status_code_to_string (code))->cstr) : ("[No code]") ) 1830 1831 #ifndef MHD_HTTP_METHOD_DEFINED 1832 1833 /** 1834 * @brief HTTP request methods 1835 * 1836 * @defgroup methods HTTP methods 1837 * 1838 * See: https://www.iana.org/assignments/http-methods/http-methods.xml 1839 * Registry export date: 2023-10-02 1840 * @{ 1841 */ 1842 1843 /** 1844 * HTTP methods explicitly supported by MHD. Note that for non-canonical 1845 * methods, MHD will return #MHD_HTTP_METHOD_OTHER and you can use 1846 * #MHD_REQUEST_INFO_FIXED_HTTP_METHOD to get the original string. 1847 * 1848 * However, applications must check for #MHD_HTTP_METHOD_OTHER *or* any enum-value 1849 * above those in this list, as future versions of MHD may add additional 1850 * methods (as per IANA registry), thus even if the API returns 1851 * #MHD_HTTP_METHOD_OTHER today, it may return a method-specific header in the 1852 * future! 1853 */ 1854 enum MHD_FIXED_ENUM_MHD_SET_ MHD_HTTP_Method 1855 { 1856 1857 /** 1858 * Method did not match any of the methods given below. 1859 */ 1860 MHD_HTTP_METHOD_OTHER = 255 1861 , 1862 /* Main HTTP methods. */ 1863 1864 /** 1865 * "GET" 1866 * Safe. Idempotent. RFC9110, Section 9.3.1. 1867 */ 1868 MHD_HTTP_METHOD_GET = 1 1869 , 1870 /** 1871 * "HEAD" 1872 * Safe. Idempotent. RFC9110, Section 9.3.2. 1873 */ 1874 MHD_HTTP_METHOD_HEAD = 2 1875 , 1876 /** 1877 * "POST" 1878 * Not safe. Not idempotent. RFC9110, Section 9.3.3. 1879 */ 1880 MHD_HTTP_METHOD_POST = 3 1881 , 1882 /** 1883 * "PUT" 1884 * Not safe. Idempotent. RFC9110, Section 9.3.4. 1885 */ 1886 MHD_HTTP_METHOD_PUT = 4 1887 , 1888 /** 1889 * "DELETE" 1890 * Not safe. Idempotent. RFC9110, Section 9.3.5. 1891 */ 1892 MHD_HTTP_METHOD_DELETE = 5 1893 , 1894 /** 1895 * "CONNECT" 1896 * Not safe. Not idempotent. RFC9110, Section 9.3.6. 1897 */ 1898 MHD_HTTP_METHOD_CONNECT = 6 1899 , 1900 /** 1901 * "OPTIONS" 1902 * Safe. Idempotent. RFC9110, Section 9.3.7. 1903 */ 1904 MHD_HTTP_METHOD_OPTIONS = 7 1905 , 1906 /** 1907 * "TRACE" 1908 * Safe. Idempotent. RFC9110, Section 9.3.8. 1909 */ 1910 MHD_HTTP_METHOD_TRACE = 8 1911 , 1912 /** 1913 * "*" 1914 * Not safe. Not idempotent. RFC9110, Section 18.2. 1915 */ 1916 MHD_HTTP_METHOD_ASTERISK = 9 1917 }; 1918 1919 #define MHD_HTTP_METHOD_DEFINED 1 1920 #endif /* ! MHD_HTTP_METHOD_DEFINED */ 1921 1922 /** 1923 * Get text version of the method name. 1924 * @param method the method to get the text version 1925 * @return the pointer to the text version, 1926 * NULL if method is MHD_HTTP_METHOD_OTHER 1927 * or not known. 1928 */ 1929 MHD_EXTERN_ const struct MHD_String * 1930 MHD_http_method_to_string (enum MHD_HTTP_Method method) 1931 MHD_FN_CONST_; 1932 1933 1934 /* Main HTTP methods. */ 1935 /* Safe. Idempotent. RFC9110, Section 9.3.1. */ 1936 #define MHD_HTTP_METHOD_STR_GET "GET" 1937 /* Safe. Idempotent. RFC9110, Section 9.3.2. */ 1938 #define MHD_HTTP_METHOD_STR_HEAD "HEAD" 1939 /* Not safe. Not idempotent. RFC9110, Section 9.3.3. */ 1940 #define MHD_HTTP_METHOD_STR_POST "POST" 1941 /* Not safe. Idempotent. RFC9110, Section 9.3.4. */ 1942 #define MHD_HTTP_METHOD_STR_PUT "PUT" 1943 /* Not safe. Idempotent. RFC9110, Section 9.3.5. */ 1944 #define MHD_HTTP_METHOD_STR_DELETE "DELETE" 1945 /* Not safe. Not idempotent. RFC9110, Section 9.3.6. */ 1946 #define MHD_HTTP_METHOD_STR_CONNECT "CONNECT" 1947 /* Safe. Idempotent. RFC9110, Section 9.3.7. */ 1948 #define MHD_HTTP_METHOD_STR_OPTIONS "OPTIONS" 1949 /* Safe. Idempotent. RFC9110, Section 9.3.8. */ 1950 #define MHD_HTTP_METHOD_STR_TRACE "TRACE" 1951 /* Not safe. Not idempotent. RFC9110, Section 18.2. */ 1952 #define MHD_HTTP_METHOD_STR_ASTERISK "*" 1953 1954 /* Additional HTTP methods. */ 1955 /* Not safe. Idempotent. RFC3744, Section 8.1. */ 1956 #define MHD_HTTP_METHOD_STR_ACL "ACL" 1957 /* Not safe. Idempotent. RFC3253, Section 12.6. */ 1958 #define MHD_HTTP_METHOD_STR_BASELINE_CONTROL "BASELINE-CONTROL" 1959 /* Not safe. Idempotent. RFC5842, Section 4. */ 1960 #define MHD_HTTP_METHOD_STR_BIND "BIND" 1961 /* Not safe. Idempotent. RFC3253, Section 4.4, Section 9.4. */ 1962 #define MHD_HTTP_METHOD_STR_CHECKIN "CHECKIN" 1963 /* Not safe. Idempotent. RFC3253, Section 4.3, Section 8.8. */ 1964 #define MHD_HTTP_METHOD_STR_CHECKOUT "CHECKOUT" 1965 /* Not safe. Idempotent. RFC4918, Section 9.8. */ 1966 #define MHD_HTTP_METHOD_STR_COPY "COPY" 1967 /* Not safe. Idempotent. RFC3253, Section 8.2. */ 1968 #define MHD_HTTP_METHOD_STR_LABEL "LABEL" 1969 /* Not safe. Idempotent. RFC2068, Section 19.6.1.2. */ 1970 #define MHD_HTTP_METHOD_STR_LINK "LINK" 1971 /* Not safe. Not idempotent. RFC4918, Section 9.10. */ 1972 #define MHD_HTTP_METHOD_STR_LOCK "LOCK" 1973 /* Not safe. Idempotent. RFC3253, Section 11.2. */ 1974 #define MHD_HTTP_METHOD_STR_MERGE "MERGE" 1975 /* Not safe. Idempotent. RFC3253, Section 13.5. */ 1976 #define MHD_HTTP_METHOD_STR_MKACTIVITY "MKACTIVITY" 1977 /* Not safe. Idempotent. RFC4791, Section 5.3.1; RFC8144, Section 2.3. */ 1978 #define MHD_HTTP_METHOD_STR_MKCALENDAR "MKCALENDAR" 1979 /* Not safe. Idempotent. RFC4918, Section 9.3; RFC5689, Section 3; RFC8144, Section 2.3. */ 1980 #define MHD_HTTP_METHOD_STR_MKCOL "MKCOL" 1981 /* Not safe. Idempotent. RFC4437, Section 6. */ 1982 #define MHD_HTTP_METHOD_STR_MKREDIRECTREF "MKREDIRECTREF" 1983 /* Not safe. Idempotent. RFC3253, Section 6.3. */ 1984 #define MHD_HTTP_METHOD_STR_MKWORKSPACE "MKWORKSPACE" 1985 /* Not safe. Idempotent. RFC4918, Section 9.9. */ 1986 #define MHD_HTTP_METHOD_STR_MOVE "MOVE" 1987 /* Not safe. Idempotent. RFC3648, Section 7. */ 1988 #define MHD_HTTP_METHOD_STR_ORDERPATCH "ORDERPATCH" 1989 /* Not safe. Not idempotent. RFC5789, Section 2. */ 1990 #define MHD_HTTP_METHOD_STR_PATCH "PATCH" 1991 /* Safe. Idempotent. RFC9113, Section 3.4. */ 1992 #define MHD_HTTP_METHOD_STR_PRI "PRI" 1993 /* Safe. Idempotent. RFC4918, Section 9.1; RFC8144, Section 2.1. */ 1994 #define MHD_HTTP_METHOD_STR_PROPFIND "PROPFIND" 1995 /* Not safe. Idempotent. RFC4918, Section 9.2; RFC8144, Section 2.2. */ 1996 #define MHD_HTTP_METHOD_STR_PROPPATCH "PROPPATCH" 1997 /* Not safe. Idempotent. RFC5842, Section 6. */ 1998 #define MHD_HTTP_METHOD_STR_REBIND "REBIND" 1999 /* Safe. Idempotent. RFC3253, Section 3.6; RFC8144, Section 2.1. */ 2000 #define MHD_HTTP_METHOD_STR_REPORT "REPORT" 2001 /* Safe. Idempotent. RFC5323, Section 2. */ 2002 #define MHD_HTTP_METHOD_STR_SEARCH "SEARCH" 2003 /* Not safe. Idempotent. RFC5842, Section 5. */ 2004 #define MHD_HTTP_METHOD_STR_UNBIND "UNBIND" 2005 /* Not safe. Idempotent. RFC3253, Section 4.5. */ 2006 #define MHD_HTTP_METHOD_STR_UNCHECKOUT "UNCHECKOUT" 2007 /* Not safe. Idempotent. RFC2068, Section 19.6.1.3. */ 2008 #define MHD_HTTP_METHOD_STR_UNLINK "UNLINK" 2009 /* Not safe. Idempotent. RFC4918, Section 9.11. */ 2010 #define MHD_HTTP_METHOD_STR_UNLOCK "UNLOCK" 2011 /* Not safe. Idempotent. RFC3253, Section 7.1. */ 2012 #define MHD_HTTP_METHOD_STR_UPDATE "UPDATE" 2013 /* Not safe. Idempotent. RFC4437, Section 7. */ 2014 #define MHD_HTTP_METHOD_STR_UPDATEREDIRECTREF "UPDATEREDIRECTREF" 2015 /* Not safe. Idempotent. RFC3253, Section 3.5. */ 2016 #define MHD_HTTP_METHOD_STR_VERSION_CONTROL "VERSION-CONTROL" 2017 2018 /** @} */ /* end of group methods */ 2019 2020 #ifndef MHD_HTTP_POSTENCODING_DEFINED 2021 2022 2023 /** 2024 * @brief Possible encodings for HTML forms submitted as HTTP POST requests 2025 * 2026 * @defgroup postenc HTTP POST encodings 2027 * See also: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#form-submission-2 2028 * @{ 2029 */ 2030 enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_HTTP_PostEncoding 2031 { 2032 /** 2033 * No post encoding / broken data / unknown encoding 2034 */ 2035 MHD_HTTP_POST_ENCODING_OTHER = 0 2036 , 2037 /** 2038 * "application/x-www-form-urlencoded" 2039 * See https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#url-encoded-form-data 2040 * See https://url.spec.whatwg.org/#application/x-www-form-urlencoded 2041 * See https://datatracker.ietf.org/doc/html/rfc3986#section-2 2042 */ 2043 MHD_HTTP_POST_ENCODING_FORM_URLENCODED = 1 2044 , 2045 /** 2046 * "multipart/form-data" 2047 * See https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data 2048 * See https://www.rfc-editor.org/rfc/rfc7578.html 2049 */ 2050 MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA = 2 2051 , 2052 /** 2053 * "text/plain" 2054 * Introduced by HTML5 2055 * See https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#plain-text-form-data 2056 * @warning Format is ambiguous. Do not use unless there is a very strong reason. 2057 */ 2058 MHD_HTTP_POST_ENCODING_TEXT_PLAIN = 3 2059 }; 2060 2061 2062 /** @} */ /* end of group postenc */ 2063 2064 #define MHD_HTTP_POSTENCODING_DEFINED 1 2065 #endif /* ! MHD_HTTP_POSTENCODING_DEFINED */ 2066 2067 2068 /** 2069 * @brief Standard headers found in HTTP requests and responses. 2070 * 2071 * See: https://www.iana.org/assignments/http-fields/http-fields.xhtml 2072 * 2073 * @defgroup headers HTTP headers 2074 * Registry export date: 2023-10-02 2075 * @{ 2076 */ 2077 2078 /* Main HTTP headers. */ 2079 /* Permanent. RFC9110, Section 12.5.1: HTTP Semantics */ 2080 #define MHD_HTTP_HEADER_ACCEPT "Accept" 2081 /* Deprecated. RFC9110, Section 12.5.2: HTTP Semantics */ 2082 #define MHD_HTTP_HEADER_ACCEPT_CHARSET "Accept-Charset" 2083 /* Permanent. RFC9110, Section 12.5.3: HTTP Semantics */ 2084 #define MHD_HTTP_HEADER_ACCEPT_ENCODING "Accept-Encoding" 2085 /* Permanent. RFC9110, Section 12.5.4: HTTP Semantics */ 2086 #define MHD_HTTP_HEADER_ACCEPT_LANGUAGE "Accept-Language" 2087 /* Permanent. RFC9110, Section 14.3: HTTP Semantics */ 2088 #define MHD_HTTP_HEADER_ACCEPT_RANGES "Accept-Ranges" 2089 /* Permanent. RFC9111, Section 5.1: HTTP Caching */ 2090 #define MHD_HTTP_HEADER_AGE "Age" 2091 /* Permanent. RFC9110, Section 10.2.1: HTTP Semantics */ 2092 #define MHD_HTTP_HEADER_ALLOW "Allow" 2093 /* Permanent. RFC9110, Section 11.6.3: HTTP Semantics */ 2094 #define MHD_HTTP_HEADER_AUTHENTICATION_INFO "Authentication-Info" 2095 /* Permanent. RFC9110, Section 11.6.2: HTTP Semantics */ 2096 #define MHD_HTTP_HEADER_AUTHORIZATION "Authorization" 2097 /* Permanent. RFC9111, Section 5.2 */ 2098 #define MHD_HTTP_HEADER_CACHE_CONTROL "Cache-Control" 2099 /* Permanent. RFC9112, Section 9.6: HTTP/1.1 */ 2100 #define MHD_HTTP_HEADER_CLOSE "Close" 2101 /* Permanent. RFC9110, Section 7.6.1: HTTP Semantics */ 2102 #define MHD_HTTP_HEADER_CONNECTION "Connection" 2103 /* Permanent. RFC9110, Section 8.4: HTTP Semantics */ 2104 #define MHD_HTTP_HEADER_CONTENT_ENCODING "Content-Encoding" 2105 /* Permanent. RFC9110, Section 8.5: HTTP Semantics */ 2106 #define MHD_HTTP_HEADER_CONTENT_LANGUAGE "Content-Language" 2107 /* Permanent. RFC9110, Section 8.6: HTTP Semantics */ 2108 #define MHD_HTTP_HEADER_CONTENT_LENGTH "Content-Length" 2109 /* Permanent. RFC9110, Section 8.7: HTTP Semantics */ 2110 #define MHD_HTTP_HEADER_CONTENT_LOCATION "Content-Location" 2111 /* Permanent. RFC9110, Section 14.4: HTTP Semantics */ 2112 #define MHD_HTTP_HEADER_CONTENT_RANGE "Content-Range" 2113 /* Permanent. RFC9110, Section 8.3: HTTP Semantics */ 2114 #define MHD_HTTP_HEADER_CONTENT_TYPE "Content-Type" 2115 /* Permanent. RFC9110, Section 6.6.1: HTTP Semantics */ 2116 #define MHD_HTTP_HEADER_DATE "Date" 2117 /* Permanent. RFC9110, Section 8.8.3: HTTP Semantics */ 2118 #define MHD_HTTP_HEADER_ETAG "ETag" 2119 /* Permanent. RFC9110, Section 10.1.1: HTTP Semantics */ 2120 #define MHD_HTTP_HEADER_EXPECT "Expect" 2121 /* Permanent. RFC9111, Section 5.3: HTTP Caching */ 2122 #define MHD_HTTP_HEADER_EXPIRES "Expires" 2123 /* Permanent. RFC9110, Section 10.1.2: HTTP Semantics */ 2124 #define MHD_HTTP_HEADER_FROM "From" 2125 /* Permanent. RFC9110, Section 7.2: HTTP Semantics */ 2126 #define MHD_HTTP_HEADER_HOST "Host" 2127 /* Permanent. RFC9110, Section 13.1.1: HTTP Semantics */ 2128 #define MHD_HTTP_HEADER_IF_MATCH "If-Match" 2129 /* Permanent. RFC9110, Section 13.1.3: HTTP Semantics */ 2130 #define MHD_HTTP_HEADER_IF_MODIFIED_SINCE "If-Modified-Since" 2131 /* Permanent. RFC9110, Section 13.1.2: HTTP Semantics */ 2132 #define MHD_HTTP_HEADER_IF_NONE_MATCH "If-None-Match" 2133 /* Permanent. RFC9110, Section 13.1.5: HTTP Semantics */ 2134 #define MHD_HTTP_HEADER_IF_RANGE "If-Range" 2135 /* Permanent. RFC9110, Section 13.1.4: HTTP Semantics */ 2136 #define MHD_HTTP_HEADER_IF_UNMODIFIED_SINCE "If-Unmodified-Since" 2137 /* Permanent. RFC9110, Section 8.8.2: HTTP Semantics */ 2138 #define MHD_HTTP_HEADER_LAST_MODIFIED "Last-Modified" 2139 /* Permanent. RFC9110, Section 10.2.2: HTTP Semantics */ 2140 #define MHD_HTTP_HEADER_LOCATION "Location" 2141 /* Permanent. RFC9110, Section 7.6.2: HTTP Semantics */ 2142 #define MHD_HTTP_HEADER_MAX_FORWARDS "Max-Forwards" 2143 /* Permanent. RFC9112, Appendix B.1: HTTP/1.1 */ 2144 #define MHD_HTTP_HEADER_MIME_VERSION "MIME-Version" 2145 /* Deprecated. RFC9111, Section 5.4: HTTP Caching */ 2146 #define MHD_HTTP_HEADER_PRAGMA "Pragma" 2147 /* Permanent. RFC9110, Section 11.7.1: HTTP Semantics */ 2148 #define MHD_HTTP_HEADER_PROXY_AUTHENTICATE "Proxy-Authenticate" 2149 /* Permanent. RFC9110, Section 11.7.3: HTTP Semantics */ 2150 #define MHD_HTTP_HEADER_PROXY_AUTHENTICATION_INFO "Proxy-Authentication-Info" 2151 /* Permanent. RFC9110, Section 11.7.2: HTTP Semantics */ 2152 #define MHD_HTTP_HEADER_PROXY_AUTHORIZATION "Proxy-Authorization" 2153 /* Permanent. RFC9110, Section 14.2: HTTP Semantics */ 2154 #define MHD_HTTP_HEADER_RANGE "Range" 2155 /* Permanent. RFC9110, Section 10.1.3: HTTP Semantics */ 2156 #define MHD_HTTP_HEADER_REFERER "Referer" 2157 /* Permanent. RFC9110, Section 10.2.3: HTTP Semantics */ 2158 #define MHD_HTTP_HEADER_RETRY_AFTER "Retry-After" 2159 /* Permanent. RFC9110, Section 10.2.4: HTTP Semantics */ 2160 #define MHD_HTTP_HEADER_SERVER "Server" 2161 /* Permanent. RFC9110, Section 10.1.4: HTTP Semantics */ 2162 #define MHD_HTTP_HEADER_TE "TE" 2163 /* Permanent. RFC9110, Section 6.6.2: HTTP Semantics */ 2164 #define MHD_HTTP_HEADER_TRAILER "Trailer" 2165 /* Permanent. RFC9112, Section 6.1: HTTP Semantics */ 2166 #define MHD_HTTP_HEADER_TRANSFER_ENCODING "Transfer-Encoding" 2167 /* Permanent. RFC9110, Section 7.8: HTTP Semantics */ 2168 #define MHD_HTTP_HEADER_UPGRADE "Upgrade" 2169 /* Permanent. RFC9110, Section 10.1.5: HTTP Semantics */ 2170 #define MHD_HTTP_HEADER_USER_AGENT "User-Agent" 2171 /* Permanent. RFC9110, Section 12.5.5: HTTP Semantics */ 2172 #define MHD_HTTP_HEADER_VARY "Vary" 2173 /* Permanent. RFC9110, Section 7.6.3: HTTP Semantics */ 2174 #define MHD_HTTP_HEADER_VIA "Via" 2175 /* Permanent. RFC9110, Section 11.6.1: HTTP Semantics */ 2176 #define MHD_HTTP_HEADER_WWW_AUTHENTICATE "WWW-Authenticate" 2177 /* Permanent. RFC9110, Section 12.5.5: HTTP Semantics */ 2178 #define MHD_HTTP_HEADER_ASTERISK "*" 2179 2180 /* Additional HTTP headers. */ 2181 /* Permanent. RFC 3229: Delta encoding in HTTP */ 2182 #define MHD_HTTP_HEADER_A_IM "A-IM" 2183 /* Permanent. RFC 2324: Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0) */ 2184 #define MHD_HTTP_HEADER_ACCEPT_ADDITIONS "Accept-Additions" 2185 /* Permanent. RFC 8942, Section 3.1: HTTP Client Hints */ 2186 #define MHD_HTTP_HEADER_ACCEPT_CH "Accept-CH" 2187 /* Permanent. RFC 7089: HTTP Framework for Time-Based Access to Resource States -- Memento */ 2188 #define MHD_HTTP_HEADER_ACCEPT_DATETIME "Accept-Datetime" 2189 /* Permanent. RFC 2295: Transparent Content Negotiation in HTTP */ 2190 #define MHD_HTTP_HEADER_ACCEPT_FEATURES "Accept-Features" 2191 /* Permanent. RFC 5789: PATCH Method for HTTP */ 2192 #define MHD_HTTP_HEADER_ACCEPT_PATCH "Accept-Patch" 2193 /* Permanent. Linked Data Platform 1.0 */ 2194 #define MHD_HTTP_HEADER_ACCEPT_POST "Accept-Post" 2195 /* Permanent. RFC-ietf-httpbis-message-signatures-19, Section 5.1: HTTP Message Signatures */ 2196 #define MHD_HTTP_HEADER_ACCEPT_SIGNATURE "Accept-Signature" 2197 /* Permanent. Fetch */ 2198 #define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS \ 2199 "Access-Control-Allow-Credentials" 2200 /* Permanent. Fetch */ 2201 #define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_HEADERS \ 2202 "Access-Control-Allow-Headers" 2203 /* Permanent. Fetch */ 2204 #define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_METHODS \ 2205 "Access-Control-Allow-Methods" 2206 /* Permanent. Fetch */ 2207 #define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN \ 2208 "Access-Control-Allow-Origin" 2209 /* Permanent. Fetch */ 2210 #define MHD_HTTP_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS \ 2211 "Access-Control-Expose-Headers" 2212 /* Permanent. Fetch */ 2213 #define MHD_HTTP_HEADER_ACCESS_CONTROL_MAX_AGE "Access-Control-Max-Age" 2214 /* Permanent. Fetch */ 2215 #define MHD_HTTP_HEADER_ACCESS_CONTROL_REQUEST_HEADERS \ 2216 "Access-Control-Request-Headers" 2217 /* Permanent. Fetch */ 2218 #define MHD_HTTP_HEADER_ACCESS_CONTROL_REQUEST_METHOD \ 2219 "Access-Control-Request-Method" 2220 /* Permanent. RFC 7639, Section 2: The ALPN HTTP Header Field */ 2221 #define MHD_HTTP_HEADER_ALPN "ALPN" 2222 /* Permanent. RFC 7838: HTTP Alternative Services */ 2223 #define MHD_HTTP_HEADER_ALT_SVC "Alt-Svc" 2224 /* Permanent. RFC 7838: HTTP Alternative Services */ 2225 #define MHD_HTTP_HEADER_ALT_USED "Alt-Used" 2226 /* Permanent. RFC 2295: Transparent Content Negotiation in HTTP */ 2227 #define MHD_HTTP_HEADER_ALTERNATES "Alternates" 2228 /* Permanent. RFC 4437: Web Distributed Authoring and Versioning (WebDAV) Redirect Reference Resources */ 2229 #define MHD_HTTP_HEADER_APPLY_TO_REDIRECT_REF "Apply-To-Redirect-Ref" 2230 /* Permanent. RFC 8053, Section 4: HTTP Authentication Extensions for Interactive Clients */ 2231 #define MHD_HTTP_HEADER_AUTHENTICATION_CONTROL "Authentication-Control" 2232 /* Permanent. RFC9211: The Cache-Status HTTP Response Header Field */ 2233 #define MHD_HTTP_HEADER_CACHE_STATUS "Cache-Status" 2234 /* Permanent. RFC 8607, Section 5.1: Calendaring Extensions to WebDAV (CalDAV): Managed Attachments */ 2235 #define MHD_HTTP_HEADER_CAL_MANAGED_ID "Cal-Managed-ID" 2236 /* Permanent. RFC 7809, Section 7.1: Calendaring Extensions to WebDAV (CalDAV): Time Zones by Reference */ 2237 #define MHD_HTTP_HEADER_CALDAV_TIMEZONES "CalDAV-Timezones" 2238 /* Permanent. RFC9297 */ 2239 #define MHD_HTTP_HEADER_CAPSULE_PROTOCOL "Capsule-Protocol" 2240 /* Permanent. RFC9213: Targeted HTTP Cache Control */ 2241 #define MHD_HTTP_HEADER_CDN_CACHE_CONTROL "CDN-Cache-Control" 2242 /* Permanent. RFC 8586: Loop Detection in Content Delivery Networks (CDNs) */ 2243 #define MHD_HTTP_HEADER_CDN_LOOP "CDN-Loop" 2244 /* Permanent. RFC 8739, Section 3.3: Support for Short-Term, Automatically Renewed (STAR) Certificates in the Automated Certificate Management Environment (ACME) */ 2245 #define MHD_HTTP_HEADER_CERT_NOT_AFTER "Cert-Not-After" 2246 /* Permanent. RFC 8739, Section 3.3: Support for Short-Term, Automatically Renewed (STAR) Certificates in the Automated Certificate Management Environment (ACME) */ 2247 #define MHD_HTTP_HEADER_CERT_NOT_BEFORE "Cert-Not-Before" 2248 /* Permanent. Clear Site Data */ 2249 #define MHD_HTTP_HEADER_CLEAR_SITE_DATA "Clear-Site-Data" 2250 /* Permanent. RFC9440, Section 2: Client-Cert HTTP Header Field */ 2251 #define MHD_HTTP_HEADER_CLIENT_CERT "Client-Cert" 2252 /* Permanent. RFC9440, Section 2: Client-Cert HTTP Header Field */ 2253 #define MHD_HTTP_HEADER_CLIENT_CERT_CHAIN "Client-Cert-Chain" 2254 /* Permanent. RFC-ietf-httpbis-digest-headers-13, Section 2: Digest Fields */ 2255 #define MHD_HTTP_HEADER_CONTENT_DIGEST "Content-Digest" 2256 /* Permanent. RFC 6266: Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP) */ 2257 #define MHD_HTTP_HEADER_CONTENT_DISPOSITION "Content-Disposition" 2258 /* Permanent. The HTTP Distribution and Replication Protocol */ 2259 #define MHD_HTTP_HEADER_CONTENT_ID "Content-ID" 2260 /* Permanent. Content Security Policy Level 3 */ 2261 #define MHD_HTTP_HEADER_CONTENT_SECURITY_POLICY "Content-Security-Policy" 2262 /* Permanent. Content Security Policy Level 3 */ 2263 #define MHD_HTTP_HEADER_CONTENT_SECURITY_POLICY_REPORT_ONLY \ 2264 "Content-Security-Policy-Report-Only" 2265 /* Permanent. RFC 6265: HTTP State Management Mechanism */ 2266 #define MHD_HTTP_HEADER_COOKIE "Cookie" 2267 /* Permanent. HTML */ 2268 #define MHD_HTTP_HEADER_CROSS_ORIGIN_EMBEDDER_POLICY \ 2269 "Cross-Origin-Embedder-Policy" 2270 /* Permanent. HTML */ 2271 #define MHD_HTTP_HEADER_CROSS_ORIGIN_EMBEDDER_POLICY_REPORT_ONLY \ 2272 "Cross-Origin-Embedder-Policy-Report-Only" 2273 /* Permanent. HTML */ 2274 #define MHD_HTTP_HEADER_CROSS_ORIGIN_OPENER_POLICY "Cross-Origin-Opener-Policy" 2275 /* Permanent. HTML */ 2276 #define MHD_HTTP_HEADER_CROSS_ORIGIN_OPENER_POLICY_REPORT_ONLY \ 2277 "Cross-Origin-Opener-Policy-Report-Only" 2278 /* Permanent. Fetch */ 2279 #define MHD_HTTP_HEADER_CROSS_ORIGIN_RESOURCE_POLICY \ 2280 "Cross-Origin-Resource-Policy" 2281 /* Permanent. RFC 5323: Web Distributed Authoring and Versioning (WebDAV) SEARCH */ 2282 #define MHD_HTTP_HEADER_DASL "DASL" 2283 /* Permanent. RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */ 2284 #define MHD_HTTP_HEADER_DAV "DAV" 2285 /* Permanent. RFC 3229: Delta encoding in HTTP */ 2286 #define MHD_HTTP_HEADER_DELTA_BASE "Delta-Base" 2287 /* Permanent. RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */ 2288 #define MHD_HTTP_HEADER_DEPTH "Depth" 2289 /* Permanent. RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */ 2290 #define MHD_HTTP_HEADER_DESTINATION "Destination" 2291 /* Permanent. The HTTP Distribution and Replication Protocol */ 2292 #define MHD_HTTP_HEADER_DIFFERENTIAL_ID "Differential-ID" 2293 /* Permanent. RFC9449: OAuth 2.0 Demonstrating Proof of Possession (DPoP) */ 2294 #define MHD_HTTP_HEADER_DPOP "DPoP" 2295 /* Permanent. RFC9449: OAuth 2.0 Demonstrating Proof of Possession (DPoP) */ 2296 #define MHD_HTTP_HEADER_DPOP_NONCE "DPoP-Nonce" 2297 /* Permanent. RFC 8470: Using Early Data in HTTP */ 2298 #define MHD_HTTP_HEADER_EARLY_DATA "Early-Data" 2299 /* Permanent. RFC9163: Expect-CT Extension for HTTP */ 2300 #define MHD_HTTP_HEADER_EXPECT_CT "Expect-CT" 2301 /* Permanent. RFC 7239: Forwarded HTTP Extension */ 2302 #define MHD_HTTP_HEADER_FORWARDED "Forwarded" 2303 /* Permanent. RFC 7486, Section 6.1.1: HTTP Origin-Bound Authentication (HOBA) */ 2304 #define MHD_HTTP_HEADER_HOBAREG "Hobareg" 2305 /* Permanent. RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */ 2306 #define MHD_HTTP_HEADER_IF "If" 2307 /* Permanent. RFC 6338: Scheduling Extensions to CalDAV */ 2308 #define MHD_HTTP_HEADER_IF_SCHEDULE_TAG_MATCH "If-Schedule-Tag-Match" 2309 /* Permanent. RFC 3229: Delta encoding in HTTP */ 2310 #define MHD_HTTP_HEADER_IM "IM" 2311 /* Permanent. RFC 8473: Token Binding over HTTP */ 2312 #define MHD_HTTP_HEADER_INCLUDE_REFERRED_TOKEN_BINDING_ID \ 2313 "Include-Referred-Token-Binding-ID" 2314 /* Permanent. RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */ 2315 #define MHD_HTTP_HEADER_KEEP_ALIVE "Keep-Alive" 2316 /* Permanent. RFC 3253: Versioning Extensions to WebDAV: (Web Distributed Authoring and Versioning) */ 2317 #define MHD_HTTP_HEADER_LABEL "Label" 2318 /* Permanent. HTML */ 2319 #define MHD_HTTP_HEADER_LAST_EVENT_ID "Last-Event-ID" 2320 /* Permanent. RFC 8288: Web Linking */ 2321 #define MHD_HTTP_HEADER_LINK "Link" 2322 /* Permanent. RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */ 2323 #define MHD_HTTP_HEADER_LOCK_TOKEN "Lock-Token" 2324 /* Permanent. RFC 7089: HTTP Framework for Time-Based Access to Resource States -- Memento */ 2325 #define MHD_HTTP_HEADER_MEMENTO_DATETIME "Memento-Datetime" 2326 /* Permanent. RFC 2227: Simple Hit-Metering and Usage-Limiting for HTTP */ 2327 #define MHD_HTTP_HEADER_METER "Meter" 2328 /* Permanent. RFC 2295: Transparent Content Negotiation in HTTP */ 2329 #define MHD_HTTP_HEADER_NEGOTIATE "Negotiate" 2330 /* Permanent. Network Error Logging */ 2331 #define MHD_HTTP_HEADER_NEL "NEL" 2332 /* Permanent. OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */ 2333 #define MHD_HTTP_HEADER_ODATA_ENTITYID "OData-EntityId" 2334 /* Permanent. OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */ 2335 #define MHD_HTTP_HEADER_ODATA_ISOLATION "OData-Isolation" 2336 /* Permanent. OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */ 2337 #define MHD_HTTP_HEADER_ODATA_MAXVERSION "OData-MaxVersion" 2338 /* Permanent. OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */ 2339 #define MHD_HTTP_HEADER_ODATA_VERSION "OData-Version" 2340 /* Permanent. RFC 8053, Section 3: HTTP Authentication Extensions for Interactive Clients */ 2341 #define MHD_HTTP_HEADER_OPTIONAL_WWW_AUTHENTICATE "Optional-WWW-Authenticate" 2342 /* Permanent. RFC 3648: Web Distributed Authoring and Versioning (WebDAV) Ordered Collections Protocol */ 2343 #define MHD_HTTP_HEADER_ORDERING_TYPE "Ordering-Type" 2344 /* Permanent. RFC 6454: The Web Origin Concept */ 2345 #define MHD_HTTP_HEADER_ORIGIN "Origin" 2346 /* Permanent. HTML */ 2347 #define MHD_HTTP_HEADER_ORIGIN_AGENT_CLUSTER "Origin-Agent-Cluster" 2348 /* Permanent. RFC 8613, Section 11.1: Object Security for Constrained RESTful Environments (OSCORE) */ 2349 #define MHD_HTTP_HEADER_OSCORE "OSCORE" 2350 /* Permanent. OASIS Project Specification 01; OASIS; Chet_Ensign */ 2351 #define MHD_HTTP_HEADER_OSLC_CORE_VERSION "OSLC-Core-Version" 2352 /* Permanent. RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */ 2353 #define MHD_HTTP_HEADER_OVERWRITE "Overwrite" 2354 /* Permanent. HTML */ 2355 #define MHD_HTTP_HEADER_PING_FROM "Ping-From" 2356 /* Permanent. HTML */ 2357 #define MHD_HTTP_HEADER_PING_TO "Ping-To" 2358 /* Permanent. RFC 3648: Web Distributed Authoring and Versioning (WebDAV) Ordered Collections Protocol */ 2359 #define MHD_HTTP_HEADER_POSITION "Position" 2360 /* Permanent. RFC 7240: Prefer Header for HTTP */ 2361 #define MHD_HTTP_HEADER_PREFER "Prefer" 2362 /* Permanent. RFC 7240: Prefer Header for HTTP */ 2363 #define MHD_HTTP_HEADER_PREFERENCE_APPLIED "Preference-Applied" 2364 /* Permanent. RFC9218: Extensible Prioritization Scheme for HTTP */ 2365 #define MHD_HTTP_HEADER_PRIORITY "Priority" 2366 /* Permanent. RFC9209: The Proxy-Status HTTP Response Header Field */ 2367 #define MHD_HTTP_HEADER_PROXY_STATUS "Proxy-Status" 2368 /* Permanent. RFC 7469: Public Key Pinning Extension for HTTP */ 2369 #define MHD_HTTP_HEADER_PUBLIC_KEY_PINS "Public-Key-Pins" 2370 /* Permanent. RFC 7469: Public Key Pinning Extension for HTTP */ 2371 #define MHD_HTTP_HEADER_PUBLIC_KEY_PINS_REPORT_ONLY \ 2372 "Public-Key-Pins-Report-Only" 2373 /* Permanent. RFC 4437: Web Distributed Authoring and Versioning (WebDAV) Redirect Reference Resources */ 2374 #define MHD_HTTP_HEADER_REDIRECT_REF "Redirect-Ref" 2375 /* Permanent. HTML */ 2376 #define MHD_HTTP_HEADER_REFRESH "Refresh" 2377 /* Permanent. RFC 8555, Section 6.5.1: Automatic Certificate Management Environment (ACME) */ 2378 #define MHD_HTTP_HEADER_REPLAY_NONCE "Replay-Nonce" 2379 /* Permanent. RFC-ietf-httpbis-digest-headers-13, Section 3: Digest Fields */ 2380 #define MHD_HTTP_HEADER_REPR_DIGEST "Repr-Digest" 2381 /* Permanent. RFC 6638: Scheduling Extensions to CalDAV */ 2382 #define MHD_HTTP_HEADER_SCHEDULE_REPLY "Schedule-Reply" 2383 /* Permanent. RFC 6338: Scheduling Extensions to CalDAV */ 2384 #define MHD_HTTP_HEADER_SCHEDULE_TAG "Schedule-Tag" 2385 /* Permanent. Fetch */ 2386 #define MHD_HTTP_HEADER_SEC_PURPOSE "Sec-Purpose" 2387 /* Permanent. RFC 8473: Token Binding over HTTP */ 2388 #define MHD_HTTP_HEADER_SEC_TOKEN_BINDING "Sec-Token-Binding" 2389 /* Permanent. RFC 6455: The WebSocket Protocol */ 2390 #define MHD_HTTP_HEADER_SEC_WEBSOCKET_ACCEPT "Sec-WebSocket-Accept" 2391 /* Permanent. RFC 6455: The WebSocket Protocol */ 2392 #define MHD_HTTP_HEADER_SEC_WEBSOCKET_EXTENSIONS "Sec-WebSocket-Extensions" 2393 /* Permanent. RFC 6455: The WebSocket Protocol */ 2394 #define MHD_HTTP_HEADER_SEC_WEBSOCKET_KEY "Sec-WebSocket-Key" 2395 /* Permanent. RFC 6455: The WebSocket Protocol */ 2396 #define MHD_HTTP_HEADER_SEC_WEBSOCKET_PROTOCOL "Sec-WebSocket-Protocol" 2397 /* Permanent. RFC 6455: The WebSocket Protocol */ 2398 #define MHD_HTTP_HEADER_SEC_WEBSOCKET_VERSION "Sec-WebSocket-Version" 2399 /* Permanent. Server Timing */ 2400 #define MHD_HTTP_HEADER_SERVER_TIMING "Server-Timing" 2401 /* Permanent. RFC 6265: HTTP State Management Mechanism */ 2402 #define MHD_HTTP_HEADER_SET_COOKIE "Set-Cookie" 2403 /* Permanent. RFC-ietf-httpbis-message-signatures-19, Section 4.2: HTTP Message Signatures */ 2404 #define MHD_HTTP_HEADER_SIGNATURE "Signature" 2405 /* Permanent. RFC-ietf-httpbis-message-signatures-19, Section 4.1: HTTP Message Signatures */ 2406 #define MHD_HTTP_HEADER_SIGNATURE_INPUT "Signature-Input" 2407 /* Permanent. RFC 5023: The Atom Publishing Protocol */ 2408 #define MHD_HTTP_HEADER_SLUG "SLUG" 2409 /* Permanent. Simple Object Access Protocol (SOAP) 1.1 */ 2410 #define MHD_HTTP_HEADER_SOAPACTION "SoapAction" 2411 /* Permanent. RFC 2518: HTTP Extensions for Distributed Authoring -- WEBDAV */ 2412 #define MHD_HTTP_HEADER_STATUS_URI "Status-URI" 2413 /* Permanent. RFC 6797: HTTP Strict Transport Security (HSTS) */ 2414 #define MHD_HTTP_HEADER_STRICT_TRANSPORT_SECURITY "Strict-Transport-Security" 2415 /* Permanent. RFC 8594: The Sunset HTTP Header Field */ 2416 #define MHD_HTTP_HEADER_SUNSET "Sunset" 2417 /* Permanent. Edge Architecture Specification */ 2418 #define MHD_HTTP_HEADER_SURROGATE_CAPABILITY "Surrogate-Capability" 2419 /* Permanent. Edge Architecture Specification */ 2420 #define MHD_HTTP_HEADER_SURROGATE_CONTROL "Surrogate-Control" 2421 /* Permanent. RFC 2295: Transparent Content Negotiation in HTTP */ 2422 #define MHD_HTTP_HEADER_TCN "TCN" 2423 /* Permanent. RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */ 2424 #define MHD_HTTP_HEADER_TIMEOUT "Timeout" 2425 /* Permanent. RFC 8030, Section 5.4: Generic Event Delivery Using HTTP Push */ 2426 #define MHD_HTTP_HEADER_TOPIC "Topic" 2427 /* Permanent. Trace Context */ 2428 #define MHD_HTTP_HEADER_TRACEPARENT "Traceparent" 2429 /* Permanent. Trace Context */ 2430 #define MHD_HTTP_HEADER_TRACESTATE "Tracestate" 2431 /* Permanent. RFC 8030, Section 5.2: Generic Event Delivery Using HTTP Push */ 2432 #define MHD_HTTP_HEADER_TTL "TTL" 2433 /* Permanent. RFC 8030, Section 5.3: Generic Event Delivery Using HTTP Push */ 2434 #define MHD_HTTP_HEADER_URGENCY "Urgency" 2435 /* Permanent. RFC 2295: Transparent Content Negotiation in HTTP */ 2436 #define MHD_HTTP_HEADER_VARIANT_VARY "Variant-Vary" 2437 /* Permanent. RFC-ietf-httpbis-digest-headers-13, Section 4: Digest Fields */ 2438 #define MHD_HTTP_HEADER_WANT_CONTENT_DIGEST "Want-Content-Digest" 2439 /* Permanent. RFC-ietf-httpbis-digest-headers-13, Section 4: Digest Fields */ 2440 #define MHD_HTTP_HEADER_WANT_REPR_DIGEST "Want-Repr-Digest" 2441 /* Permanent. Fetch */ 2442 #define MHD_HTTP_HEADER_X_CONTENT_TYPE_OPTIONS "X-Content-Type-Options" 2443 /* Permanent. HTML */ 2444 #define MHD_HTTP_HEADER_X_FRAME_OPTIONS "X-Frame-Options" 2445 /* Provisional. AMP-Cache-Transform HTTP request header */ 2446 #define MHD_HTTP_HEADER_AMP_CACHE_TRANSFORM "AMP-Cache-Transform" 2447 /* Provisional. OSLC Configuration Management Version 1.0. Part 3: Configuration Specification */ 2448 #define MHD_HTTP_HEADER_CONFIGURATION_CONTEXT "Configuration-Context" 2449 /* Provisional. RFC 6017: Electronic Data Interchange - Internet Integration (EDIINT) Features Header Field */ 2450 #define MHD_HTTP_HEADER_EDIINT_FEATURES "EDIINT-Features" 2451 /* Provisional. OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */ 2452 #define MHD_HTTP_HEADER_ISOLATION "Isolation" 2453 /* Provisional. Permissions Policy */ 2454 #define MHD_HTTP_HEADER_PERMISSIONS_POLICY "Permissions-Policy" 2455 /* Provisional. Repeatable Requests Version 1.0; OASIS; Chet_Ensign */ 2456 #define MHD_HTTP_HEADER_REPEATABILITY_CLIENT_ID "Repeatability-Client-ID" 2457 /* Provisional. Repeatable Requests Version 1.0; OASIS; Chet_Ensign */ 2458 #define MHD_HTTP_HEADER_REPEATABILITY_FIRST_SENT "Repeatability-First-Sent" 2459 /* Provisional. Repeatable Requests Version 1.0; OASIS; Chet_Ensign */ 2460 #define MHD_HTTP_HEADER_REPEATABILITY_REQUEST_ID "Repeatability-Request-ID" 2461 /* Provisional. Repeatable Requests Version 1.0; OASIS; Chet_Ensign */ 2462 #define MHD_HTTP_HEADER_REPEATABILITY_RESULT "Repeatability-Result" 2463 /* Provisional. Reporting API */ 2464 #define MHD_HTTP_HEADER_REPORTING_ENDPOINTS "Reporting-Endpoints" 2465 /* Provisional. Global Privacy Control (GPC) */ 2466 #define MHD_HTTP_HEADER_SEC_GPC "Sec-GPC" 2467 /* Provisional. Resource Timing Level 1 */ 2468 #define MHD_HTTP_HEADER_TIMING_ALLOW_ORIGIN "Timing-Allow-Origin" 2469 /* Deprecated. PEP - an Extension Mechanism for HTTP; status-change-http-experiments-to-historic */ 2470 #define MHD_HTTP_HEADER_C_PEP_INFO "C-PEP-Info" 2471 /* Deprecated. White Paper: Joint Electronic Payment Initiative */ 2472 #define MHD_HTTP_HEADER_PROTOCOL_INFO "Protocol-Info" 2473 /* Deprecated. White Paper: Joint Electronic Payment Initiative */ 2474 #define MHD_HTTP_HEADER_PROTOCOL_QUERY "Protocol-Query" 2475 /* Obsoleted. Access Control for Cross-site Requests */ 2476 #define MHD_HTTP_HEADER_ACCESS_CONTROL "Access-Control" 2477 /* Obsoleted. RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */ 2478 #define MHD_HTTP_HEADER_C_EXT "C-Ext" 2479 /* Obsoleted. RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */ 2480 #define MHD_HTTP_HEADER_C_MAN "C-Man" 2481 /* Obsoleted. RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */ 2482 #define MHD_HTTP_HEADER_C_OPT "C-Opt" 2483 /* Obsoleted. PEP - an Extension Mechanism for HTTP; status-change-http-experiments-to-historic */ 2484 #define MHD_HTTP_HEADER_C_PEP "C-PEP" 2485 /* Obsoleted. RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1; RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 */ 2486 #define MHD_HTTP_HEADER_CONTENT_BASE "Content-Base" 2487 /* Obsoleted. RFC 2616, Section 14.15: Hypertext Transfer Protocol -- HTTP/1.1; RFC 7231, Appendix B: Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content */ 2488 #define MHD_HTTP_HEADER_CONTENT_MD5 "Content-MD5" 2489 /* Obsoleted. HTML 4.01 Specification */ 2490 #define MHD_HTTP_HEADER_CONTENT_SCRIPT_TYPE "Content-Script-Type" 2491 /* Obsoleted. HTML 4.01 Specification */ 2492 #define MHD_HTTP_HEADER_CONTENT_STYLE_TYPE "Content-Style-Type" 2493 /* Obsoleted. RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */ 2494 #define MHD_HTTP_HEADER_CONTENT_VERSION "Content-Version" 2495 /* Obsoleted. RFC 2965: HTTP State Management Mechanism; RFC 6265: HTTP State Management Mechanism */ 2496 #define MHD_HTTP_HEADER_COOKIE2 "Cookie2" 2497 /* Obsoleted. HTML 4.01 Specification */ 2498 #define MHD_HTTP_HEADER_DEFAULT_STYLE "Default-Style" 2499 /* Obsoleted. RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */ 2500 #define MHD_HTTP_HEADER_DERIVED_FROM "Derived-From" 2501 /* Obsoleted. RFC 3230: Instance Digests in HTTP; RFC-ietf-httpbis-digest-headers-13, Section 1.3: Digest Fields */ 2502 #define MHD_HTTP_HEADER_DIGEST "Digest" 2503 /* Obsoleted. RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */ 2504 #define MHD_HTTP_HEADER_EXT "Ext" 2505 /* Obsoleted. Implementation of OPS Over HTTP */ 2506 #define MHD_HTTP_HEADER_GETPROFILE "GetProfile" 2507 /* Obsoleted. RFC 7540, Section 3.2.1: Hypertext Transfer Protocol Version 2 (HTTP/2) */ 2508 #define MHD_HTTP_HEADER_HTTP2_SETTINGS "HTTP2-Settings" 2509 /* Obsoleted. RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */ 2510 #define MHD_HTTP_HEADER_MAN "Man" 2511 /* Obsoleted. Access Control for Cross-site Requests */ 2512 #define MHD_HTTP_HEADER_METHOD_CHECK "Method-Check" 2513 /* Obsoleted. Access Control for Cross-site Requests */ 2514 #define MHD_HTTP_HEADER_METHOD_CHECK_EXPIRES "Method-Check-Expires" 2515 /* Obsoleted. RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */ 2516 #define MHD_HTTP_HEADER_OPT "Opt" 2517 /* Obsoleted. The Platform for Privacy Preferences 1.0 (P3P1.0) Specification */ 2518 #define MHD_HTTP_HEADER_P3P "P3P" 2519 /* Obsoleted. PEP - an Extension Mechanism for HTTP */ 2520 #define MHD_HTTP_HEADER_PEP "PEP" 2521 /* Obsoleted. PEP - an Extension Mechanism for HTTP */ 2522 #define MHD_HTTP_HEADER_PEP_INFO "Pep-Info" 2523 /* Obsoleted. PICS Label Distribution Label Syntax and Communication Protocols */ 2524 #define MHD_HTTP_HEADER_PICS_LABEL "PICS-Label" 2525 /* Obsoleted. Implementation of OPS Over HTTP */ 2526 #define MHD_HTTP_HEADER_PROFILEOBJECT "ProfileObject" 2527 /* Obsoleted. PICS Label Distribution Label Syntax and Communication Protocols */ 2528 #define MHD_HTTP_HEADER_PROTOCOL "Protocol" 2529 /* Obsoleted. PICS Label Distribution Label Syntax and Communication Protocols */ 2530 #define MHD_HTTP_HEADER_PROTOCOL_REQUEST "Protocol-Request" 2531 /* Obsoleted. Notification for Proxy Caches */ 2532 #define MHD_HTTP_HEADER_PROXY_FEATURES "Proxy-Features" 2533 /* Obsoleted. Notification for Proxy Caches */ 2534 #define MHD_HTTP_HEADER_PROXY_INSTRUCTION "Proxy-Instruction" 2535 /* Obsoleted. RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */ 2536 #define MHD_HTTP_HEADER_PUBLIC "Public" 2537 /* Obsoleted. Access Control for Cross-site Requests */ 2538 #define MHD_HTTP_HEADER_REFERER_ROOT "Referer-Root" 2539 /* Obsoleted. RFC 2310: The Safe Response Header Field; status-change-http-experiments-to-historic */ 2540 #define MHD_HTTP_HEADER_SAFE "Safe" 2541 /* Obsoleted. RFC 2660: The Secure HyperText Transfer Protocol; status-change-http-experiments-to-historic */ 2542 #define MHD_HTTP_HEADER_SECURITY_SCHEME "Security-Scheme" 2543 /* Obsoleted. RFC 2965: HTTP State Management Mechanism; RFC 6265: HTTP State Management Mechanism */ 2544 #define MHD_HTTP_HEADER_SET_COOKIE2 "Set-Cookie2" 2545 /* Obsoleted. Implementation of OPS Over HTTP */ 2546 #define MHD_HTTP_HEADER_SETPROFILE "SetProfile" 2547 /* Obsoleted. RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */ 2548 #define MHD_HTTP_HEADER_URI "URI" 2549 /* Obsoleted. RFC 3230: Instance Digests in HTTP; RFC-ietf-httpbis-digest-headers-13, Section 1.3: Digest Fields */ 2550 #define MHD_HTTP_HEADER_WANT_DIGEST "Want-Digest" 2551 /* Obsoleted. RFC9111, Section 5.5: HTTP Caching */ 2552 #define MHD_HTTP_HEADER_WARNING "Warning" 2553 2554 /* Headers removed from the registry. Do not use! */ 2555 /* Obsoleted. RFC4229 */ 2556 #define MHD_HTTP_HEADER_COMPLIANCE "Compliance" 2557 /* Obsoleted. RFC4229 */ 2558 #define MHD_HTTP_HEADER_CONTENT_TRANSFER_ENCODING "Content-Transfer-Encoding" 2559 /* Obsoleted. RFC4229 */ 2560 #define MHD_HTTP_HEADER_COST "Cost" 2561 /* Obsoleted. RFC4229 */ 2562 #define MHD_HTTP_HEADER_MESSAGE_ID "Message-ID" 2563 /* Obsoleted. RFC4229 */ 2564 #define MHD_HTTP_HEADER_NON_COMPLIANCE "Non-Compliance" 2565 /* Obsoleted. RFC4229 */ 2566 #define MHD_HTTP_HEADER_OPTIONAL "Optional" 2567 /* Obsoleted. RFC4229 */ 2568 #define MHD_HTTP_HEADER_RESOLUTION_HINT "Resolution-Hint" 2569 /* Obsoleted. RFC4229 */ 2570 #define MHD_HTTP_HEADER_RESOLVER_LOCATION "Resolver-Location" 2571 /* Obsoleted. RFC4229 */ 2572 #define MHD_HTTP_HEADER_SUBOK "SubOK" 2573 /* Obsoleted. RFC4229 */ 2574 #define MHD_HTTP_HEADER_SUBST "Subst" 2575 /* Obsoleted. RFC4229 */ 2576 #define MHD_HTTP_HEADER_TITLE "Title" 2577 /* Obsoleted. RFC4229 */ 2578 #define MHD_HTTP_HEADER_UA_COLOR "UA-Color" 2579 /* Obsoleted. RFC4229 */ 2580 #define MHD_HTTP_HEADER_UA_MEDIA "UA-Media" 2581 /* Obsoleted. RFC4229 */ 2582 #define MHD_HTTP_HEADER_UA_PIXELS "UA-Pixels" 2583 /* Obsoleted. RFC4229 */ 2584 #define MHD_HTTP_HEADER_UA_RESOLUTION "UA-Resolution" 2585 /* Obsoleted. RFC4229 */ 2586 #define MHD_HTTP_HEADER_UA_WINDOWPIXELS "UA-Windowpixels" 2587 /* Obsoleted. RFC4229 */ 2588 #define MHD_HTTP_HEADER_VERSION "Version" 2589 /* Obsoleted. W3C Mobile Web Best Practices Working Group */ 2590 #define MHD_HTTP_HEADER_X_DEVICE_ACCEPT "X-Device-Accept" 2591 /* Obsoleted. W3C Mobile Web Best Practices Working Group */ 2592 #define MHD_HTTP_HEADER_X_DEVICE_ACCEPT_CHARSET "X-Device-Accept-Charset" 2593 /* Obsoleted. W3C Mobile Web Best Practices Working Group */ 2594 #define MHD_HTTP_HEADER_X_DEVICE_ACCEPT_ENCODING "X-Device-Accept-Encoding" 2595 /* Obsoleted. W3C Mobile Web Best Practices Working Group */ 2596 #define MHD_HTTP_HEADER_X_DEVICE_ACCEPT_LANGUAGE "X-Device-Accept-Language" 2597 /* Obsoleted. W3C Mobile Web Best Practices Working Group */ 2598 #define MHD_HTTP_HEADER_X_DEVICE_USER_AGENT "X-Device-User-Agent" 2599 2600 2601 /** 2602 * Predefined list of headers 2603 * To be filled with HPACK static data 2604 */ 2605 enum MHD_PredefinedHeader 2606 { 2607 MHD_PREDEF_ACCEPT_CHARSET = 15, 2608 MHD_PREDEF_ACCEPT_LANGUAGE = 17 2609 }; 2610 2611 2612 /** @} */ /* end of group headers */ 2613 2614 /** 2615 * A client has requested the given url using the given method 2616 * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT, 2617 * #MHD_HTTP_METHOD_DELETE, #MHD_HTTP_METHOD_POST, etc). 2618 * If @a upload_size is not zero and response action is provided by this 2619 * callback, then upload will be discarded and the stream (the connection for 2620 * HTTP/1.1) will be closed after sending the response. 2621 * 2622 * @param cls argument given together with the function 2623 * pointer when the handler was registered with MHD 2624 * @param request the request object 2625 * @param path the requested uri (without arguments after "?") 2626 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET, 2627 * #MHD_HTTP_METHOD_PUT, etc.) 2628 * @param upload_size the size of the message upload content payload, 2629 * #MHD_SIZE_UNKNOWN for chunked uploads (if the 2630 * final chunk has not been processed yet) 2631 * @return action how to proceed, NULL 2632 * if the request must be aborted due to a serious 2633 * error while handling the request (implies closure 2634 * of underling data stream, for HTTP/1.1 it means 2635 * socket closure). 2636 */ 2637 typedef const struct MHD_Action * 2638 (MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_NONNULL_ (3) 2639 *MHD_RequestCallback)(void *cls, 2640 struct MHD_Request *MHD_RESTRICT request, 2641 const struct MHD_String *MHD_RESTRICT path, 2642 enum MHD_HTTP_Method method, 2643 uint_fast64_t upload_size); 2644 2645 2646 /** 2647 * Create (but do not yet start) an MHD daemon. 2648 * Usually, various options are set before 2649 * starting the daemon with #MHD_daemon_start(). 2650 * 2651 * @param req_cb the function to be called for incoming requests 2652 * @param req_cb_cls the closure for @a cb 2653 * @return the pointer to the new object on success, 2654 * NULL on error (like out-of-memory) 2655 */ 2656 MHD_EXTERN_ struct MHD_Daemon * 2657 MHD_daemon_create (MHD_RequestCallback req_cb, 2658 void *req_cb_cls) 2659 MHD_FN_MUST_CHECK_RESULT_; 2660 2661 2662 /** 2663 * Start a webserver. 2664 * This function: 2665 * + checks the combination of set options, 2666 * + initialises the TLS library (if TLS is requested), 2667 * + creates the listen socket (if not provided and if allowed), 2668 * + starts the daemon internal threads (if allowed) 2669 * 2670 * @param[in,out] daemon daemon to start; you can no longer set 2671 * options on this daemon after this call! 2672 * @return #MHD_SC_OK on success 2673 * @ingroup daemon 2674 */ 2675 MHD_EXTERN_ enum MHD_StatusCode 2676 MHD_daemon_start (struct MHD_Daemon *daemon) 2677 MHD_FN_PAR_NONNULL_ (1) MHD_FN_MUST_CHECK_RESULT_; 2678 2679 2680 /** 2681 * Stop accepting connections from the listening socket. Allows 2682 * clients to continue processing, but stops accepting new 2683 * connections. Note that the caller is responsible for closing the 2684 * returned socket; however, if MHD is run using threads (anything but 2685 * external select mode), it must not be closed until AFTER 2686 * #MHD_daemon_destroy() has been called (as it is theoretically possible 2687 * that an existing thread is still using it). 2688 * 2689 * @param[in,out] daemon the daemon to stop accepting new connections for 2690 * @return the old listen socket on success, #MHD_INVALID_SOCKET if 2691 * the daemon was already not listening anymore, or 2692 * was never started, or has no listen socket. 2693 * @ingroup daemon 2694 */ 2695 MHD_EXTERN_ MHD_Socket 2696 MHD_daemon_quiesce (struct MHD_Daemon *daemon) 2697 MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (1); 2698 2699 2700 /** 2701 * Shutdown and destroy an HTTP daemon. 2702 * 2703 * @param[in] daemon daemon to stop 2704 * @ingroup daemon 2705 */ 2706 MHD_EXTERN_ void 2707 MHD_daemon_destroy (struct MHD_Daemon *daemon) 2708 MHD_FN_PAR_NONNULL_ALL_; 2709 2710 /* ******************* External event loop ************************ */ 2711 2712 /** 2713 * @defgroup event External network events processing 2714 */ 2715 2716 /** 2717 * The network status of the socket. 2718 * When set by MHD (by #MHD_SocketRegistrationUpdateCallback or 2719 * similar) it indicates a request to watch for specific socket state: 2720 * watch for readiness for receiving the data, watch for readiness for sending 2721 * the data and/or watch for exception state of the socket. 2722 * When set by application (and provided for #MHD_daemon_event_update() and 2723 * similar) it must indicate the actual status of the socket. 2724 * 2725 * Any actual state is a bitwise OR combination of #MHD_FD_STATE_RECV, 2726 * #MHD_FD_STATE_SEND, #MHD_FD_STATE_EXCEPT. 2727 * @ingroup event 2728 */ 2729 enum MHD_FIXED_ENUM_ MHD_FdState 2730 { 2731 /** 2732 * The socket is not ready for receiving or sending and 2733 * does not have any exceptional state. 2734 * The state never set by MHD, except de-registration of the sockets 2735 * in a #MHD_SocketRegistrationUpdateCallback. 2736 */ 2737 MHD_FD_STATE_NONE = 0 2738 , 2739 /* ** Three bit-flags ** */ 2740 2741 /** 2742 * Indicates that socket should be watched for incoming data 2743 * (when set by #MHD_SocketRegistrationUpdateCallback) 2744 * / socket has incoming data ready to read (when used for 2745 * #MHD_daemon_event_update()) 2746 */ 2747 MHD_FD_STATE_RECV = 1 << 0 2748 , 2749 /** 2750 * Indicates that socket should be watched for availability for sending 2751 * (when set by #MHD_SocketRegistrationUpdateCallback) 2752 * / socket has ability to send data (when used for 2753 * #MHD_daemon_event_update()) 2754 */ 2755 MHD_FD_STATE_SEND = 1 << 1 2756 , 2757 /** 2758 * Indicates that socket should be watched for disconnect, out-of-band 2759 * data available or high priority data available (when set by 2760 * #MHD_SocketRegistrationUpdateCallback) 2761 * / socket has been disconnected, has out-of-band data available or 2762 * has high priority data available (when used for 2763 * #MHD_daemon_event_update()). This status must not include "remote 2764 * peer shut down writing" status. 2765 * Note: #MHD_SocketRegistrationUpdateCallback() always set it as exceptions 2766 * must be always watched. 2767 */ 2768 MHD_FD_STATE_EXCEPT = 1 << 2 2769 , 2770 2771 /* The rest of the list is a bit-wise combination of three main 2772 * states. Application may use three main states directly as 2773 * a bit-mask instead of using of the following values 2774 */ 2775 2776 /** 2777 * Combination of #MHD_FD_STATE_RECV and #MHD_FD_STATE_SEND states. 2778 */ 2779 MHD_FD_STATE_RECV_SEND = MHD_FD_STATE_RECV | MHD_FD_STATE_SEND 2780 , 2781 /** 2782 * Combination of #MHD_FD_STATE_RECV and #MHD_FD_STATE_EXCEPT states. 2783 */ 2784 MHD_FD_STATE_RECV_EXCEPT = MHD_FD_STATE_RECV | MHD_FD_STATE_EXCEPT 2785 , 2786 /** 2787 * Combination of #MHD_FD_STATE_RECV and #MHD_FD_STATE_EXCEPT states. 2788 */ 2789 MHD_FD_STATE_SEND_EXCEPT = MHD_FD_STATE_RECV | MHD_FD_STATE_EXCEPT 2790 , 2791 /** 2792 * Combination of #MHD_FD_STATE_RECV, #MHD_FD_STATE_SEND and 2793 * #MHD_FD_STATE_EXCEPT states. 2794 */ 2795 MHD_FD_STATE_RECV_SEND_EXCEPT = \ 2796 MHD_FD_STATE_RECV | MHD_FD_STATE_SEND | MHD_FD_STATE_EXCEPT 2797 }; 2798 2799 /** 2800 * Checks whether specific @a state is enabled/set in the @a var 2801 */ 2802 #define MHD_FD_STATE_IS_SET(var,state) \ 2803 (MHD_FD_STATE_NONE != \ 2804 ((enum MHD_FdState) (((unsigned int) (var)) \ 2805 & ((unsigned int) (state))))) 2806 2807 /** 2808 * Checks whether RECV is enabled/set in the @a var 2809 */ 2810 #define MHD_FD_STATE_IS_SET_RECV(var) \ 2811 MHD_FD_STATE_IS_SET ((var),MHD_FD_STATE_RECV) 2812 /** 2813 * Checks whether SEND is enabled/set in the @a var 2814 */ 2815 #define MHD_FD_STATE_IS_SET_SEND(var) \ 2816 MHD_FD_STATE_IS_SET ((var),MHD_FD_STATE_SEND) 2817 /** 2818 * Checks whether EXCEPT is enabled/set in the @a var 2819 */ 2820 #define MHD_FD_STATE_IS_SET_EXCEPT(var) \ 2821 MHD_FD_STATE_IS_SET ((var),MHD_FD_STATE_EXCEPT) 2822 2823 2824 /** 2825 * Set/enable specific @a state in the @a var 2826 */ 2827 #define MHD_FD_STATE_SET(var,state) \ 2828 ((var) = \ 2829 (enum MHD_FdState) (((unsigned int) var) | ((unsigned int) state))) 2830 /** 2831 * Set/enable RECV state in the @a var 2832 */ 2833 #define MHD_FD_STATE_SET_RECV(var) MHD_FD_STATE_SET ((var),MHD_FD_STATE_RECV) 2834 /** 2835 * Set/enable SEND state in the @a var 2836 */ 2837 #define MHD_FD_STATE_SET_SEND(var) MHD_FD_STATE_SET ((var),MHD_FD_STATE_SEND) 2838 /** 2839 * Set/enable EXCEPT state in the @a var 2840 */ 2841 #define MHD_FD_STATE_SET_EXCEPT(var) \ 2842 MHD_FD_STATE_SET ((var),MHD_FD_STATE_EXCEPT) 2843 2844 /** 2845 * Clear/disable specific @a state in the @a var 2846 */ 2847 #define MHD_FD_STATE_CLEAR(var,state) \ 2848 ( (var) = \ 2849 (enum MHD_FdState) \ 2850 (((unsigned int) var) \ 2851 & ((enum MHD_FdState) (~((unsigned int) state)))) \ 2852 ) 2853 /** 2854 * Clear/disable RECV state in the @a var 2855 */ 2856 #define MHD_FD_STATE_CLEAR_RECV(var) \ 2857 MHD_FD_STATE_CLEAR ((var),MHD_FD_STATE_RECV) 2858 /** 2859 * Clear/disable SEND state in the @a var 2860 */ 2861 #define MHD_FD_STATE_CLEAR_SEND(var) \ 2862 MHD_FD_STATE_CLEAR ((var),MHD_FD_STATE_SEND) 2863 /** 2864 * Clear/disable EXCEPT state in the @a var 2865 */ 2866 #define MHD_FD_STATE_CLEAR_EXCEPT(var) \ 2867 MHD_FD_STATE_CLEAR ((var),MHD_FD_STATE_EXCEPT) 2868 2869 2870 /** 2871 * The context data to be used for updates of the socket state 2872 */ 2873 struct MHD_EventUpdateContext; 2874 2875 2876 /* Define MHD_APP_SOCKET_CNTX_TYPE to the socket context type before 2877 * including this header. 2878 * This is optional, but improves the types safety. 2879 * For example: 2880 * #define MHD_APP_SOCKET_CNTX_TYPE struct my_structure 2881 */ 2882 #ifndef MHD_APP_SOCKET_CNTX_TYPE 2883 # define MHD_APP_SOCKET_CNTX_TYPE void 2884 #endif 2885 2886 /** 2887 * The callback for registration/de-registration of the sockets to watch. 2888 * 2889 * This callback must not call #MHD_daemon_destroy(), #MHD_daemon_quiesce(), 2890 * #MHD_daemon_add_connection(). 2891 * 2892 * @param cls the closure 2893 * @param fd the socket to watch 2894 * @param watch_for the states of the @a fd to watch, if set to 2895 * #MHD_FD_STATE_NONE the socket must be de-registred 2896 * @param app_cntx_old the old application defined context for the socket, 2897 * NULL if @a fd socket was not registered before 2898 * @param ecb_cntx the context handle to be used 2899 * with #MHD_daemon_event_update() 2900 * @return must be NULL for the removed (de-registred) sockets, 2901 * for new and updated sockets: NULL in case of error (the connection 2902 * will be aborted or daemon failed to start if FD does not belong to 2903 * connection) 2904 * or the new socket context (opaque for MHD, must be non-NULL) 2905 * @sa #MHD_D_OPTION_REREGISTER_ALL 2906 * @ingroup event 2907 */ 2908 typedef MHD_APP_SOCKET_CNTX_TYPE * 2909 (MHD_FN_PAR_NONNULL_ (5) 2910 *MHD_SocketRegistrationUpdateCallback)( 2911 void *cls, 2912 MHD_Socket fd, 2913 enum MHD_FdState watch_for, 2914 MHD_APP_SOCKET_CNTX_TYPE *app_cntx_old, 2915 struct MHD_EventUpdateContext *ecb_cntx); 2916 2917 2918 /** 2919 * Update the sockets state. 2920 * Must be called for every socket that got state updated. 2921 * For #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL() mode 2922 * this function must be called for each socket between any two calls of 2923 * #MHD_daemon_process_reg_events() function. 2924 * Available only for daemons started in 2925 * #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL or 2926 * #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_EDGE modes. 2927 * @param daemon the daemon handle 2928 * @param ecb_cntx the context handle provided 2929 * for #MHD_SocketRegistrationUpdateCallback 2930 * @param fd_current_state the current state of the socket 2931 * @ingroup event 2932 */ 2933 MHD_EXTERN_ void 2934 MHD_daemon_event_update ( 2935 struct MHD_Daemon *MHD_RESTRICT daemon, 2936 struct MHD_EventUpdateContext *MHD_RESTRICT ecb_cntx, 2937 enum MHD_FdState fd_current_state) 2938 MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (2); 2939 2940 2941 /** 2942 * Perform all daemon activities based on FDs events provided earlier by 2943 * application via #MHD_daemon_event_update(). 2944 * 2945 * This function accepts new connections (if any), performs HTTP communications 2946 * on all active connections, closes connections as needed and performs FDs 2947 * registration updates by calling #MHD_SocketRegistrationUpdateCallback 2948 * callback for every socket that needs to be added/updated/removed. 2949 * 2950 * Available only for daemons started in #MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL or 2951 * #MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE modes. 2952 * 2953 * When used in #MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL mode, application must 2954 * provide all updates by calling #MHD_daemon_event_update() for every 2955 * registered FD between any two calls of this function. 2956 * 2957 * @param daemon the daemon handle 2958 * @param[out] next_max_wait_milsec the optional pointer to receive the 2959 next maximum wait time in milliseconds 2960 to be used for the sockets polling 2961 function, can be NULL 2962 * @return #MHD_SC_OK on success, 2963 * error code otherwise 2964 * @sa #MHD_D_OPTION_REREGISTER_ALL 2965 * @ingroup event 2966 */ 2967 MHD_EXTERN_ enum MHD_StatusCode 2968 MHD_daemon_process_reg_events ( 2969 struct MHD_Daemon *MHD_RESTRICT daemon, 2970 uint_fast64_t *MHD_RESTRICT next_max_wait_milsec) 2971 MHD_FN_PAR_NONNULL_ (1); 2972 2973 /* ********************* daemon options ************** */ 2974 2975 2976 /** 2977 * Which threading and polling mode should be used by MHD? 2978 */ 2979 enum MHD_FIXED_ENUM_APP_SET_ MHD_WorkMode 2980 { 2981 /** 2982 * Work mode with no internal threads. 2983 * The application periodically calls #MHD_daemon_process_blocking(), where 2984 * MHD internally checks all sockets automatically. 2985 * This is the default mode. 2986 * Use helper macro #MHD_D_OPTION_WM_EXTERNAL_PERIODIC() to enable 2987 * this mode. 2988 */ 2989 MHD_WM_EXTERNAL_PERIODIC = 0 2990 , 2991 /** 2992 * Work mode with an external event loop with level triggers. 2993 * MHD provides registration of all FDs to be monitored by using 2994 * #MHD_SocketRegistrationUpdateCallback, application performs level triggered 2995 * FDs polling (like select() or poll()), calls function 2996 * #MHD_daemon_event_update() for every registered FD and then calls main 2997 * function MHD_daemon_process_reg_events() to process the data. 2998 * Use helper macro #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL() to enable 2999 * this mode. 3000 * @sa #MHD_D_OPTION_REREGISTER_ALL 3001 */ 3002 MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL = 8 3003 , 3004 /** 3005 * Work mode with an external event loop with edge triggers. 3006 * MHD provides registration of all FDs to be monitored by using 3007 * #MHD_SocketRegistrationUpdateCallback, application performs edge triggered 3008 * sockets polling (like epoll with EPOLLET), calls function 3009 * #MHD_daemon_event_update() for FDs with updated states and then calls main 3010 * function MHD_daemon_process_reg_events() to process the data. 3011 * Use helper macro #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_EDGE() to enable 3012 * this mode. 3013 * @sa #MHD_D_OPTION_REREGISTER_ALL 3014 */ 3015 MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE = 9 3016 , 3017 /** 3018 * Work mode with no internal threads and aggregate watch FD. 3019 * Application uses #MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD to get single FD 3020 * that gets triggered by any MHD event. 3021 * This FD can be watched as an aggregate indicator for all MHD events. 3022 * This mode is available only on selected platforms (currently 3023 * GNU/Linux and OpenIndiana only), see #MHD_LIB_INFO_FIXED_HAS_AGGREGATE_FD. 3024 * When the FD is triggered, #MHD_daemon_process_nonblocking() should 3025 * be called. 3026 * Use helper macro #MHD_D_OPTION_WM_EXTERNAL_SINGLE_FD_WATCH() to enable 3027 * this mode. 3028 */ 3029 MHD_WM_EXTERNAL_SINGLE_FD_WATCH = 16 3030 , 3031 /** 3032 * Work mode with one or more worker threads. 3033 * If specified number of threads is one, then daemon starts with single 3034 * worker thread that handles all connections. 3035 * If number of threads is larger than one, then that number of worker 3036 * threads, and handling of connection is distributed among the workers. 3037 * Use helper macro #MHD_D_OPTION_WM_WORKER_THREADS() to enable 3038 * this mode. 3039 */ 3040 MHD_WM_WORKER_THREADS = 24 3041 , 3042 /** 3043 * Work mode with one internal thread for listening and additional threads 3044 * per every connection. Use this if handling requests is CPU-intensive or 3045 * blocking, your application is thread-safe and you have plenty of 3046 * memory (per connection). 3047 * Use helper macro #MHD_D_OPTION_WM_THREAD_PER_CONNECTION() to enable 3048 * this mode. 3049 */ 3050 MHD_WM_THREAD_PER_CONNECTION = 32 3051 }; 3052 3053 /** 3054 * Work mode parameters for #MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL and 3055 * #MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE modes 3056 */ 3057 struct MHD_WorkModeExternalEventLoopCBParam 3058 { 3059 /** 3060 * Socket registration callback 3061 */ 3062 MHD_SocketRegistrationUpdateCallback reg_cb; 3063 /** 3064 * Closure for the @a reg_cb 3065 */ 3066 void *reg_cb_cls; 3067 }; 3068 3069 /** 3070 * MHD work mode parameters 3071 */ 3072 union MHD_WorkModeParam 3073 { 3074 /** 3075 * Work mode parameters for #MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL and 3076 * #MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE modes 3077 */ 3078 struct MHD_WorkModeExternalEventLoopCBParam v_external_event_loop_cb; 3079 /** 3080 * Number of worker threads for #MHD_WM_WORKER_THREADS. 3081 * If set to one, then daemon starts with single worker thread that process 3082 * all connections. 3083 * If set to value larger than one, then that number of worker threads 3084 * and distributed handling of requests among the workers. 3085 * Zero is treated as one. 3086 */ 3087 unsigned int num_worker_threads; 3088 }; 3089 3090 /** 3091 * Parameter for #MHD_D_O_WORK_MODE(). 3092 * Not recommended to be used directly, better use macro/functions to create it: 3093 * #MHD_WM_OPTION_EXTERNAL_PERIODIC(), 3094 * #MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(), 3095 * #MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(), 3096 * #MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH(), 3097 * #MHD_WM_OPTION_WORKER_THREADS(), 3098 * #MHD_WM_OPTION_THREAD_PER_CONNECTION() 3099 */ 3100 struct MHD_WorkModeWithParam 3101 { 3102 /** 3103 * The work mode for MHD 3104 */ 3105 enum MHD_WorkMode mode; 3106 /** 3107 * The parameters used for specified work mode 3108 */ 3109 union MHD_WorkModeParam params; 3110 }; 3111 3112 3113 #if defined(MHD_USE_COMPOUND_LITERALS) && defined(MHD_USE_DESIG_NEST_INIT) 3114 /** 3115 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with 3116 * no internal threads. 3117 * The application periodically calls #MHD_daemon_process_blocking(), where 3118 * MHD internally checks all sockets automatically. 3119 * This is the default mode. 3120 * @return the object of struct MHD_WorkModeWithParam with requested values 3121 */ 3122 # define MHD_WM_OPTION_EXTERNAL_PERIODIC() \ 3123 MHD_NOWARN_COMPOUND_LITERALS_ \ 3124 (const struct MHD_WorkModeWithParam) \ 3125 { \ 3126 .mode = (MHD_WM_EXTERNAL_PERIODIC) \ 3127 } \ 3128 MHD_RESTORE_WARN_COMPOUND_LITERALS_ 3129 3130 /** 3131 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with 3132 * an external event loop with level triggers. 3133 * Application uses #MHD_SocketRegistrationUpdateCallback, level triggered 3134 * sockets polling (like select() or poll()) and #MHD_daemon_event_update(). 3135 * @param cb_val the callback for sockets registration 3136 * @param cb_cls_val the closure for the @a cv_val callback 3137 * @return the object of struct MHD_WorkModeWithParam with requested values 3138 */ 3139 # define MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(cb_val,cb_cls_val) \ 3140 MHD_NOWARN_COMPOUND_LITERALS_ \ 3141 (const struct MHD_WorkModeWithParam) \ 3142 { \ 3143 .mode = (MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL), \ 3144 .params.v_external_event_loop_cb.reg_cb = (cb_val), \ 3145 .params.v_external_event_loop_cb.reg_cb_cls = (cb_cls_val) \ 3146 } \ 3147 MHD_RESTORE_WARN_COMPOUND_LITERALS_ 3148 3149 /** 3150 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with 3151 * an external event loop with edge triggers. 3152 * Application uses #MHD_SocketRegistrationUpdateCallback, edge triggered 3153 * sockets polling (like epoll with EPOLLET) and #MHD_daemon_event_update(). 3154 * @param cb_val the callback for sockets registration 3155 * @param cb_cls_val the closure for the @a cv_val callback 3156 * @return the object of struct MHD_WorkModeWithParam with requested values 3157 */ 3158 # define MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(cb_val,cb_cls_val) \ 3159 MHD_NOWARN_COMPOUND_LITERALS_ \ 3160 (const struct MHD_WorkModeWithParam) \ 3161 { \ 3162 .mode = (MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE), \ 3163 .params.v_external_event_loop_cb.reg_cb = (cb_val), \ 3164 .params.v_external_event_loop_cb.reg_cb_cls = (cb_cls_val) \ 3165 } \ 3166 MHD_RESTORE_WARN_COMPOUND_LITERALS_ 3167 3168 /** 3169 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with 3170 * no internal threads and aggregate watch FD. 3171 * Application uses #MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD to get single FD 3172 * that gets triggered by any MHD event. 3173 * This FD can be watched as an aggregate indicator for all MHD events. 3174 * This mode is available only on selected platforms (currently 3175 * GNU/Linux only), see #MHD_LIB_INFO_FIXED_HAS_AGGREGATE_FD. 3176 * When the FD is triggered, #MHD_daemon_process_nonblocking() should 3177 * be called. 3178 * @return the object of struct MHD_WorkModeWithParam with requested values 3179 */ 3180 # define MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH() \ 3181 MHD_NOWARN_COMPOUND_LITERALS_ \ 3182 (const struct MHD_WorkModeWithParam) \ 3183 { \ 3184 .mode = (MHD_WM_EXTERNAL_SINGLE_FD_WATCH) \ 3185 } \ 3186 MHD_RESTORE_WARN_COMPOUND_LITERALS_ 3187 3188 /** 3189 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with 3190 * one or more worker threads. 3191 * If number of threads is one, then daemon starts with single worker thread 3192 * that handles all connections. 3193 * If number of threads is larger than one, then that number of worker threads, 3194 * and handling of connection is distributed among the workers. 3195 * @param num_workers the number of worker threads, zero is treated as one 3196 * @return the object of struct MHD_WorkModeWithParam with requested values 3197 */ 3198 # define MHD_WM_OPTION_WORKER_THREADS(num_workers) \ 3199 MHD_NOWARN_COMPOUND_LITERALS_ \ 3200 (const struct MHD_WorkModeWithParam) \ 3201 { \ 3202 .mode = (MHD_WM_WORKER_THREADS), \ 3203 .params.num_worker_threads = (num_workers) \ 3204 } \ 3205 MHD_RESTORE_WARN_COMPOUND_LITERALS_ 3206 3207 /** 3208 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with 3209 * one internal thread for listening and additional threads per every 3210 * connection. Use this if handling requests is CPU-intensive or blocking, 3211 * your application is thread-safe and you have plenty of memory (per 3212 * connection). 3213 * @return the object of struct MHD_WorkModeWithParam with requested values 3214 */ 3215 # define MHD_WM_OPTION_THREAD_PER_CONNECTION() \ 3216 MHD_NOWARN_COMPOUND_LITERALS_ \ 3217 (const struct MHD_WorkModeWithParam) \ 3218 { \ 3219 .mode = (MHD_WM_THREAD_PER_CONNECTION) \ 3220 } \ 3221 MHD_RESTORE_WARN_COMPOUND_LITERALS_ 3222 3223 #else /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */ 3224 MHD_NOWARN_UNUSED_FUNC_ 3225 3226 /** 3227 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with 3228 * no internal threads. 3229 * The application periodically calls #MHD_daemon_process_blocking(), where 3230 * MHD internally checks all sockets automatically. 3231 * This is the default mode. 3232 * @return the object of struct MHD_WorkModeWithParam with requested values 3233 */ 3234 static MHD_INLINE struct MHD_WorkModeWithParam 3235 MHD_WM_OPTION_EXTERNAL_PERIODIC (void) 3236 { 3237 struct MHD_WorkModeWithParam wm_val; 3238 3239 wm_val.mode = MHD_WM_EXTERNAL_PERIODIC; 3240 3241 return wm_val; 3242 } 3243 3244 3245 /** 3246 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with 3247 * an external event loop with level triggers. 3248 * Application uses #MHD_SocketRegistrationUpdateCallback, level triggered 3249 * sockets polling (like select() or poll()) and #MHD_daemon_event_update(). 3250 * @param cb_val the callback for sockets registration 3251 * @param cb_cls_val the closure for the @a cv_val callback 3252 * @return the object of struct MHD_WorkModeWithParam with requested values 3253 */ 3254 static MHD_INLINE struct MHD_WorkModeWithParam 3255 MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL ( 3256 MHD_SocketRegistrationUpdateCallback cb_val, 3257 void *cb_cls_val) 3258 { 3259 struct MHD_WorkModeWithParam wm_val; 3260 3261 wm_val.mode = MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL; 3262 wm_val.params.v_external_event_loop_cb.reg_cb = cb_val; 3263 wm_val.params.v_external_event_loop_cb.reg_cb_cls = cb_cls_val; 3264 3265 return wm_val; 3266 } 3267 3268 3269 /** 3270 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with 3271 * an external event loop with edge triggers. 3272 * Application uses #MHD_SocketRegistrationUpdateCallback, edge triggered 3273 * sockets polling (like epoll with EPOLLET) and #MHD_daemon_event_update(). 3274 * @param cb_val the callback for sockets registration 3275 * @param cb_cls_val the closure for the @a cv_val callback 3276 * @return the object of struct MHD_WorkModeWithParam with requested values 3277 */ 3278 static MHD_INLINE struct MHD_WorkModeWithParam 3279 MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE ( 3280 MHD_SocketRegistrationUpdateCallback cb_val, 3281 void *cb_cls_val) 3282 { 3283 struct MHD_WorkModeWithParam wm_val; 3284 3285 wm_val.mode = MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE; 3286 wm_val.params.v_external_event_loop_cb.reg_cb = cb_val; 3287 wm_val.params.v_external_event_loop_cb.reg_cb_cls = cb_cls_val; 3288 3289 return wm_val; 3290 } 3291 3292 3293 /** 3294 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with 3295 * no internal threads and aggregate watch FD. 3296 * Application uses #MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD to get single FD 3297 * that gets triggered by any MHD event. 3298 * This FD can be watched as an aggregate indicator for all MHD events. 3299 * This mode is available only on selected platforms (currently 3300 * GNU/Linux only), see #MHD_LIB_INFO_FIXED_HAS_AGGREGATE_FD. 3301 * When the FD is triggered, #MHD_daemon_process_nonblocking() should 3302 * be called. 3303 * @return the object of struct MHD_WorkModeWithParam with requested values 3304 */ 3305 static MHD_INLINE struct MHD_WorkModeWithParam 3306 MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH (void) 3307 { 3308 struct MHD_WorkModeWithParam wm_val; 3309 3310 wm_val.mode = MHD_WM_EXTERNAL_SINGLE_FD_WATCH; 3311 3312 return wm_val; 3313 } 3314 3315 3316 /** 3317 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with 3318 * one or more worker threads. 3319 * If number of threads is one, then daemon starts with single worker thread 3320 * that handles all connections. 3321 * If number of threads is larger than one, then that number of worker threads, 3322 * and handling of connection is distributed among the workers. 3323 * @param num_workers the number of worker threads, zero is treated as one 3324 * @return the object of struct MHD_WorkModeWithParam with requested values 3325 */ 3326 static MHD_INLINE struct MHD_WorkModeWithParam 3327 MHD_WM_OPTION_WORKER_THREADS (unsigned int num_workers) 3328 { 3329 struct MHD_WorkModeWithParam wm_val; 3330 3331 wm_val.mode = MHD_WM_WORKER_THREADS; 3332 wm_val.params.num_worker_threads = num_workers; 3333 3334 return wm_val; 3335 } 3336 3337 3338 /** 3339 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with 3340 * one internal thread for listening and additional threads per every 3341 * connection. Use this if handling requests is CPU-intensive or blocking, 3342 * your application is thread-safe and you have plenty of memory (per 3343 * connection). 3344 * @return the object of struct MHD_WorkModeWithParam with requested values 3345 */ 3346 static MHD_INLINE struct MHD_WorkModeWithParam 3347 MHD_WM_OPTION_THREAD_PER_CONNECTION (void) 3348 { 3349 struct MHD_WorkModeWithParam wm_val; 3350 3351 wm_val.mode = MHD_WM_THREAD_PER_CONNECTION; 3352 3353 return wm_val; 3354 } 3355 3356 3357 MHD_RESTORE_WARN_UNUSED_FUNC_ 3358 #endif /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */ 3359 3360 /** 3361 * @defgroup logging Log events and control 3362 */ 3363 3364 3365 /** 3366 * Type of a callback function used for logging by MHD. 3367 * 3368 * @param cls closure 3369 * @param sc status code of the event 3370 * @param fm format string (`printf()`-style) 3371 * @param ap arguments to @a fm 3372 * @ingroup logging 3373 */ 3374 typedef void 3375 (MHD_FN_PAR_NONNULL_ (3) 3376 MHD_FN_PAR_CSTR_ (3) 3377 *MHD_LoggingCallback)(void *cls, 3378 enum MHD_StatusCode sc, 3379 const char *fm, 3380 va_list ap); 3381 3382 /** 3383 * Parameter for listen socket binding type 3384 */ 3385 enum MHD_FIXED_ENUM_APP_SET_ MHD_DaemonOptionBindType 3386 { 3387 /** 3388 * The listen socket bind to the networks address with sharing the address. 3389 * Several sockets can bind to the same address. 3390 */ 3391 MHD_D_OPTION_BIND_TYPE_SHARED = -1 3392 , 3393 /** 3394 * The listen socket bind to the networks address without sharing the address, 3395 * except allowing binding to port/address which has TIME_WAIT state (the 3396 * state after closing connection). 3397 * On some platforms it may also allow to bind to specific address if other 3398 * socket already bond to the same port of wildcard address (or bind to 3399 * wildcard address when other socket already bond to specific address 3400 * with the same port). 3401 * Typically achieved by enabling 'SO_REUSEADDR' socket option. 3402 * Default. 3403 */ 3404 MHD_D_OPTION_BIND_TYPE_NOT_SHARED = 0 3405 , 3406 /** 3407 * The listen socket bind to the networks address without sharing the address. 3408 * The daemon way fail to start when any sockets still in "TIME_WAIT" state 3409 * on the same port, which effectively prevents quick restart of the daemon 3410 * on the same port. 3411 * On W32 systems it works like #MHD_D_OPTION_BIND_TYPE_NOT_SHARED due to 3412 * the OS limitations. 3413 */ 3414 MHD_D_OPTION_BIND_TYPE_NOT_SHARED_STRICTER = 1 3415 , 3416 /** 3417 * The list socket bind to the networks address in explicit exclusive mode. 3418 * Works as #MHD_D_OPTION_BIND_TYPE_NOT_SHARED_STRICTER on platforms without 3419 * support for the explicit exclusive socket use. 3420 */ 3421 MHD_D_OPTION_BIND_TYPE_EXCLUSIVE = 2 3422 }; 3423 3424 3425 /** 3426 * Possible levels of enforcement for TCP_FASTOPEN. 3427 */ 3428 enum MHD_FIXED_ENUM_APP_SET_ MHD_TCPFastOpenType 3429 { 3430 /** 3431 * Disable use of TCP_FASTOPEN. 3432 */ 3433 MHD_FOM_DISABLE = -1 3434 , 3435 /** 3436 * Enable TCP_FASTOPEN where supported. 3437 * On GNU/Linux it works with a kernel >= 3.6. 3438 * This is the default. 3439 */ 3440 MHD_FOM_AUTO = 0 3441 , 3442 /** 3443 * Require TCP_FASTOPEN. 3444 * Also causes #MHD_daemon_start() to fail if TCP_FASTOPEN cannot be enabled. 3445 */ 3446 MHD_FOM_REQUIRE = 1 3447 }; 3448 3449 3450 /** 3451 * Address family to be used by MHD. 3452 */ 3453 enum MHD_FIXED_ENUM_APP_SET_ MHD_AddressFamily 3454 { 3455 /** 3456 * Option not given, do not listen at all 3457 * (unless listen socket or address specified by 3458 * other means). 3459 */ 3460 MHD_AF_NONE = 0 3461 , 3462 /** 3463 * Pick "best" available method automatically. 3464 */ 3465 MHD_AF_AUTO = 1 3466 , 3467 /** 3468 * Use IPv4 only. 3469 */ 3470 MHD_AF_INET4 = 2 3471 , 3472 /** 3473 * Use IPv6 only. 3474 */ 3475 MHD_AF_INET6 = 3 3476 , 3477 /** 3478 * Use dual stack (IPv4 and IPv6 on the same socket). 3479 */ 3480 MHD_AF_DUAL = 4 3481 , 3482 /** 3483 * Use dual stack (IPv4 and IPv6 on the same socket), 3484 * fallback to pure IPv6 if dual stack is not possible. 3485 */ 3486 MHD_AF_DUAL_v4_OPTIONAL = 5 3487 , 3488 /** 3489 * Use dual stack (IPv4 and IPv6 on the same socket), 3490 * fallback to pure IPv4 if dual stack is not possible. 3491 */ 3492 MHD_AF_DUAL_v6_OPTIONAL = 6 3493 3494 }; 3495 3496 3497 /** 3498 * Sockets polling internal syscalls used by MHD. 3499 */ 3500 enum MHD_FIXED_ENUM_APP_SET_ MHD_SockPollSyscall 3501 { 3502 /** 3503 * Automatic selection of best-available method. This is also the 3504 * default. 3505 */ 3506 MHD_SPS_AUTO = 0 3507 , 3508 /** 3509 * Use select(). 3510 */ 3511 MHD_SPS_SELECT = 1 3512 , 3513 /** 3514 * Use poll(). 3515 */ 3516 MHD_SPS_POLL = 2 3517 , 3518 /** 3519 * Use epoll. 3520 */ 3521 MHD_SPS_EPOLL = 3 3522 , 3523 /** 3524 * Use kqueue. 3525 */ 3526 MHD_SPS_KQUEUE = 4 3527 }; 3528 3529 3530 /** 3531 * Protocol strictness levels enforced by MHD on clients. 3532 * Each level applies different parsing settings for HTTP headers and other 3533 * protocol elements. 3534 */ 3535 enum MHD_FIXED_ENUM_APP_SET_ MHD_ProtocolStrictLevel 3536 { 3537 3538 /* * Basic levels * */ 3539 /** 3540 * A sane default level of protocol enforcement for production use. 3541 * Provides a balance between enhanced security and broader compatibility, 3542 * as permitted by RFCs for HTTP servers. 3543 */ 3544 MHD_PSL_DEFAULT = 0 3545 , 3546 /** 3547 * Apply stricter protocol interpretation while remaining within 3548 * RFC-defined limits for HTTP servers. 3549 * 3550 * At this level (and stricter), using a bare LF instead of CRLF is forbidden, 3551 * and requests that include both a "Transfer-Encoding:" and 3552 * a "Content-Length:" headers are rejected. 3553 * 3554 * Suitable for public servers. 3555 */ 3556 MHD_PSL_STRICT = 1 3557 , 3558 /** 3559 * Be more permissive in interpreting the protocol, while still 3560 * operating within the RFC-defined limits for HTTP servers. 3561 */ 3562 MHD_PSL_PERMISSIVE = -1 3563 , 3564 /* * Special levels * */ 3565 /** 3566 * A stricter protocol interpretation than what is allowed by RFCs for HTTP 3567 * servers. However, it should remain fully compatible with clients correctly 3568 * following all RFC "MUST" requirements for HTTP clients. 3569 * 3570 * For chunked encoding, this level (and more restrictive ones) forbids 3571 * whitespace in chunk extensions. 3572 * For cookie parsing, this level (and more restrictive ones) rejects 3573 * the entire cookie if even a single value within it is incorrectly encoded. 3574 * 3575 * Recommended for testing clients against MHD. Can also be used for 3576 * security-centric applications, though doing so slightly violates 3577 * relevant RFC requirements for HTTP servers. 3578 */ 3579 MHD_PSL_VERY_STRICT = 2 3580 , 3581 /** 3582 * The strictest interpretation of the HTTP protocol, even stricter than 3583 * allowed by RFCs for HTTP servers. 3584 * However, it should remain fully compatible with clients complying with both 3585 * RFC "SHOULD" and "MUST" requirements for HTTP clients. 3586 * 3587 * This level can be used for testing clients against MHD. 3588 * It is not recommended for public services, as it may reject legitimate 3589 * clients that do not follow RFC "SHOULD" requirements. 3590 */ 3591 MHD_PSL_EXTRA_STRICT = 3 3592 , 3593 /** 3594 * A more relaxed protocol interpretation that violates some RFC "SHOULD" 3595 * restrictions for HTTP servers. 3596 * For cookie parsing, this level (and more permissive levels) allows 3597 * whitespace in cookie values. 3598 * 3599 * This level may be used in isolated environments. 3600 */ 3601 MHD_PSL_VERY_PERMISSIVE = -2 3602 , 3603 /** 3604 * The most flexible protocol interpretation, going beyond RFC "MUST" 3605 * requirements for HTTP servers. 3606 * 3607 * This level allows HTTP/1.1 requests without a "Host:" header. 3608 * For cookie parsing, whitespace is allowed before and after 3609 * the '=' character. 3610 * 3611 * Not recommended unless absolutely necessary to communicate with clients 3612 * that have severely broken HTTP implementations. 3613 */ 3614 MHD_PSL_EXTRA_PERMISSIVE = -3, 3615 }; 3616 3617 /** 3618 * The way Strict Level is enforced. 3619 * MHD can be compiled with limited set of strictness levels. 3620 * These values instructs MHD how to apply the request level. 3621 */ 3622 enum MHD_FIXED_ENUM_APP_SET_ MHD_UseStictLevel 3623 { 3624 /** 3625 * Use requested level if available or the nearest stricter 3626 * level. 3627 * Fail if only more permissive levels available. 3628 * Recommended value. 3629 */ 3630 MHD_USL_THIS_OR_STRICTER = 0 3631 , 3632 /** 3633 * Use requested level only. 3634 * Fail if this level is not available. 3635 */ 3636 MHD_USL_PRECISE = 1 3637 , 3638 /** 3639 * Use requested level if available or the nearest level (stricter 3640 * or more permissive). 3641 */ 3642 MHD_USL_NEAREST = 2 3643 }; 3644 3645 3646 /** 3647 * Connection memory buffer zeroing mode. 3648 * Works as a hardening measure. 3649 */ 3650 enum MHD_FIXED_ENUM_APP_SET_ MHD_ConnBufferZeroingMode 3651 { 3652 /** 3653 * Do not perform zeroing of connection memory buffer. 3654 * Default mode. 3655 */ 3656 MHD_CONN_BUFFER_ZEROING_DISABLED = 0 3657 , 3658 /** 3659 * Perform connection memory buffer zeroing before processing request. 3660 */ 3661 MHD_CONN_BUFFER_ZEROING_BASIC = 1 3662 , 3663 /** 3664 * Perform connection memory buffer zeroing before processing request and 3665 * when reusing buffer memory areas during processing request. 3666 */ 3667 MHD_CONN_BUFFER_ZEROING_HEAVY = 2 3668 }; 3669 3670 3671 /* ********************** (d) TLS support ********************** */ 3672 3673 /** 3674 * The TLS backend choice 3675 */ 3676 enum MHD_FIXED_ENUM_APP_SET_ MHD_TlsBackend 3677 { 3678 /** 3679 * Disable TLS, use plain TCP connections (default) 3680 */ 3681 MHD_TLS_BACKEND_NONE = 0 3682 , 3683 /** 3684 * Use best available TLS backend. 3685 */ 3686 MHD_TLS_BACKEND_ANY = 1 3687 , 3688 /** 3689 * Use GnuTLS as TLS backend. 3690 */ 3691 MHD_TLS_BACKEND_GNUTLS = 2 3692 , 3693 /** 3694 * Use OpenSSL as TLS backend. 3695 */ 3696 MHD_TLS_BACKEND_OPENSSL = 3 3697 , 3698 /** 3699 * Use MbedTLS as TLS backend. 3700 */ 3701 MHD_TLS_BACKEND_MBEDTLS = 4 3702 }; 3703 3704 /** 3705 * Values for #MHD_D_O_DAUTH_NONCE_BIND_TYPE. 3706 * 3707 * These values can limit the scope of validity of MHD-generated nonces. 3708 * Values can be combined with bitwise OR. 3709 * Any value, except #MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_NONE, enforce function 3710 * #MHD_digest_auth_check() (and similar functions) to check nonce by 3711 * re-generating it again with the same parameters, which is CPU-intensive 3712 * operation. 3713 */ 3714 enum MHD_FIXED_FLAGS_ENUM_APP_SET_ MHD_DaemonOptionValueDAuthBindNonce 3715 { 3716 /** 3717 * Generated nonces are valid for any request from any client until expired. 3718 * This is default and recommended value. 3719 * #MHD_digest_auth_check() (and similar functions) would check only whether 3720 * the nonce value that is used by client has been generated by MHD and not 3721 * expired yet. 3722 * It is recommended because RFC 7616 allows clients to use the same nonce 3723 * for any request in the same "protection space". 3724 * When checking client's authorisation requests CPU is loaded less if this 3725 * value is used. 3726 * This mode gives MHD maximum flexibility for nonces generation and can 3727 * prevent possible nonce collisions (and corresponding log warning messages) 3728 * when clients' requests are intensive. 3729 * This value cannot be biwise-OR combined with other values. 3730 */ 3731 MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_NONE = 0 3732 , 3733 /** 3734 * Generated nonces are valid only for the same realm. 3735 */ 3736 MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_REALM = (1 << 0) 3737 , 3738 /** 3739 * Generated nonces are valid only for the same URI (excluding parameters 3740 * after '?' in URI) and request method (GET, POST etc). 3741 * Not recommended unless "protection space" is limited to a single URI as 3742 * RFC 7616 allows clients to reuse server-generated nonces for any URI 3743 * in the same "protection space" which by default consists of all server 3744 * URIs. 3745 */ 3746 MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_URI = (1 << 1) 3747 , 3748 3749 /** 3750 * Generated nonces are valid only for the same URI including URI parameters 3751 * and request method (GET, POST etc). 3752 * This value implies #MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_URI. 3753 * Not recommended for that same reasons as 3754 * #MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_URI. 3755 */ 3756 MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_URI_PARAMS = (1 << 2) 3757 , 3758 3759 /** 3760 * Generated nonces are valid only for the single client's IP. 3761 * While it looks like security improvement, in practice the same client may 3762 * jump from one IP to another (mobile or Wi-Fi handover, DHCP re-assignment, 3763 * Multi-NAT, different proxy chain and other reasons), while IP address 3764 * spoofing could be used relatively easily. 3765 */ 3766 MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_CLIENT_IP = (1 << 3) 3767 }; 3768 3769 3770 struct MHD_ServerCredentialsContext; 3771 3772 3773 /** 3774 * Context required to provide a pre-shared key to the 3775 * server. 3776 * 3777 * @param mscc the context 3778 * @param psk_size the number of bytes in @a psk 3779 * @param psk the pre-shared-key; should be allocated with malloc(), 3780 * will be freed by MHD 3781 */ 3782 MHD_EXTERN_ enum MHD_StatusCode 3783 MHD_connection_set_psk ( 3784 struct MHD_ServerCredentialsContext *mscc, 3785 size_t psk_size, 3786 const /*void? */ char psk[MHD_FN_PAR_DYN_ARR_SIZE_ (psk_size)]); 3787 3788 #define MHD_connection_set_psk_unavailable(mscc) \ 3789 MHD_connection_set_psk (mscc, 0, NULL) 3790 3791 3792 /** 3793 * Function called to lookup the pre-shared key (PSK) for a given 3794 * HTTP connection based on the @a username. MHD will suspend handling of 3795 * the @a connection until the application calls #MHD_connection_set_psk(). 3796 * If looking up the PSK fails, the application must still call 3797 * #MHD_connection_set_psk_unavailable(). 3798 * 3799 * @param cls closure 3800 * @param connection the HTTPS connection 3801 * @param username the user name claimed by the other side 3802 * @param mscc context to pass to #MHD_connection_set_psk(). 3803 */ 3804 typedef void 3805 (*MHD_PskServerCredentialsCallback)( 3806 void *cls, 3807 const struct MHD_Connection *MHD_RESTRICT connection, 3808 const struct MHD_String *MHD_RESTRICT username, 3809 struct MHD_ServerCredentialsContext *mscc); 3810 3811 3812 /** 3813 * The specified callback will be called one time, 3814 * after network initialisation, TLS pre-initialisation, but before 3815 * the start of the internal threads (if allowed). 3816 * 3817 * This callback may use introspection call to retrieve and adjust 3818 * some of the daemon aspects. For example, TLS backend handler can be used 3819 * to configure some TLS aspects. 3820 * @param cls the callback closure 3821 */ 3822 typedef void 3823 (*MHD_DaemonReadyCallback)(void *cls); 3824 3825 3826 /** 3827 * Allow or deny a client to connect. 3828 * 3829 * @param cls closure 3830 * @param addr_len length of @a addr 3831 * @param addr address information from the client 3832 * @see #MHD_D_OPTION_ACCEPT_POLICY() 3833 * @return #MHD_YES if connection is allowed, #MHD_NO if not 3834 */ 3835 typedef enum MHD_Bool 3836 (*MHD_AcceptPolicyCallback)(void *cls, 3837 size_t addr_len, 3838 const struct sockaddr *addr); 3839 3840 3841 /** 3842 * The data for the #MHD_EarlyUriLogCallback 3843 */ 3844 struct MHD_EarlyUriCbData 3845 { 3846 /** 3847 * The request handle. 3848 * Headers are not yet available. 3849 */ 3850 struct MHD_Request *request; 3851 3852 /** 3853 * The full URI ("request target") from the HTTP request, including URI 3854 * parameters (the part after '?') 3855 */ 3856 struct MHD_String full_uri; 3857 3858 /** 3859 * The request HTTP method 3860 */ 3861 enum MHD_HTTP_Method method; 3862 }; 3863 3864 /** 3865 * Function called by MHD to allow the application to log the @a full_uri 3866 * of the new request. 3867 * This is the only moment when unmodified URI is provided. 3868 * After this callback MHD parses the URI and modifies it by extracting 3869 * GET parameters in-place. 3870 * 3871 * If this callback is set then it is the first application function called 3872 * for the new request. 3873 * 3874 * If #MHD_RequestEndedCallback is also set then it is guaranteed that 3875 * #MHD_RequestEndedCallback is called for the same request. Application 3876 * may allocate request specific data in this callback and de-allocate 3877 * the data in #MHD_RequestEndedCallback. 3878 * 3879 * @param cls client-defined closure 3880 * @param req_data the request data 3881 * @param request_app_context_ptr the pointer to variable that can be set to 3882 * the application context for the request; 3883 * initially the variable set to NULL 3884 */ 3885 typedef void 3886 (MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (3) 3887 *MHD_EarlyUriLogCallback)(void *cls, 3888 const struct MHD_EarlyUriCbData *req_data, 3889 void **request_app_context_ptr); 3890 3891 3892 /** 3893 * The `enum MHD_ConnectionNotificationCode` specifies types 3894 * of connection notifications. 3895 * @ingroup request 3896 */ 3897 enum MHD_FIXED_ENUM_MHD_SET_ MHD_ConnectionNotificationCode 3898 { 3899 3900 /** 3901 * A new connection has been started. 3902 * @ingroup request 3903 */ 3904 MHD_CONNECTION_NOTIFY_STARTED = 0 3905 , 3906 /** 3907 * A connection is closed. 3908 * @ingroup request 3909 */ 3910 MHD_CONNECTION_NOTIFY_CLOSED = 1 3911 3912 }; 3913 3914 /** 3915 * Extra details for connection notifications. 3916 * Currently not used 3917 */ 3918 union MHD_ConnectionNotificationDetails 3919 { 3920 /** 3921 * Unused 3922 */ 3923 int reserved1; 3924 }; 3925 3926 3927 /** 3928 * The connection notification data structure 3929 */ 3930 struct MHD_ConnectionNotificationData 3931 { 3932 /** 3933 * The connection handle 3934 */ 3935 struct MHD_Connection *connection; 3936 /** 3937 * The connection-specific application context data (opaque for MHD). 3938 * Initially set to NULL (for connections added by MHD) or set by 3939 * @a connection_cntx parameter for connections added by 3940 * #MHD_daemon_add_connection(). 3941 */ 3942 void *application_context; 3943 /** 3944 * The code of the event 3945 */ 3946 enum MHD_ConnectionNotificationCode code; 3947 /** 3948 * Event details 3949 */ 3950 union MHD_ConnectionNotificationDetails details; 3951 }; 3952 3953 3954 /** 3955 * Signature of the callback used by MHD to notify the 3956 * application about started/stopped network connections 3957 * 3958 * @param cls client-defined closure 3959 * @param[in,out] data the details about the event 3960 * @see #MHD_D_OPTION_NOTIFY_CONNECTION() 3961 * @ingroup request 3962 */ 3963 typedef void 3964 (MHD_FN_PAR_NONNULL_ (2) 3965 *MHD_NotifyConnectionCallback)(void *cls, 3966 struct MHD_ConnectionNotificationData *data); 3967 3968 3969 /** 3970 * The type of stream notifications. 3971 * @ingroup request 3972 */ 3973 enum MHD_FIXED_ENUM_MHD_SET_ MHD_StreamNotificationCode 3974 { 3975 /** 3976 * A new stream has been started. 3977 * @ingroup request 3978 */ 3979 MHD_STREAM_NOTIFY_STARTED = 0 3980 , 3981 /** 3982 * A stream is closed. 3983 * @ingroup request 3984 */ 3985 MHD_STREAM_NOTIFY_CLOSED = 1 3986 }; 3987 3988 /** 3989 * Additional information about stream started event 3990 */ 3991 struct MHD_StreamNotificationDetailStarted 3992 { 3993 /** 3994 * Set to #MHD_YES of the stream was started by client 3995 */ 3996 enum MHD_Bool by_client; 3997 }; 3998 3999 /** 4000 * Additional information about stream events 4001 */ 4002 union MHD_StreamNotificationDetail 4003 { 4004 /** 4005 * Information for event #MHD_STREAM_NOTIFY_STARTED 4006 */ 4007 struct MHD_StreamNotificationDetailStarted started; 4008 }; 4009 4010 /** 4011 * Stream notification data structure 4012 */ 4013 struct MHD_StreamNotificationData 4014 { 4015 /** 4016 * The handle of the stream 4017 */ 4018 struct MHD_Stream *stream; 4019 /** 4020 * The code of the event 4021 */ 4022 enum MHD_StreamNotificationCode code; 4023 /** 4024 * Detailed information about notification event 4025 */ 4026 union MHD_StreamNotificationDetail details; 4027 }; 4028 4029 4030 /** 4031 * Signature of the callback used by MHD to notify the 4032 * application about started/stopped data stream 4033 * For HTTP/1.1 it is the same like network connection 4034 * with 1:1 match. 4035 * 4036 * @param cls client-defined closure 4037 * @param data the details about the event 4038 * @see #MHD_D_OPTION_NOTIFY_STREAM() 4039 * @ingroup request 4040 */ 4041 typedef void 4042 (MHD_FN_PAR_NONNULL_ (2) 4043 *MHD_NotifyStreamCallback)( 4044 void *cls, 4045 const struct MHD_StreamNotificationData *data); 4046 4047 #include "microhttpd2_generated_daemon_options.h" 4048 4049 4050 /** 4051 * The `enum MHD_RequestEndedCode` specifies reasons 4052 * why a request has been ended. 4053 * @ingroup request 4054 */ 4055 enum MHD_FIXED_ENUM_MHD_SET_ MHD_RequestEndedCode 4056 { 4057 4058 /** 4059 * The response was successfully sent. 4060 * @ingroup request 4061 */ 4062 MHD_REQUEST_ENDED_COMPLETED_OK = 0 4063 , 4064 /** 4065 * The response was successfully sent and connection is being switched 4066 * to another protocol. 4067 * @ingroup request 4068 */ 4069 MHD_REQUEST_ENDED_COMPLETED_OK_UPGRADE = 1 4070 , 4071 /** 4072 * No activity on the connection for the number of seconds specified using 4073 * #MHD_C_OPTION_TIMEOUT(). 4074 * @ingroup request 4075 */ 4076 MHD_REQUEST_ENDED_TIMEOUT_REACHED = 10 4077 , 4078 /** 4079 * The connection was broken or TLS protocol error. 4080 * @ingroup request 4081 */ 4082 MHD_REQUEST_ENDED_CONNECTION_ERROR = 20 4083 , 4084 /** 4085 * The client terminated the connection by closing the socket either 4086 * completely or for writing (TCP half-closed) before sending complete 4087 * request. 4088 * @ingroup request 4089 */ 4090 MHD_REQUEST_ENDED_CLIENT_ABORT = 30 4091 , 4092 /** 4093 * The request is not valid according to HTTP specifications. 4094 * @ingroup request 4095 */ 4096 MHD_REQUEST_ENDED_HTTP_PROTOCOL_ERROR = 31 4097 , 4098 /** 4099 * The application aborted request without response. 4100 * @ingroup request 4101 */ 4102 MHD_REQUEST_ENDED_BY_APP_ABORT = 40 4103 , 4104 /** 4105 * The request was aborted due to the application failed to provide a valid 4106 * response. 4107 * @ingroup request 4108 */ 4109 MHD_REQUEST_ENDED_BY_APP_ERROR = 41 4110 , 4111 /** 4112 * The request was aborted due to the application failed to register external 4113 * event monitoring for the connection. 4114 * @ingroup request 4115 */ 4116 MHD_REQUEST_ENDED_BY_EXT_EVENT_ERROR = 42 4117 , 4118 /** 4119 * Error handling the connection due to resources exhausted. 4120 * @ingroup request 4121 */ 4122 MHD_REQUEST_ENDED_NO_RESOURCES = 50 4123 , 4124 /** 4125 * The request was aborted due to error reading file for file-backed response 4126 * @ingroup request 4127 */ 4128 MHD_REQUEST_ENDED_FILE_ERROR = 51 4129 , 4130 /** 4131 * The request was aborted due to error generating valid nonce for Digest Auth 4132 * @ingroup request 4133 */ 4134 MHD_REQUEST_ENDED_NONCE_ERROR = 52 4135 , 4136 /** 4137 * Closing the session since MHD is being shut down. 4138 * @ingroup request 4139 */ 4140 MHD_REQUEST_ENDED_DAEMON_SHUTDOWN = 60 4141 }; 4142 4143 /** 4144 * Additional information about request ending 4145 */ 4146 union MHD_RequestEndedDetail 4147 { 4148 /** 4149 * Reserved member. 4150 * Do not use. 4151 */ 4152 void *reserved; 4153 }; 4154 4155 /** 4156 * Request termination data structure 4157 */ 4158 struct MHD_RequestEndedData 4159 { 4160 /** 4161 * The request handle. 4162 * Note that most of the request data may be already unvailable. 4163 */ 4164 struct MHD_Request *req; 4165 /** 4166 * The code of the event 4167 */ 4168 enum MHD_RequestEndedCode code; 4169 /** 4170 * Detailed information about the event 4171 */ 4172 union MHD_RequestEndedDetail details; 4173 }; 4174 4175 4176 /** 4177 * Signature of the callback used by MHD to notify the application 4178 * about completed requests. 4179 * 4180 * This is the last callback called for any request (if provided by 4181 * the application). 4182 * 4183 * @param cls client-defined closure 4184 * @param data the details about the event 4185 * @param request_app_context the application request context, as possibly set 4186 by the #MHD_EarlyUriLogCallback 4187 * @see #MHD_R_OPTION_TERMINATION_CALLBACK() 4188 * @ingroup request 4189 */ 4190 typedef void 4191 (*MHD_RequestEndedCallback) (void *cls, 4192 const struct MHD_RequestEndedData *data, 4193 void *request_app_context); 4194 4195 4196 #include "microhttpd2_generated_response_options.h" 4197 /* Beginning of generated code documenting how to use options. 4198 You should treat the following functions *as if* they were 4199 part of the header/API. The actual declarations are more 4200 complex, so these here are just for documentation! 4201 We do not actually *build* this code... */ 4202 #if 0 4203 4204 /** 4205 * Set MHD work (threading and polling) mode. 4206 * Consider use of #MHD_D_OPTION_WM_EXTERNAL_PERIODIC(), #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL(), #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_EDGE(), #MHD_D_OPTION_WM_EXTERNAL_SINGLE_FD_WATCH(), #MHD_D_OPTION_WM_WORKER_THREADS() or #MHD_D_OPTION_WM_THREAD_PER_CONNECTION() instead of direct use of this parameter. 4207 * @param wmp the object created by one of the next functions/macros: #MHD_WM_OPTION_EXTERNAL_PERIODIC(), #MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(), #MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(), #MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH(), #MHD_WM_OPTION_WORKER_THREADS(), #MHD_WM_OPTION_THREAD_PER_CONNECTION() 4208 * @return structure with the requested setting 4209 */ 4210 struct MHD_DaemonOptionAndValue 4211 MHD_D_OPTION_WORK_MODE ( 4212 struct MHD_WorkModeWithParam wmp 4213 ); 4214 4215 /** 4216 * Select a sockets watch system call used for internal polling. 4217 * @param els FIXME 4218 * @return structure with the requested setting 4219 */ 4220 struct MHD_DaemonOptionAndValue 4221 MHD_D_OPTION_POLL_SYSCALL ( 4222 enum MHD_SockPollSyscall els 4223 ); 4224 4225 /** 4226 * Instruct MHD to register all sockets every processing round. 4227 * 4228 By default (this options is not enabled) every processing round (every time 4229 * when #MHD_daemon_event_update() is called) MHD calls 4230 * #MHD_SocketRegistrationUpdateCallback only for the new sockets, for 4231 * the removed sockets and for the updated sockets. 4232 * Some sockets are registered when #MHD_daemon_start() is called. 4233 * 4234 If this options is enabled, then #MHD_SocketRegistrationUpdateCallback is 4235 * called for every socket each processing round. No sockets are registered when 4236 * the daemon is being started. 4237 * @param value the value of the parameter * @return structure with the requested setting 4238 */ 4239 struct MHD_DaemonOptionAndValue 4240 MHD_D_OPTION_REREGISTER_ALL ( 4241 enum MHD_Bool value 4242 ); 4243 4244 /** 4245 * Set a callback to use for logging 4246 * @param log_cb the callback to use for logging, 4247 * NULL to disable logging. 4248 * The logging to stderr is enabled by default. 4249 * @param log_cb_cls the closure for the logging callback 4250 * @return structure with the requested setting 4251 */ 4252 struct MHD_DaemonOptionAndValue 4253 MHD_D_OPTION_LOG_CALLBACK ( 4254 MHD_LoggingCallback log_cb, 4255 void *log_cb_cls 4256 ); 4257 4258 /** 4259 * Bind to the given TCP port and address family. 4260 * 4261 Does not work with #MHD_D_OPTION_BIND_SA() or #MHD_D_OPTION_LISTEN_SOCKET(). 4262 * 4263 If no listen socket optins (#MHD_D_OPTION_BIND_PORT(), #MHD_D_OPTION_BIND_SA(), #MHD_D_OPTION_LISTEN_SOCKET()) are used, MHD does not listen for incoming connection. 4264 * @param af the address family to use, 4265 * the #MHD_AF_NONE to disable listen socket (the same effect as if this option is not used) 4266 * @param port port to use, 0 to let system assign any free port, 4267 * ignored if @a af is #MHD_AF_NONE 4268 * @return structure with the requested setting 4269 */ 4270 struct MHD_DaemonOptionAndValue 4271 MHD_D_OPTION_BIND_PORT ( 4272 enum MHD_AddressFamily af, 4273 uint_least16_t port 4274 ); 4275 4276 /** 4277 * Bind to the given socket address. 4278 * 4279 Does not work with #MHD_D_OPTION_BIND_PORT() or #MHD_D_OPTION_LISTEN_SOCKET(). 4280 * 4281 If no listen socket optins (#MHD_D_OPTION_BIND_PORT(), #MHD_D_OPTION_BIND_SA(), #MHD_D_OPTION_LISTEN_SOCKET()) are used, MHD does not listen for incoming connection. 4282 * @param sa_len the size of the socket address pointed by @a sa. 4283 * @param sa the address to bind to; can be IPv4 (AF_INET), IPv6 (AF_INET6) or even a UNIX domain socket (AF_UNIX) 4284 * @param dual When a previous version of the protocol exist (like IPv4 when @a v_sa is IPv6) bind to both protocols (IPv6 and IPv4). 4285 * @return structure with the requested setting 4286 */ 4287 struct MHD_DaemonOptionAndValue 4288 MHD_D_OPTION_BIND_SA ( 4289 size_t sa_len, 4290 /* const */ struct sockaddr *sa, 4291 enum MHD_Bool dual 4292 ); 4293 4294 /** 4295 * Accept connections from the given socket. Socket 4296 * must be a TCP or UNIX domain (SOCK_STREAM) socket. 4297 * 4298 Does not work with #MHD_D_OPTION_BIND_PORT() or #MHD_D_OPTION_BIND_SA(). 4299 * 4300 If no listen socket optins (#MHD_D_OPTION_BIND_PORT(), #MHD_D_OPTION_BIND_SA(), #MHD_D_OPTION_LISTEN_SOCKET()) are used, MHD does not listen for incoming connection. 4301 * @param listen_fd the listen socket to use, ignored if set to #MHD_INVALID_SOCKET 4302 * @return structure with the requested setting 4303 */ 4304 struct MHD_DaemonOptionAndValue 4305 MHD_D_OPTION_LISTEN_SOCKET ( 4306 MHD_Socket listen_fd 4307 ); 4308 4309 /** 4310 * Select mode of reusing address:port listen address. 4311 * 4312 Works only when #MHD_D_OPTION_BIND_PORT() or #MHD_D_OPTION_BIND_SA() are used. 4313 * @param reuse_type FIXME 4314 * @return structure with the requested setting 4315 */ 4316 struct MHD_DaemonOptionAndValue 4317 MHD_D_OPTION_LISTEN_ADDR_REUSE ( 4318 enum MHD_DaemonOptionBindType reuse_type 4319 ); 4320 4321 /** 4322 * Configure TCP_FASTOPEN option, including setting a 4323 * custom @a queue_length. 4324 * 4325 Note that having a larger queue size can cause resource exhaustion 4326 * attack as the TCP stack has to now allocate resources for the SYN 4327 * packet along with its DATA. 4328 * 4329 Works only when #MHD_D_OPTION_BIND_PORT() or #MHD_D_OPTION_BIND_SA() are used. 4330 * @param option the type use of of TCP FastOpen 4331 * @param queue_length the length of the queue, zero to use system or MHD default, 4332 * silently ignored on platforms without support for custom queue size 4333 * @return structure with the requested setting 4334 */ 4335 struct MHD_DaemonOptionAndValue 4336 MHD_D_OPTION_TCP_FASTOPEN ( 4337 enum MHD_TCPFastOpenType option, 4338 unsigned int queue_length 4339 ); 4340 4341 /** 4342 * Use the given backlog for the listen() call. 4343 * 4344 Works only when #MHD_D_OPTION_BIND_PORT() or #MHD_D_OPTION_BIND_SA() are used. 4345 * Zero parameter treated as MHD/system default. 4346 * @param backlog_size FIXME 4347 * @return structure with the requested setting 4348 */ 4349 struct MHD_DaemonOptionAndValue 4350 MHD_D_OPTION_LISTEN_BACKLOG ( 4351 unsigned int backlog_size 4352 ); 4353 4354 /** 4355 * Inform that SIGPIPE is suppressed or handled by application. 4356 * If suppressed/handled, MHD uses network functions that could generate SIGPIPE, like `sendfile()`. 4357 * Silently ignored when MHD creates internal threads as for them SIGPIPE is suppressed automatically. 4358 * @param value the value of the parameter * @return structure with the requested setting 4359 */ 4360 struct MHD_DaemonOptionAndValue 4361 MHD_D_OPTION_SIGPIPE_SUPPRESSED ( 4362 enum MHD_Bool value 4363 ); 4364 4365 /** 4366 * Enable TLS (HTTPS) and select TLS backend 4367 * @param backend the TLS backend to use, 4368 * #MHD_TLS_BACKEND_NONE for non-TLS (plain TCP) connections 4369 * @return structure with the requested setting 4370 */ 4371 struct MHD_DaemonOptionAndValue 4372 MHD_D_OPTION_TLS ( 4373 enum MHD_TlsBackend backend 4374 ); 4375 4376 /** 4377 * Provide TLS key and certificate data in-memory. 4378 * Works only if TLS mode is enabled. 4379 * @param mem_cert The X.509 certificates chain in PEM format loaded into memory (not a filename). 4380 * The first certificate must be the server certificate, following by the chain of signing 4381 * certificates up to (but not including) CA root certificate. 4382 * @param mem_key the private key in PEM format loaded into memory (not a filename) 4383 * @param mem_pass the option passphrase phrase to decrypt the private key, 4384 * could be NULL if private key does not need a password 4385 * @return structure with the requested setting 4386 */ 4387 struct MHD_DaemonOptionAndValue 4388 MHD_D_OPTION_TLS_CERT_KEY ( 4389 /* const */ char *mem_cert, 4390 const char *mem_key, 4391 const char *mem_pass 4392 ); 4393 4394 /** 4395 * Provide the certificate of the certificate authority (CA) to be used by the MHD daemon for client authentication. 4396 * Works only if TLS mode is enabled. 4397 * @param mem_client_ca the CA certificate in memory (not a filename) 4398 * @return structure with the requested setting 4399 */ 4400 struct MHD_DaemonOptionAndValue 4401 MHD_D_OPTION_TLS_CLIENT_CA ( 4402 const char *mem_client_ca 4403 ); 4404 4405 /** 4406 * Configure PSK to use for the TLS key exchange. 4407 * @param psk_cb the function to call to obtain pre-shared key 4408 * @param psk_cb_cls the closure for @a psk_cb 4409 * @return structure with the requested setting 4410 */ 4411 struct MHD_DaemonOptionAndValue 4412 MHD_D_OPTION_TLS_PSK_CALLBACK ( 4413 MHD_PskServerCredentialsCallback psk_cb, 4414 void *psk_cb_cls 4415 ); 4416 4417 /** 4418 * Control ALPN for TLS connection. 4419 * Silently ignored for non-TLS. 4420 * By default ALPN is automatically used for TLS connections. 4421 * @param value the value of the parameter * @return structure with the requested setting 4422 */ 4423 struct MHD_DaemonOptionAndValue 4424 MHD_D_OPTION_NO_ALPN ( 4425 enum MHD_Bool value 4426 ); 4427 4428 /** 4429 * Provide application name to load dedicated section in TLS backend's configuration file. 4430 * Search for "System-wide configuration of the library" for GnuTLS documentation or 4431 * for "config, OPENSSL LIBRARY CONFIGURATION" for OpenSSL documentation. 4432 * If not specified the default backend configuration is used: 4433 * "@LIBMICROHTTPD" (if available), then "@SYSTEM" (if available) then default priorities, then "NORMAL" for GnuTLS; 4434 * "libmicrohttpd" (if available), then default name ("openssl_conf") for OpenSSL. 4435 * Ignored when MbedTLS is used as daemon's TLS backend. 4436 * @param app_name the name of the application, used as converted to 4437 * uppercase (with '@'-prefixed) for GnuTLS and as converted to 4438 * lowercase for OpenSSL; must not be longer than 127 characters 4439 * @param disable_fallback forbid use fallback/default configuration if specified 4440 * configuration is not found; also forbid ignoring errors in the 4441 * configuration on TLS backends, which may ignoring configuration 4442 * errors 4443 * @return structure with the requested setting 4444 */ 4445 struct MHD_DaemonOptionAndValue 4446 MHD_D_OPTION_TLS_APP_NAME ( 4447 char *app_name, 4448 enum MHD_Bool disable_fallback 4449 ); 4450 4451 /** 4452 * Set the configuration pathname for OpenSSL configuration file 4453 * Ignored OpenSSL is not used as daemon's TLS backend. 4454 * @param pathname the path and the name of the OpenSSL configuration file, 4455 * if only the name is provided then standard path for 4456 * configuration files is used, 4457 * could be NULL to use default configuration file pathname 4458 * or an empty (zero-size) string to disable file loading 4459 * @param disable_fallback forbid use of fallback/default location and name of 4460 * the OpenSSL configuration file; also forbid initialisation without 4461 * configuration file 4462 * @return structure with the requested setting 4463 */ 4464 struct MHD_DaemonOptionAndValue 4465 MHD_D_OPTION_TLS_OPENSSL_DEF_FILE ( 4466 char *pathname, 4467 enum MHD_Bool disable_fallback 4468 ); 4469 4470 /** 4471 * Specify the inactivity timeout for a connection in milliseconds. 4472 * If a connection remains idle (no activity) for this many 4473 * milliseconds, it is closed automatically. 4474 * Use zero for no timeout; this is also the (unsafe!) 4475 * default. 4476 * Values larger than 1209600000 (two weeks) are silently 4477 * clamped to 1209600000. 4478 * Precise closing time is not guaranteed and depends on 4479 * system clock granularity and amount of time spent on 4480 * processing other connections. Typical precision is 4481 * within +/- 30 milliseconds, while the worst case could 4482 * be greater than +/- 1 second. 4483 * Values below 1500 milliseconds are risky as they 4484 * may cause valid connections to be aborted and may 4485 * increase load the server load due to clients' repetitive 4486 * automatic retries. 4487 * @param timeout the timeout in milliseconds, zero for no timeout 4488 * @return structure with the requested setting 4489 */ 4490 struct MHD_DaemonOptionAndValue 4491 MHD_D_OPTION_DEFAULT_TIMEOUT_MILSEC ( 4492 uint_fast32_t timeout 4493 ); 4494 4495 /** 4496 * Maximum number of (concurrent) network connections served by daemon. 4497 * @note The real maximum number of network connections could be smaller 4498 * than requested due to the system limitations, like FD_SETSIZE when 4499 * polling by select() is used. 4500 * @param glob_limit FIXME 4501 * @return structure with the requested setting 4502 */ 4503 struct MHD_DaemonOptionAndValue 4504 MHD_D_OPTION_GLOBAL_CONNECTION_LIMIT ( 4505 unsigned int glob_limit 4506 ); 4507 4508 /** 4509 * Limit on the number of (concurrent) network connections made to the server from the same IP address. 4510 * Can be used to prevent one IP from taking over all of the allowed connections. If the same IP tries to establish more than the specified number of connections, they will be immediately rejected. 4511 * @param limit FIXME 4512 * @return structure with the requested setting 4513 */ 4514 struct MHD_DaemonOptionAndValue 4515 MHD_D_OPTION_PER_IP_LIMIT ( 4516 unsigned int limit 4517 ); 4518 4519 /** 4520 * Set a policy callback that accepts/rejects connections based on the client's IP address. The callbeck function will be called before servicing any new incoming connection. 4521 * @param apc the accept policy callback 4522 * @param apc_cls the closure for the callback 4523 * @return structure with the requested setting 4524 */ 4525 struct MHD_DaemonOptionAndValue 4526 MHD_D_OPTION_ACCEPT_POLICY ( 4527 MHD_AcceptPolicyCallback apc, 4528 void *apc_cls 4529 ); 4530 4531 /** 4532 * Set mode of connection memory buffer zeroing 4533 * @param buff_zeroing buffer zeroing mode 4534 * @return structure with the requested setting 4535 */ 4536 struct MHD_DaemonOptionAndValue 4537 MHD_D_OPTION_CONN_BUFF_ZEROING ( 4538 enum MHD_ConnBufferZeroingMode buff_zeroing 4539 ); 4540 4541 /** 4542 * Set how strictly MHD will enforce the HTTP protocol. 4543 * @param sl the level of strictness 4544 * @param how the way how to use the requested level 4545 * @return structure with the requested setting 4546 */ 4547 struct MHD_DaemonOptionAndValue 4548 MHD_D_OPTION_PROTOCOL_STRICT_LEVEL ( 4549 enum MHD_ProtocolStrictLevel sl, 4550 enum MHD_UseStictLevel how 4551 ); 4552 4553 /** 4554 * Set a callback to be called first for every request when the request line is received (before any parsing of the header). 4555 * This callback is the only way to get raw (unmodified) request URI as URI is parsed and modified by MHD in-place. 4556 * Mandatory URI modification may apply before this call, like binary zero replacement, as required by RFCs. 4557 * @param cb the early URI callback 4558 * @param cls the closure for the callback 4559 * @return structure with the requested setting 4560 */ 4561 struct MHD_DaemonOptionAndValue 4562 MHD_D_OPTION_EARLY_URI_LOGGER ( 4563 MHD_EarlyUriLogCallback cb, 4564 void *cls 4565 ); 4566 4567 /** 4568 * Disable converting plus ('+') character to space in GET parameters (URI part after '?'). 4569 * Plus conversion is not required by HTTP RFCs, however it required by HTML specifications, see https://url.spec.whatwg.org/#application/x-www-form-urlencoded for details. 4570 * By default plus is converted to space in the query part of URI. 4571 * @param value the value of the parameter * @return structure with the requested setting 4572 */ 4573 struct MHD_DaemonOptionAndValue 4574 MHD_D_OPTION_DISABLE_URI_QUERY_PLUS_AS_SPACE ( 4575 enum MHD_Bool value 4576 ); 4577 4578 /** 4579 * Suppresse use of 'Date:' header. 4580 * According to RFC should be suppressed only if the system has no RTC. 4581 * The 'Date:' is not suppressed (the header is enabled) by default. 4582 * @param value the value of the parameter * @return structure with the requested setting 4583 */ 4584 struct MHD_DaemonOptionAndValue 4585 MHD_D_OPTION_SUPPRESS_DATE_HEADER ( 4586 enum MHD_Bool value 4587 ); 4588 4589 /** 4590 * Use SHOUTcast for responses. 4591 * This will cause *all* responses to begin with the SHOUTcast 'ICY' line instead of 'HTTP'. 4592 * @param value the value of the parameter * @return structure with the requested setting 4593 */ 4594 struct MHD_DaemonOptionAndValue 4595 MHD_D_OPTION_ENABLE_SHOUTCAST ( 4596 enum MHD_Bool value 4597 ); 4598 4599 /** 4600 * Maximum memory size per connection. 4601 * Default is 32kb. 4602 * Values above 128kb are unlikely to result in much performance benefit, as half of the memory will be typically used for IO, and TCP buffers are unlikely to support window sizes above 64k on most systems. 4603 * The size should be large enough to fit all request headers (together with internal parsing information). 4604 * @param value the value of the parameter * @return structure with the requested setting 4605 */ 4606 struct MHD_DaemonOptionAndValue 4607 MHD_D_OPTION_CONN_MEMORY_LIMIT ( 4608 size_t value 4609 ); 4610 4611 /** 4612 * The size of the shared memory pool for accamulated upload processing. 4613 * The same large pool is shared for all connections server by MHD and used when application requests avoiding of incremental upload processing to accamulate complete content upload before giving it to the application. 4614 * Default is 8Mb. 4615 * Can be set to zero to disable share pool. 4616 * @param value the value of the parameter * @return structure with the requested setting 4617 */ 4618 struct MHD_DaemonOptionAndValue 4619 MHD_D_OPTION_LARGE_POOL_SIZE ( 4620 size_t value 4621 ); 4622 4623 /** 4624 * Desired size of the stack for the threads started by MHD. 4625 * Use 0 for system default, which is also MHD default. 4626 * Works only with #MHD_D_OPTION_WM_WORKER_THREADS() or #MHD_D_OPTION_WM_THREAD_PER_CONNECTION(). 4627 * @param value the value of the parameter * @return structure with the requested setting 4628 */ 4629 struct MHD_DaemonOptionAndValue 4630 MHD_D_OPTION_STACK_SIZE ( 4631 size_t value 4632 ); 4633 4634 /** 4635 * The the maximum FD value. 4636 * The limit is applied to all sockets used by MHD. 4637 * If listen socket FD is equal or higher that specified value, the daemon fail to start. 4638 * If new connection FD is equal or higher that specified value, the connection is rejected. 4639 * Useful if application uses select() for polling the sockets, system FD_SETSIZE is good value for this option in such case. 4640 * Silently ignored on W32 (WinSock sockets). 4641 * @param max_fd FIXME 4642 * @return structure with the requested setting 4643 */ 4644 struct MHD_DaemonOptionAndValue 4645 MHD_D_OPTION_FD_NUMBER_LIMIT ( 4646 MHD_Socket max_fd 4647 ); 4648 4649 /** 4650 * Enable `turbo`. 4651 * Disables certain calls to `shutdown()`, enables aggressive non-blocking optimistic reads and other potentially unsafe optimisations. 4652 * Most effects only happen with internal threads with epoll. 4653 * The 'turbo' mode is not enabled (mode is disabled) by default. 4654 * @param value the value of the parameter * @return structure with the requested setting 4655 */ 4656 struct MHD_DaemonOptionAndValue 4657 MHD_D_OPTION_TURBO ( 4658 enum MHD_Bool value 4659 ); 4660 4661 /** 4662 * Disable some internal thread safety. 4663 * Indicates that MHD daemon will be used by application in single-threaded mode only. When this flag is set then application must call any MHD function only within a single thread. 4664 * This flag turns off some internal thread-safety and allows MHD making some of the internal optimisations suitable only for single-threaded environment. 4665 * Not compatible with any internal threads modes. 4666 * If MHD is compiled with custom configuration for embedded projects without threads support, this option is mandatory. 4667 * Thread safety is not disabled (safety is enabled) by default. 4668 * @param value the value of the parameter * @return structure with the requested setting 4669 */ 4670 struct MHD_DaemonOptionAndValue 4671 MHD_D_OPTION_DISABLE_THREAD_SAFETY ( 4672 enum MHD_Bool value 4673 ); 4674 4675 /** 4676 * You need to set this option if you want to disable use of HTTP Upgrade. 4677 * Upgrade may require usage of additional internal resources, which we can avoid providing if they will not be used. 4678 * You should only use this option if you do not use upgrade functionality and need a generally minor boost in performance and resources saving. 4679 * The upgrade is not disallowed (upgrade is allowed) by default. 4680 * @param value the value of the parameter * @return structure with the requested setting 4681 */ 4682 struct MHD_DaemonOptionAndValue 4683 MHD_D_OPTION_DISALLOW_UPGRADE ( 4684 enum MHD_Bool value 4685 ); 4686 4687 /** 4688 * Disable #MHD_action_suspend() functionality. 4689 * 4690 You should only use this function if you do not use suspend functionality and need a generally minor boost in performance. 4691 * The suspend is not disallowed (suspend is allowed) by default. 4692 * @param value the value of the parameter * @return structure with the requested setting 4693 */ 4694 struct MHD_DaemonOptionAndValue 4695 MHD_D_OPTION_DISALLOW_SUSPEND_RESUME ( 4696 enum MHD_Bool value 4697 ); 4698 4699 /** 4700 * Disable cookies parsing. 4701 * 4702 Disable automatic cookies processing if cookies are not used. 4703 * Cookies are automatically parsed by default. 4704 * @param value the value of the parameter * @return structure with the requested setting 4705 */ 4706 struct MHD_DaemonOptionAndValue 4707 MHD_D_OPTION_DISABLE_COOKIES ( 4708 enum MHD_Bool value 4709 ); 4710 4711 /** 4712 * Set a callback to be called for pre-start finalisation. 4713 * 4714 The specified callback will be called one time, after network initialisation, TLS pre-initialisation, but before the start of the internal threads (if allowed) 4715 * @param cb the pre-start callback 4716 * @param cb_cls the closure for the callback 4717 * @return structure with the requested setting 4718 */ 4719 struct MHD_DaemonOptionAndValue 4720 MHD_D_OPTION_DAEMON_READY_CALLBACK ( 4721 MHD_DaemonReadyCallback cb, 4722 void *cb_cls 4723 ); 4724 4725 /** 4726 * Set a function that should be called whenever a connection is started or closed. 4727 * @param ncc the callback for notifications 4728 * @param cls the closure for the callback 4729 * @return structure with the requested setting 4730 */ 4731 struct MHD_DaemonOptionAndValue 4732 MHD_D_OPTION_NOTIFY_CONNECTION ( 4733 MHD_NotifyConnectionCallback ncc, 4734 void *cls 4735 ); 4736 4737 /** 4738 * Register a function that should be called whenever a stream is started or closed. 4739 * For HTTP/1.1 this callback is called one time for every connection. 4740 * @param nsc the callback for notifications 4741 * @param cls the closure for the callback 4742 * @return structure with the requested setting 4743 */ 4744 struct MHD_DaemonOptionAndValue 4745 MHD_D_OPTION_NOTIFY_STREAM ( 4746 MHD_NotifyStreamCallback nsc, 4747 void *cls 4748 ); 4749 4750 /** 4751 * Set strong random data to be used by MHD. 4752 * Currently the data is only needed for Digest Auth module. 4753 * Daemon support for Digest Auth is enabled automatically if this option is used. 4754 * The recommended size is between 8 and 32 bytes. Security can be lower for sizes less or equal four. 4755 * Sizes larger then 32 (or, probably, larger than 16 - debatable) will not increase the security. 4756 * @param buf_size the size of the buffer 4757 * @param buf the buffer with strong random data, the content will be copied by MHD 4758 * @return structure with the requested setting 4759 */ 4760 struct MHD_DaemonOptionAndValue 4761 MHD_D_OPTION_RANDOM_ENTROPY ( 4762 size_t buf_size, 4763 /* const */ void *buf 4764 ); 4765 4766 /** 4767 * Specify the size of the internal hash map array that tracks generated digest nonces usage. 4768 * When the size of the map is too small then need to handle concurrent DAuth requests, a lot of stale nonce results will be produced. 4769 * By default the size is 1000 entries. 4770 * @param size the size of the map array 4771 * @return structure with the requested setting 4772 */ 4773 struct MHD_DaemonOptionAndValue 4774 MHD_D_OPTION_AUTH_DIGEST_MAP_SIZE ( 4775 size_t size 4776 ); 4777 4778 /** 4779 * Nonce validity time (in seconds) used for Digest Auth. 4780 * If followed by zero value the value is silently ignored. 4781 * @see #MHD_digest_auth_check(), MHD_digest_auth_check_digest() 4782 * @param timeout FIXME 4783 * @return structure with the requested setting 4784 */ 4785 struct MHD_DaemonOptionAndValue 4786 MHD_D_OPTION_AUTH_DIGEST_NONCE_TIMEOUT ( 4787 unsigned int timeout 4788 ); 4789 4790 /** 4791 * Default maximum nc (nonce count) value used for Digest Auth. 4792 * If followed by zero value the value is silently ignored. 4793 * @see #MHD_digest_auth_check(), MHD_digest_auth_check_digest() 4794 * @param max_nc FIXME 4795 * @return structure with the requested setting 4796 */ 4797 struct MHD_DaemonOptionAndValue 4798 MHD_D_OPTION_AUTH_DIGEST_DEF_MAX_NC ( 4799 uint_fast32_t max_nc 4800 ); 4801 4802 /* End of generated code documenting how to use options */ 4803 #endif 4804 4805 /* Beginning of generated code documenting how to use options. 4806 You should treat the following functions *as if* they were 4807 part of the header/API. The actual declarations are more 4808 complex, so these here are just for documentation! 4809 We do not actually *build* this code... */ 4810 #if 0 4811 4812 /** 4813 * Make the response object re-usable. 4814 * The response will not be consumed by MHD_action_from_response() and must be destroyed by MHD_response_destroy(). 4815 * Useful if the same response is often used to reply. 4816 * @param value the value of the parameter * @return structure with the requested setting 4817 */ 4818 struct MHD_ResponseOptionAndValue 4819 MHD_R_OPTION_REUSABLE ( 4820 enum MHD_Bool value 4821 ); 4822 4823 /** 4824 * Enable special processing of the response as body-less (with undefined body size). No automatic 'Content-Length' or 'Transfer-Encoding: chunked' headers are added when the response is used with #MHD_HTTP_STATUS_NOT_MODIFIED code or to respond to HEAD request. 4825 * The flag also allow to set arbitrary 'Content-Length' by #MHD_response_add_header() function. 4826 * This flag value can be used only with responses created without body (zero-size body). 4827 * Responses with this flag enabled cannot be used in situations where reply body must be sent to the client. 4828 * This flag is primarily intended to be used when automatic 'Content-Length' header is undesirable in response to HEAD requests. 4829 * @param value the value of the parameter * @return structure with the requested setting 4830 */ 4831 struct MHD_ResponseOptionAndValue 4832 MHD_R_OPTION_HEAD_ONLY_RESPONSE ( 4833 enum MHD_Bool value 4834 ); 4835 4836 /** 4837 * Force use of chunked encoding even if the response content size is known. 4838 * Ignored when the reply cannot have body/content. 4839 * @param value the value of the parameter * @return structure with the requested setting 4840 */ 4841 struct MHD_ResponseOptionAndValue 4842 MHD_R_OPTION_CHUNKED_ENC ( 4843 enum MHD_Bool value 4844 ); 4845 4846 /** 4847 * Force close connection after sending the response, prevents keep-alive connections and adds 'Connection: close' header. 4848 * @param value the value of the parameter * @return structure with the requested setting 4849 */ 4850 struct MHD_ResponseOptionAndValue 4851 MHD_R_OPTION_CONN_CLOSE ( 4852 enum MHD_Bool value 4853 ); 4854 4855 /** 4856 * Only respond in conservative (dumb) HTTP/1.0-compatible mode. 4857 * Response still use HTTP/1.1 version in header, but always close the connection after sending the response and do not use chunked encoding for the response. 4858 * You can also set the #MHD_R_O_HTTP_1_0_SERVER flag to force HTTP/1.0 version in the response. 4859 * Responses are still compatible with HTTP/1.1. 4860 * Summary: 4861 * + declared reply version: HTTP/1.1 4862 * + keep-alive: no 4863 * + chunked: no 4864 * 4865 This option can be used to communicate with some broken client, which does not implement HTTP/1.1 features, but advertises HTTP/1.1 support. 4866 * @param value the value of the parameter * @return structure with the requested setting 4867 */ 4868 struct MHD_ResponseOptionAndValue 4869 MHD_R_OPTION_HTTP_1_0_COMPATIBLE_STRICT ( 4870 enum MHD_Bool value 4871 ); 4872 4873 /** 4874 * Only respond in HTTP/1.0-mode. 4875 * Contrary to the #MHD_R_O_HTTP_1_0_COMPATIBLE_STRICT flag, the response's HTTP version will always be set to 1.0 and keep-alive connections will be used if explicitly requested by the client. 4876 * The 'Connection:' header will be added for both 'close' and 'keep-alive' connections. 4877 * Chunked encoding will not be used for the response. 4878 * Due to backward compatibility, responses still can be used with HTTP/1.1 clients. 4879 * This option can be used to emulate HTTP/1.0 server (for response part only as chunked encoding in requests (if any) is processed by MHD). 4880 * Summary: 4881 * + declared reply version: HTTP/1.0 4882 * + keep-alive: possible 4883 * + chunked: no 4884 * 4885 With this option HTTP/1.0 server is emulated (with support for 'keep-alive' connections). 4886 * @param value the value of the parameter * @return structure with the requested setting 4887 */ 4888 struct MHD_ResponseOptionAndValue 4889 MHD_R_OPTION_HTTP_1_0_SERVER ( 4890 enum MHD_Bool value 4891 ); 4892 4893 /** 4894 * Disable sanity check preventing clients from manually setting the HTTP content length option. 4895 * Allow to set several 'Content-Length' headers. These headers will be used even with replies without body. 4896 * @param value the value of the parameter * @return structure with the requested setting 4897 */ 4898 struct MHD_ResponseOptionAndValue 4899 MHD_R_OPTION_INSANITY_HEADER_CONTENT_LENGTH ( 4900 enum MHD_Bool value 4901 ); 4902 4903 /** 4904 * Set a function to be called once MHD is finished with the request. 4905 * @param ended_cb the function to call, 4906 * NULL to not use the callback 4907 * @param ended_cb_cls the closure for the callback 4908 * @return structure with the requested setting 4909 */ 4910 struct MHD_ResponseOptionAndValue 4911 MHD_R_OPTION_TERMINATION_CALLBACK ( 4912 MHD_RequestEndedCallback ended_cb, 4913 void *ended_cb_cls 4914 ); 4915 4916 /* End of generated code documenting how to use options */ 4917 #endif 4918 4919 /** 4920 * Create parameter for #MHD_daemon_set_options() for work mode with 4921 * no internal threads. 4922 * The application periodically calls #MHD_daemon_process_blocking(), where 4923 * MHD internally checks all sockets automatically. 4924 * This is the default mode. 4925 * @return the object of struct MHD_DaemonOptionAndValue with requested values 4926 */ 4927 #define MHD_D_OPTION_WM_EXTERNAL_PERIODIC() \ 4928 MHD_D_OPTION_WORK_MODE (MHD_WM_OPTION_EXTERNAL_PERIODIC ()) 4929 4930 /** 4931 * Create parameter for #MHD_daemon_set_options() for work mode with 4932 * an external event loop with level triggers. 4933 * Application uses #MHD_SocketRegistrationUpdateCallback, level triggered 4934 * sockets polling (like select() or poll()) and #MHD_daemon_event_update(). 4935 * @param cb_val the callback for sockets registration 4936 * @param cb_cls_val the closure for the @a cv_val callback 4937 * @return the object of struct MHD_DaemonOptionAndValue with requested values 4938 */ 4939 #define MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL(cb_val,cb_cls_val) \ 4940 MHD_D_OPTION_WORK_MODE ( \ 4941 MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL ((cb_val),(cb_cls_val))) 4942 4943 /** 4944 * Create parameter for #MHD_daemon_set_options() for work mode with 4945 * an external event loop with edge triggers. 4946 * Application uses #MHD_SocketRegistrationUpdateCallback, edge triggered 4947 * sockets polling (like epoll with EPOLLET) and #MHD_daemon_event_update(). 4948 * @param cb_val the callback for sockets registration 4949 * @param cb_cls_val the closure for the @a cv_val callback 4950 * @return the object of struct MHD_DaemonOptionAndValue with requested values 4951 */ 4952 #define MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_EDGE(cb_val,cb_cls_val) \ 4953 MHD_D_OPTION_WORK_MODE ( \ 4954 MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE ((cb_val),(cb_cls_val))) 4955 4956 /** 4957 * Create parameter for #MHD_daemon_set_options() for work mode with 4958 * no internal threads and aggregate watch FD. 4959 * Application uses #MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD to get single FD 4960 * that gets triggered by any MHD event. 4961 * This FD can be watched as an aggregate indicator for all MHD events. 4962 * This mode is available only on selected platforms (currently 4963 * GNU/Linux only), see #MHD_LIB_INFO_FIXED_HAS_AGGREGATE_FD. 4964 * When the FD is triggered, #MHD_daemon_process_nonblocking() should 4965 * be called. 4966 * @return the object of struct MHD_DaemonOptionAndValue with requested values 4967 */ 4968 #define MHD_D_OPTION_WM_EXTERNAL_SINGLE_FD_WATCH() \ 4969 MHD_D_OPTION_WORK_MODE (MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH ()) 4970 4971 /** 4972 * Create parameter for #MHD_daemon_set_options() for work mode with 4973 * one or more worker threads. 4974 * If number of threads is one, then daemon starts with single worker thread 4975 * that handles all connections. 4976 * If number of threads is larger than one, then that number of worker threads, 4977 * and handling of connection is distributed among the workers. 4978 * @param num_workers the number of worker threads, zero is treated as one 4979 * @return the object of struct MHD_DaemonOptionAndValue with requested values 4980 */ 4981 #define MHD_D_OPTION_WM_WORKER_THREADS(num_workers) \ 4982 MHD_D_OPTION_WORK_MODE (MHD_WM_OPTION_WORKER_THREADS (num_workers)) 4983 4984 /** 4985 * Create parameter for #MHD_daemon_set_options() for work mode with 4986 * one internal thread for listening and additional threads per every 4987 * connection. Use this if handling requests is CPU-intensive or blocking, 4988 * your application is thread-safe and you have plenty of memory (per 4989 * connection). 4990 * @return the object of struct MHD_DaemonOptionAndValue with requested values 4991 */ 4992 #define MHD_D_OPTION_WM_THREAD_PER_CONNECTION() \ 4993 MHD_D_OPTION_WORK_MODE (MHD_WM_OPTION_THREAD_PER_CONNECTION ()) 4994 4995 /** 4996 * Set the requested options for the daemon. 4997 * 4998 * If any option fail other options may be or may be not applied. 4999 * @param daemon the daemon to set the options 5000 * @param[in] options the pointer to the array with the options; 5001 * the array processing stops at the first ::MHD_D_O_END 5002 * option, but not later than after processing 5003 * @a options_max_num entries 5004 * @param options_max_num the maximum number of entries in the @a options, 5005 * use #MHD_OPTIONS_ARRAY_MAX_SIZE if options processing 5006 * must stop only at zero-termination option 5007 * @return ::MHD_SC_OK on success, 5008 * error code otherwise 5009 */ 5010 MHD_EXTERN_ enum MHD_StatusCode 5011 MHD_daemon_set_options ( 5012 struct MHD_Daemon *MHD_RESTRICT daemon, 5013 const struct MHD_DaemonOptionAndValue *MHD_RESTRICT options, 5014 size_t options_max_num) 5015 MHD_FN_PAR_NONNULL_ALL_; 5016 5017 5018 /** 5019 * Set the requested single option for the daemon. 5020 * 5021 * @param daemon the daemon to set the option 5022 * @param[in] option_ptr the pointer to the option 5023 * @return ::MHD_SC_OK on success, 5024 * error code otherwise 5025 */ 5026 #define MHD_daemon_set_option(daemon, option_ptr) \ 5027 MHD_daemon_set_options (daemon, option_ptr, 1) 5028 5029 5030 /* *INDENT-OFF* */ 5031 #ifdef MHD_USE_VARARG_MACROS 5032 MHD_NOWARN_VARIADIC_MACROS_ 5033 # if defined(MHD_USE_COMPOUND_LITERALS) && \ 5034 defined(MHD_USE_COMP_LIT_FUNC_PARAMS) 5035 /** 5036 * Set the requested options for the daemon. 5037 * 5038 * If any option fail other options may be or may be not applied. 5039 * 5040 * It should be used with helpers that creates required options, for example: 5041 * 5042 * MHD_DAEMON_SET_OPTIONS(d, MHD_D_OPTION_SUPPRESS_DATE_HEADER(MHD_YES), 5043 * MHD_D_OPTION_SOCK_ADDR(sa_len, sa)) 5044 * 5045 * @param daemon the daemon to set the options 5046 * @param ... the list of the options, each option must be created 5047 * by helpers MHD_D_OPTION_NameOfOption(option_value) 5048 * @return ::MHD_SC_OK on success, 5049 * error code otherwise 5050 */ 5051 # define MHD_DAEMON_SET_OPTIONS(daemon,...) \ 5052 MHD_NOWARN_COMPOUND_LITERALS_ \ 5053 MHD_NOWARN_AGGR_DYN_INIT_ \ 5054 MHD_daemon_set_options ( \ 5055 daemon, \ 5056 ((const struct MHD_DaemonOptionAndValue[]) \ 5057 {__VA_ARGS__, MHD_D_OPTION_TERMINATE ()}), \ 5058 MHD_OPTIONS_ARRAY_MAX_SIZE) \ 5059 MHD_RESTORE_WARN_AGGR_DYN_INIT_ \ 5060 MHD_RESTORE_WARN_COMPOUND_LITERALS_ 5061 # elif defined(MHD_USE_CPP_INIT_LIST) 5062 MHD_C_DECLARATIONS_FINISH_HERE_ 5063 # include <vector> 5064 MHD_C_DECLARATIONS_START_HERE_ 5065 /** 5066 * Set the requested options for the daemon. 5067 * 5068 * If any option fail other options may be or may be not applied. 5069 * 5070 * It should be used with helpers that creates required options, for example: 5071 * 5072 * MHD_DAEMON_SET_OPTIONS(d, MHD_D_OPTION_SUPPRESS_DATE_HEADER(MHD_YES), 5073 * MHD_D_OPTION_SOCK_ADDR(sa_len, sa)) 5074 * 5075 * @param daemon the daemon to set the options 5076 * @param ... the list of the options, each option must be created 5077 * by helpers MHD_D_OPTION_NameOfOption(option_value) 5078 * @return ::MHD_SC_OK on success, 5079 * error code otherwise 5080 */ 5081 # define MHD_DAEMON_SET_OPTIONS(daemon,...) \ 5082 MHD_NOWARN_CPP_INIT_LIST_ \ 5083 MHD_daemon_set_options ( \ 5084 daemon, \ 5085 (std::vector<struct MHD_DaemonOptionAndValue> \ 5086 {__VA_ARGS__,MHD_D_OPTION_TERMINATE ()}).data (), \ 5087 MHD_OPTIONS_ARRAY_MAX_SIZE) \ 5088 MHD_RESTORE_WARN_CPP_INIT_LIST_ 5089 # endif 5090 MHD_RESTORE_WARN_VARIADIC_MACROS_ 5091 #endif /* MHD_USE_VARARG_MACROS && MHD_USE_COMP_LIT_FUNC_PARAMS */ 5092 /* *INDENT-ON* */ 5093 5094 5095 /* ******************* Event loop ************************ */ 5096 5097 5098 /** 5099 * Run websever operation with possible blocking. 5100 * 5101 * Supported only in #MHD_WM_EXTERNAL_PERIODIC and 5102 * #MHD_WM_EXTERNAL_SINGLE_FD_WATCH modes. 5103 * 5104 * This function does the following: waits for any network event not more than 5105 * specified number of microseconds, processes all incoming and outgoing data, 5106 * processes new connections, processes any timed-out connection, and does 5107 * other things required to run webserver. 5108 * Once all connections are processed, function returns. 5109 * 5110 * This function is useful for quick and simple (lazy) webserver implementation 5111 * if application needs to run a single thread only and does not have any other 5112 * network activity. 5113 * 5114 * In #MHD_WM_EXTERNAL_PERIODIC mode if @a microsec parameter is not zero 5115 * this function determines the internal daemon timeout and use returned value 5116 * as maximum wait time if it less than value of @a microsec parameter. 5117 * 5118 * @param daemon the daemon to run 5119 * @param microsec the maximum time in microseconds to wait for network and 5120 * other events. Note: there is no guarantee that function 5121 * blocks for the specified amount of time. The real processing 5122 * time can be shorter (if some data or connection timeout 5123 * comes earlier) or longer (if data processing requires more 5124 * time, especially in user callbacks). 5125 * If set to '0' then function does not block and processes 5126 * only already available data (if any). Zero value is 5127 * recommended when used in #MHD_WM_EXTERNAL_SINGLE_FD_WATCH 5128 * and the watched FD has been triggered. 5129 * If set to #MHD_WAIT_INDEFINITELY then function waits 5130 * for events indefinitely (blocks until next network activity 5131 * or connection timeout). 5132 * Always used as zero value in 5133 * #MHD_WM_EXTERNAL_SINGLE_FD_WATCH mode. 5134 * @return #MHD_SC_OK on success, otherwise 5135 * an error code 5136 * @ingroup event 5137 */ 5138 MHD_EXTERN_ enum MHD_StatusCode 5139 MHD_daemon_process_blocking (struct MHD_Daemon *daemon, 5140 uint_fast64_t microsec) 5141 MHD_FN_PAR_NONNULL_ (1); 5142 5143 /** 5144 * Run webserver operations (without blocking unless in client 5145 * callbacks). 5146 * 5147 * Supported only in #MHD_WM_EXTERNAL_SINGLE_FD_WATCH mode. 5148 * 5149 * This function does the following: processes all incoming and outgoing data, 5150 * processes new connections, processes any timed-out connection, and does 5151 * other things required to run webserver. 5152 * Once all connections are processed, function returns. 5153 * 5154 * @param daemon the daemon to run 5155 * @return #MHD_SC_OK on success, otherwise 5156 * an error code 5157 * @ingroup event 5158 */ 5159 #define MHD_daemon_process_nonblocking(daemon) \ 5160 MHD_daemon_process_blocking (daemon, 0) 5161 5162 5163 /** 5164 * Add another client connection to the set of connections managed by 5165 * MHD. This API is usually not needed (since MHD will accept inbound 5166 * connections on the server socket). Use this API in special cases, 5167 * for example if your HTTP server is behind NAT and needs to connect 5168 * out to the HTTP client, or if you are building a proxy. 5169 * 5170 * The given client socket will be managed (and closed!) by MHD after 5171 * this call and must no longer be used directly by the application 5172 * afterwards. 5173 * The client socket will be closed by MHD even if error returned. 5174 * 5175 * @param daemon daemon that manages the connection 5176 * @param new_socket socket to manage (MHD will expect to receive an 5177 HTTP request from this socket next). 5178 * @param addr_size number of bytes in @a addr 5179 * @param addr IP address of the client, ignored when @a addrlen is zero 5180 * @param connection_cntx meta data the application wants to 5181 * associate with the new connection object 5182 * @return #MHD_SC_OK on success, 5183 * error on failure (the @a new_socket is closed) 5184 * @ingroup specialized 5185 */ 5186 MHD_EXTERN_ enum MHD_StatusCode 5187 MHD_daemon_add_connection (struct MHD_Daemon *MHD_RESTRICT daemon, 5188 MHD_Socket new_socket, 5189 size_t addr_size, 5190 const struct sockaddr *MHD_RESTRICT addr, 5191 void *connection_cntx) 5192 MHD_FN_PAR_NONNULL_ (1) 5193 MHD_FN_PAR_IN_ (4); 5194 5195 5196 /* ********************* connection options ************** */ 5197 5198 enum MHD_FIXED_ENUM_APP_SET_ MHD_ConnectionOption 5199 { 5200 /** 5201 * Not a real option. 5202 * Should not be used directly. 5203 * This value indicates the end of the list of the options. 5204 */ 5205 MHD_C_O_END = 0 5206 , 5207 /** 5208 * Set custom timeout for the given connection. 5209 * Specified as the number of seconds. Use zero for no timeout. 5210 * Setting this option resets connection timeout timer. 5211 */ 5212 MHD_C_O_TIMEOUT = 1 5213 , 5214 5215 5216 /* * Sentinel * */ 5217 /** 5218 * The sentinel value. 5219 * This value enforces specific underlying integer type for the enum. 5220 * Do not use. 5221 */ 5222 MHD_C_O_SENTINEL = 65535 5223 }; 5224 5225 5226 /** 5227 * Dummy-struct for space allocation. 5228 * Do not use in application logic. 5229 */ 5230 struct MHD_ReservedStruct 5231 { 5232 uint_fast64_t reserved1; 5233 void *reserved2; 5234 }; 5235 5236 5237 /** 5238 * Parameters for MHD connection options 5239 */ 5240 union MHD_ConnectionOptionValue 5241 { 5242 /** 5243 * Value for #MHD_C_O_TIMEOUT 5244 */ 5245 unsigned int v_timeout; 5246 /** 5247 * Reserved member. Do not use. 5248 */ 5249 struct MHD_ReservedStruct reserved; 5250 }; 5251 5252 /** 5253 * Combination of MHD connection option with parameters values 5254 */ 5255 struct MHD_ConnectionOptionAndValue 5256 { 5257 /** 5258 * The connection configuration option 5259 */ 5260 enum MHD_ConnectionOption opt; 5261 /** 5262 * The value for the @a opt option 5263 */ 5264 union MHD_ConnectionOptionValue val; 5265 }; 5266 5267 #if defined(MHD_USE_COMPOUND_LITERALS) && defined(MHD_USE_DESIG_NEST_INIT) 5268 /** 5269 * Set custom timeout for the given connection. 5270 * Specified as the number of seconds. Use zero for no timeout. 5271 * Setting this option resets connection timeout timer. 5272 * @param timeout the in seconds, zero for no timeout 5273 * @return the object of struct MHD_ConnectionOptionAndValue with the requested 5274 * values 5275 */ 5276 # define MHD_C_OPTION_TIMEOUT(timeout) \ 5277 MHD_NOWARN_COMPOUND_LITERALS_ \ 5278 (const struct MHD_ConnectionOptionAndValue) \ 5279 { \ 5280 .opt = (MHD_C_O_TIMEOUT), \ 5281 .val.v_timeout = (timeout) \ 5282 } \ 5283 MHD_RESTORE_WARN_COMPOUND_LITERALS_ 5284 5285 /** 5286 * Terminate the list of the options 5287 * @return the terminating object of struct MHD_ConnectionOptionAndValue 5288 */ 5289 # define MHD_C_OPTION_TERMINATE() \ 5290 MHD_NOWARN_COMPOUND_LITERALS_ \ 5291 (const struct MHD_ConnectionOptionAndValue) \ 5292 { \ 5293 .opt = (MHD_C_O_END) \ 5294 } \ 5295 MHD_RESTORE_WARN_COMPOUND_LITERALS_ 5296 5297 #else /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */ 5298 MHD_NOWARN_UNUSED_FUNC_ 5299 5300 /** 5301 * Set custom timeout for the given connection. 5302 * Specified as the number of seconds. Use zero for no timeout. 5303 * Setting this option resets connection timeout timer. 5304 * @param timeout the in seconds, zero for no timeout 5305 * @return the object of struct MHD_ConnectionOptionAndValue with the requested 5306 * values 5307 */ 5308 static MHD_INLINE struct MHD_ConnectionOptionAndValue 5309 MHD_C_OPTION_TIMEOUT (unsigned int timeout) 5310 { 5311 struct MHD_ConnectionOptionAndValue opt_val; 5312 5313 opt_val.opt = MHD_C_O_TIMEOUT; 5314 opt_val.val.v_timeout = timeout; 5315 5316 return opt_val; 5317 } 5318 5319 5320 /** 5321 * Terminate the list of the options 5322 * @return the terminating object of struct MHD_ConnectionOptionAndValue 5323 */ 5324 static MHD_INLINE struct MHD_ConnectionOptionAndValue 5325 MHD_C_OPTION_TERMINATE (void) 5326 { 5327 struct MHD_ConnectionOptionAndValue opt_val; 5328 5329 opt_val.opt = MHD_C_O_END; 5330 5331 return opt_val; 5332 } 5333 5334 5335 MHD_RESTORE_WARN_UNUSED_FUNC_ 5336 #endif /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */ 5337 5338 /** 5339 * Set the requested options for the connection. 5340 * 5341 * If any option fail other options may be or may be not applied. 5342 * @param connection the connection to set the options 5343 * @param[in] options the pointer to the array with the options; 5344 * the array processing stops at the first ::MHD_D_O_END 5345 * option, but not later than after processing 5346 * @a options_max_num entries 5347 * @param options_max_num the maximum number of entries in the @a options, 5348 * use #MHD_OPTIONS_ARRAY_MAX_SIZE if options processing 5349 * must stop only at zero-termination option 5350 * @return ::MHD_SC_OK on success, 5351 * error code otherwise 5352 */ 5353 MHD_EXTERN_ enum MHD_StatusCode 5354 MHD_connection_set_options ( 5355 struct MHD_Connection *MHD_RESTRICT connection, 5356 const struct MHD_ConnectionOptionAndValue *MHD_RESTRICT options, 5357 size_t options_max_num) 5358 MHD_FN_PAR_NONNULL_ALL_; 5359 5360 5361 /** 5362 * Set the requested single option for the connection. 5363 * 5364 * @param connection the connection to set the options 5365 * @param[in] option_ptr the pointer to the option 5366 * @return ::MHD_SC_OK on success, 5367 * error code otherwise 5368 */ 5369 #define MHD_connection_set_option(connection, option_ptr) \ 5370 MHD_connection_set_options (connection, options_ptr, 1) 5371 5372 5373 /* *INDENT-OFF* */ 5374 #ifdef MHD_USE_VARARG_MACROS 5375 MHD_NOWARN_VARIADIC_MACROS_ 5376 # if defined(MHD_USE_COMPOUND_LITERALS) && defined(MHD_USE_COMP_LIT_FUNC_PARAMS \ 5377 ) 5378 /** 5379 * Set the requested options for the connection. 5380 * 5381 * If any option fail other options may be or may be not applied. 5382 * 5383 * It should be used with helpers that creates required options, for example: 5384 * 5385 * MHD_CONNECTION_SET_OPTIONS(d, MHD_C_OPTION_TIMEOUT(30)) 5386 * 5387 * @param connection the connection to set the options 5388 * @param ... the list of the options, each option must be created 5389 * by helpers MHD_C_OPTION_NameOfOption(option_value) 5390 * @return ::MHD_SC_OK on success, 5391 * error code otherwise 5392 */ 5393 # define MHD_CONNECTION_SET_OPTIONS(connection,...) \ 5394 MHD_NOWARN_COMPOUND_LITERALS_ \ 5395 MHD_connection_set_options ( \ 5396 daemon, \ 5397 ((const struct MHD_ConnectionOptionAndValue []) \ 5398 {__VA_ARGS__, MHD_C_OPTION_TERMINATE ()}), \ 5399 MHD_OPTIONS_ARRAY_MAX_SIZE) \ 5400 MHD_RESTORE_WARN_COMPOUND_LITERALS_ 5401 # elif defined(MHD_USE_CPP_INIT_LIST) 5402 MHD_C_DECLARATIONS_FINISH_HERE_ 5403 # include <vector> 5404 MHD_C_DECLARATIONS_START_HERE_ 5405 /** 5406 * Set the requested options for the connection. 5407 * 5408 * If any option fail other options may be or may be not applied. 5409 * 5410 * It should be used with helpers that creates required options, for example: 5411 * 5412 * MHD_CONNECTION_SET_OPTIONS(d, MHD_C_OPTION_TIMEOUT(30)) 5413 * 5414 * @param connection the connection to set the options 5415 * @param ... the list of the options, each option must be created 5416 * by helpers MHD_C_OPTION_NameOfOption(option_value) 5417 * @return ::MHD_SC_OK on success, 5418 * error code otherwise 5419 */ 5420 # define MHD_CONNECTION_SET_OPTIONS(daemon,...) \ 5421 MHD_NOWARN_CPP_INIT_LIST_ \ 5422 MHD_daemon_set_options ( \ 5423 daemon, \ 5424 (std::vector<struct MHD_ConnectionOptionAndValue> \ 5425 {__VA_ARGS__,MHD_C_OPTION_TERMINATE ()}).data (), \ 5426 MHD_OPTIONS_ARRAY_MAX_SIZE) \ 5427 MHD_RESTORE_WARN_CPP_INIT_LIST_ 5428 # endif 5429 MHD_RESTORE_WARN_VARIADIC_MACROS_ 5430 #endif /* MHD_USE_VARARG_MACROS && MHD_USE_COMP_LIT_FUNC_PARAMS */ 5431 /* *INDENT-ON* */ 5432 5433 5434 /* **************** Request handling functions ***************** */ 5435 5436 5437 /** 5438 * The `enum MHD_ValueKind` specifies the source of 5439 * the name-value pairs in the HTTP protocol. 5440 */ 5441 enum MHD_FLAGS_ENUM_ MHD_ValueKind 5442 { 5443 5444 /** 5445 * HTTP header. 5446 * The 'value' for this kind is mandatory. 5447 */ 5448 MHD_VK_HEADER = (1u << 0) 5449 , 5450 /** 5451 * Cookies. Note that the original HTTP header containing 5452 * the cookie(s) will still be available and intact. 5453 * The 'value' for this kind is optional. 5454 */ 5455 MHD_VK_COOKIE = (1u << 1) 5456 , 5457 /** 5458 * URI query parameter. 5459 * The 'value' for this kind is optional. 5460 */ 5461 MHD_VK_URI_QUERY_PARAM = (1u << 2) 5462 , 5463 /** 5464 * POST data. 5465 * This is available only if #MHD_action_parse_post() action is used, 5466 * a content encoding is supported by MHD, and only if the posted content 5467 * fits within the specified memory buffers. 5468 * 5469 * @warning The encoding "multipart/form-data" has more fields than just 5470 * "name" and "value". See #MHD_request_get_post_data_cb() and 5471 * #MHD_request_get_post_data_list(). In particular it could be important 5472 * to check used "Transfer-Encoding". While it is deprecated and not used 5473 * by modern clients, formally it can be used. 5474 */ 5475 MHD_VK_POSTDATA = (1u << 3) 5476 , 5477 /** 5478 * HTTP trailer (only for HTTP 1.1 chunked encodings, "footer"). 5479 * The 'value' for this kind is mandatory. 5480 */ 5481 MHD_VK_TRAILER = (1u << 4) 5482 , 5483 /** 5484 * Header and trailer values. 5485 */ 5486 MHD_VK_HEADER_TRAILER = MHD_VK_HEADER | MHD_VK_TRAILER 5487 , 5488 /** 5489 * Values from URI query parameters or post data. 5490 */ 5491 MHD_VK_URI_QUERY_POST = MHD_VK_POSTDATA | MHD_VK_URI_QUERY_PARAM 5492 }; 5493 5494 /** 5495 * Name with value pair 5496 */ 5497 struct MHD_NameAndValue 5498 { 5499 /** 5500 * The name (key) of the field. 5501 * The pointer to the C string must never be NULL. 5502 * Some types (kinds) allow empty strings. 5503 */ 5504 struct MHD_String name; 5505 /** 5506 * The value of the field. 5507 * Some types (kinds) allow absence of the value. The absence is indicated 5508 * by NULL pointer to the C string. 5509 */ 5510 struct MHD_StringNullable value; 5511 }; 5512 5513 /** 5514 * Name, value and kind (type) of data 5515 */ 5516 struct MHD_NameValueKind 5517 { 5518 /** 5519 * The name and the value of the field 5520 */ 5521 struct MHD_NameAndValue nv; 5522 /** 5523 * The kind (type) of the field 5524 */ 5525 enum MHD_ValueKind kind; 5526 }; 5527 5528 /** 5529 * Iterator over name-value pairs. This iterator can be used to 5530 * iterate over all of the cookies, headers, footers or POST-data fields 5531 * of a request. 5532 * 5533 * The @a nv pointer is valid only until return from this function. 5534 * 5535 * The strings in @a nv are valid until any MHD_Action or MHD_UploadAction 5536 * is provided. 5537 * If the data is needed beyond this point, it should be copied. 5538 * 5539 * @param cls closure 5540 * @param nv the name and the value of the element, the pointer is valid only until 5541 * return from this function 5542 * @param kind the type (kind) of the element 5543 * @return #MHD_YES to continue iterating, 5544 * #MHD_NO to abort the iteration 5545 * @ingroup request 5546 */ 5547 typedef enum MHD_Bool 5548 (MHD_FN_PAR_NONNULL_ (3) 5549 *MHD_NameValueIterator)(void *cls, 5550 enum MHD_ValueKind kind, 5551 const struct MHD_NameAndValue *nv); 5552 5553 5554 /** 5555 * Get all of the headers (or other kind of request data) via callback. 5556 * 5557 * @param[in,out] request request to get values from 5558 * @param kind types of values to iterate over, can be a bitmask 5559 * @param iterator callback to call on each header; 5560 * maybe NULL (then just count headers) 5561 * @param iterator_cls extra argument to @a iterator 5562 * @return number of entries iterated over 5563 * @ingroup request 5564 */ 5565 MHD_EXTERN_ size_t 5566 MHD_request_get_values_cb (struct MHD_Request *request, 5567 enum MHD_ValueKind kind, 5568 MHD_NameValueIterator iterator, 5569 void *iterator_cls) 5570 MHD_FN_PAR_NONNULL_ (1); 5571 5572 5573 /** 5574 * Get all of the headers (or other kind of request data) from the request. 5575 * 5576 * The pointers to the strings in @a elements are valid until any 5577 * MHD_Action or MHD_UploadAction is provided. If the data is needed beyond 5578 * this point, it should be copied. 5579 * 5580 * @param[in] request request to get values from 5581 * @param kind the types of values to get, can be a bitmask 5582 * @param num_elements the number of elements in @a elements array 5583 * @param[out] elements the array of @a num_elements strings to be filled with 5584 * the key-value pairs; if @a request has more elements 5585 * than @a num_elements than any @a num_elements are 5586 * stored 5587 * @return the number of elements stored in @a elements, the 5588 * number cannot be larger then @a num_elements, 5589 * zero if there is no such values or any error occurs 5590 */ 5591 MHD_EXTERN_ size_t 5592 MHD_request_get_values_list ( 5593 struct MHD_Request *request, 5594 enum MHD_ValueKind kind, 5595 size_t num_elements, 5596 struct MHD_NameValueKind elements[MHD_FN_PAR_DYN_ARR_SIZE_ (num_elements)]) 5597 MHD_FN_PAR_NONNULL_ (1) 5598 MHD_FN_PAR_NONNULL_ (4) MHD_FN_PAR_OUT_SIZE_ (4,3); 5599 5600 5601 /** 5602 * Get a particular header (or other kind of request data) value. 5603 * If multiple values match the kind, return any one of them. 5604 * 5605 * The data in the @a value_out is valid until any MHD_Action or 5606 * MHD_UploadAction is provided. If the data is needed beyond this point, 5607 * it should be copied. 5608 * 5609 * @param request request to get values from 5610 * @param kind what kind of value are we looking for 5611 * @param key the name of the value looking for (used for case-insensetive 5612 * match), empty to lookup 'trailing' value without a key 5613 * @param[out] value_out set to the value of the header if succeed, 5614 * the @a cstr pointer could be NULL even if succeed 5615 * if the requested item found, but has no value 5616 * @return #MHD_YES if succeed, the @a value_out is set; 5617 * #MHD_NO if no such item was found, the @a value_out string pointer 5618 * set to NULL 5619 * @ingroup request 5620 */ 5621 MHD_EXTERN_ enum MHD_Bool 5622 MHD_request_get_value (struct MHD_Request *MHD_RESTRICT request, 5623 enum MHD_ValueKind kind, 5624 const char *MHD_RESTRICT key, 5625 struct MHD_StringNullable *MHD_RESTRICT value_out) 5626 MHD_FN_PAR_NONNULL_ (1) 5627 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_CSTR_ (3) 5628 MHD_FN_PAR_OUT_ (4); 5629 5630 5631 /** 5632 * @brief Status codes defined for HTTP responses. 5633 * 5634 * @defgroup httpcode HTTP response codes 5635 * @{ 5636 */ 5637 /* Registry export date: 2023-09-29 */ 5638 /* See http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml */ 5639 enum MHD_FIXED_ENUM_APP_SET_ MHD_HTTP_StatusCode 5640 { 5641 /* 100 "Continue". RFC9110, Section 15.2.1. */ 5642 MHD_HTTP_STATUS_CONTINUE = 100 5643 , 5644 /* 101 "Switching Protocols". RFC9110, Section 15.2.2. */ 5645 MHD_HTTP_STATUS_SWITCHING_PROTOCOLS = 101 5646 , 5647 /* 102 "Processing". RFC2518. */ 5648 MHD_HTTP_STATUS_PROCESSING = 102 5649 , 5650 /* 103 "Early Hints". RFC8297. */ 5651 MHD_HTTP_STATUS_EARLY_HINTS = 103 5652 , 5653 5654 /* 200 "OK". RFC9110, Section 15.3.1. */ 5655 MHD_HTTP_STATUS_OK = 200 5656 , 5657 /* 201 "Created". RFC9110, Section 15.3.2. */ 5658 MHD_HTTP_STATUS_CREATED = 201 5659 , 5660 /* 202 "Accepted". RFC9110, Section 15.3.3. */ 5661 MHD_HTTP_STATUS_ACCEPTED = 202 5662 , 5663 /* 203 "Non-Authoritative Information". RFC9110, Section 15.3.4. */ 5664 MHD_HTTP_STATUS_NON_AUTHORITATIVE_INFORMATION = 203 5665 , 5666 /* 204 "No Content". RFC9110, Section 15.3.5. */ 5667 MHD_HTTP_STATUS_NO_CONTENT = 204 5668 , 5669 /* 205 "Reset Content". RFC9110, Section 15.3.6. */ 5670 MHD_HTTP_STATUS_RESET_CONTENT = 205 5671 , 5672 /* 206 "Partial Content". RFC9110, Section 15.3.7. */ 5673 MHD_HTTP_STATUS_PARTIAL_CONTENT = 206 5674 , 5675 /* 207 "Multi-Status". RFC4918. */ 5676 MHD_HTTP_STATUS_MULTI_STATUS = 207 5677 , 5678 /* 208 "Already Reported". RFC5842. */ 5679 MHD_HTTP_STATUS_ALREADY_REPORTED = 208 5680 , 5681 5682 /* 226 "IM Used". RFC3229. */ 5683 MHD_HTTP_STATUS_IM_USED = 226 5684 , 5685 5686 /* 300 "Multiple Choices". RFC9110, Section 15.4.1. */ 5687 MHD_HTTP_STATUS_MULTIPLE_CHOICES = 300 5688 , 5689 /* 301 "Moved Permanently". RFC9110, Section 15.4.2. */ 5690 MHD_HTTP_STATUS_MOVED_PERMANENTLY = 301 5691 , 5692 /* 302 "Found". RFC9110, Section 15.4.3. */ 5693 MHD_HTTP_STATUS_FOUND = 302 5694 , 5695 /* 303 "See Other". RFC9110, Section 15.4.4. */ 5696 MHD_HTTP_STATUS_SEE_OTHER = 303 5697 , 5698 /* 304 "Not Modified". RFC9110, Section 15.4.5. */ 5699 MHD_HTTP_STATUS_NOT_MODIFIED = 304 5700 , 5701 /* 305 "Use Proxy". RFC9110, Section 15.4.6. */ 5702 MHD_HTTP_STATUS_USE_PROXY = 305 5703 , 5704 /* 306 "Switch Proxy". Not used! RFC9110, Section 15.4.7. */ 5705 MHD_HTTP_STATUS_SWITCH_PROXY = 306 5706 , 5707 /* 307 "Temporary Redirect". RFC9110, Section 15.4.8. */ 5708 MHD_HTTP_STATUS_TEMPORARY_REDIRECT = 307 5709 , 5710 /* 308 "Permanent Redirect". RFC9110, Section 15.4.9. */ 5711 MHD_HTTP_STATUS_PERMANENT_REDIRECT = 308 5712 , 5713 5714 /* 400 "Bad Request". RFC9110, Section 15.5.1. */ 5715 MHD_HTTP_STATUS_BAD_REQUEST = 400 5716 , 5717 /* 401 "Unauthorized". RFC9110, Section 15.5.2. */ 5718 MHD_HTTP_STATUS_UNAUTHORIZED = 401 5719 , 5720 /* 402 "Payment Required". RFC9110, Section 15.5.3. */ 5721 MHD_HTTP_STATUS_PAYMENT_REQUIRED = 402 5722 , 5723 /* 403 "Forbidden". RFC9110, Section 15.5.4. */ 5724 MHD_HTTP_STATUS_FORBIDDEN = 403 5725 , 5726 /* 404 "Not Found". RFC9110, Section 15.5.5. */ 5727 MHD_HTTP_STATUS_NOT_FOUND = 404 5728 , 5729 /* 405 "Method Not Allowed". RFC9110, Section 15.5.6. */ 5730 MHD_HTTP_STATUS_METHOD_NOT_ALLOWED = 405 5731 , 5732 /* 406 "Not Acceptable". RFC9110, Section 15.5.7. */ 5733 MHD_HTTP_STATUS_NOT_ACCEPTABLE = 406 5734 , 5735 /* 407 "Proxy Authentication Required". RFC9110, Section 15.5.8. */ 5736 MHD_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED = 407 5737 , 5738 /* 408 "Request Timeout". RFC9110, Section 15.5.9. */ 5739 MHD_HTTP_STATUS_REQUEST_TIMEOUT = 408 5740 , 5741 /* 409 "Conflict". RFC9110, Section 15.5.10. */ 5742 MHD_HTTP_STATUS_CONFLICT = 409 5743 , 5744 /* 410 "Gone". RFC9110, Section 15.5.11. */ 5745 MHD_HTTP_STATUS_GONE = 410 5746 , 5747 /* 411 "Length Required". RFC9110, Section 15.5.12. */ 5748 MHD_HTTP_STATUS_LENGTH_REQUIRED = 411 5749 , 5750 /* 412 "Precondition Failed". RFC9110, Section 15.5.13. */ 5751 MHD_HTTP_STATUS_PRECONDITION_FAILED = 412 5752 , 5753 /* 413 "Content Too Large". RFC9110, Section 15.5.14. */ 5754 MHD_HTTP_STATUS_CONTENT_TOO_LARGE = 413 5755 , 5756 /* 414 "URI Too Long". RFC9110, Section 15.5.15. */ 5757 MHD_HTTP_STATUS_URI_TOO_LONG = 414 5758 , 5759 /* 415 "Unsupported Media Type". RFC9110, Section 15.5.16. */ 5760 MHD_HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE = 415 5761 , 5762 /* 416 "Range Not Satisfiable". RFC9110, Section 15.5.17. */ 5763 MHD_HTTP_STATUS_RANGE_NOT_SATISFIABLE = 416 5764 , 5765 /* 417 "Expectation Failed". RFC9110, Section 15.5.18. */ 5766 MHD_HTTP_STATUS_EXPECTATION_FAILED = 417 5767 , 5768 5769 5770 /* 421 "Misdirected Request". RFC9110, Section 15.5.20. */ 5771 MHD_HTTP_STATUS_MISDIRECTED_REQUEST = 421 5772 , 5773 /* 422 "Unprocessable Content". RFC9110, Section 15.5.21. */ 5774 MHD_HTTP_STATUS_UNPROCESSABLE_CONTENT = 422 5775 , 5776 /* 423 "Locked". RFC4918. */ 5777 MHD_HTTP_STATUS_LOCKED = 423 5778 , 5779 /* 424 "Failed Dependency". RFC4918. */ 5780 MHD_HTTP_STATUS_FAILED_DEPENDENCY = 424 5781 , 5782 /* 425 "Too Early". RFC8470. */ 5783 MHD_HTTP_STATUS_TOO_EARLY = 425 5784 , 5785 /* 426 "Upgrade Required". RFC9110, Section 15.5.22. */ 5786 MHD_HTTP_STATUS_UPGRADE_REQUIRED = 426 5787 , 5788 5789 /* 428 "Precondition Required". RFC6585. */ 5790 MHD_HTTP_STATUS_PRECONDITION_REQUIRED = 428 5791 , 5792 /* 429 "Too Many Requests". RFC6585. */ 5793 MHD_HTTP_STATUS_TOO_MANY_REQUESTS = 429 5794 , 5795 5796 /* 431 "Request Header Fields Too Large". RFC6585. */ 5797 MHD_HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE = 431 5798 , 5799 5800 /* 451 "Unavailable For Legal Reasons". RFC7725. */ 5801 MHD_HTTP_STATUS_UNAVAILABLE_FOR_LEGAL_REASONS = 451 5802 , 5803 5804 /* 500 "Internal Server Error". RFC9110, Section 15.6.1. */ 5805 MHD_HTTP_STATUS_INTERNAL_SERVER_ERROR = 500 5806 , 5807 /* 501 "Not Implemented". RFC9110, Section 15.6.2. */ 5808 MHD_HTTP_STATUS_NOT_IMPLEMENTED = 501 5809 , 5810 /* 502 "Bad Gateway". RFC9110, Section 15.6.3. */ 5811 MHD_HTTP_STATUS_BAD_GATEWAY = 502 5812 , 5813 /* 503 "Service Unavailable". RFC9110, Section 15.6.4. */ 5814 MHD_HTTP_STATUS_SERVICE_UNAVAILABLE = 503 5815 , 5816 /* 504 "Gateway Timeout". RFC9110, Section 15.6.5. */ 5817 MHD_HTTP_STATUS_GATEWAY_TIMEOUT = 504 5818 , 5819 /* 505 "HTTP Version Not Supported". RFC9110, Section 15.6.6. */ 5820 MHD_HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED = 505 5821 , 5822 /* 506 "Variant Also Negotiates". RFC2295. */ 5823 MHD_HTTP_STATUS_VARIANT_ALSO_NEGOTIATES = 506 5824 , 5825 /* 507 "Insufficient Storage". RFC4918. */ 5826 MHD_HTTP_STATUS_INSUFFICIENT_STORAGE = 507 5827 , 5828 /* 508 "Loop Detected". RFC5842. */ 5829 MHD_HTTP_STATUS_LOOP_DETECTED = 508 5830 , 5831 5832 /* 510 "Not Extended". (OBSOLETED) RFC2774; status-change-http-experiments-to-historic. */ 5833 MHD_HTTP_STATUS_NOT_EXTENDED = 510 5834 , 5835 /* 511 "Network Authentication Required". RFC6585. */ 5836 MHD_HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED = 511 5837 , 5838 5839 5840 /* Not registered non-standard codes */ 5841 /* 449 "Reply With". MS IIS extension. */ 5842 MHD_HTTP_STATUS_RETRY_WITH = 449 5843 , 5844 5845 /* 450 "Blocked by Windows Parental Controls". MS extension. */ 5846 MHD_HTTP_STATUS_BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS = 450 5847 , 5848 5849 /* 509 "Bandwidth Limit Exceeded". Apache extension. */ 5850 MHD_HTTP_STATUS_BANDWIDTH_LIMIT_EXCEEDED = 509 5851 }; 5852 5853 5854 /** 5855 * Returns the string status for a response code. 5856 * 5857 * This function works for @b HTTP status code, not for @b MHD error codes/ 5858 * @param code the HTTP code to get text representation for 5859 * @return the pointer to the text representation, 5860 * NULL if HTTP status code in not known. 5861 */ 5862 MHD_EXTERN_ const struct MHD_String * 5863 MHD_HTTP_status_code_to_string (enum MHD_HTTP_StatusCode code) 5864 MHD_FN_CONST_; 5865 5866 /** 5867 * Get the pointer to the C string for the HTTP response code, never NULL. 5868 */ 5869 #define MHD_HTTP_status_code_to_string_lazy(code) \ 5870 (MHD_HTTP_status_code_to_string ((code)) ? \ 5871 ((MHD_HTTP_status_code_to_string (code))->cstr) : ("[No status]") ) 5872 5873 5874 /** @} */ /* end of group httpcode */ 5875 5876 #ifndef MHD_HTTP_PROTOCOL_VER_DEFINED 5877 5878 /** 5879 * @brief HTTP protocol versions 5880 * @defgroup versions HTTP versions 5881 * @{ 5882 */ 5883 enum MHD_FIXED_ENUM_MHD_SET_ MHD_HTTP_ProtocolVersion 5884 { 5885 MHD_HTTP_VERSION_INVALID = 0 /**< Invalid/unrecognised HTTP version */ 5886 , 5887 MHD_HTTP_VERSION_1_0 = 10 /**< HTTP/1.0 */ 5888 , 5889 MHD_HTTP_VERSION_1_1 = 11 /**< HTTP/1.1 */ 5890 , 5891 MHD_HTTP_VERSION_1_2P = 19 /**< HTTP/1.2 - HTTP/1.9 */ 5892 , 5893 MHD_HTTP_VERSION_2 = 20 /**< HTTP/2 */ 5894 , 5895 MHD_HTTP_VERSION_3 = 30 /**< HTTP/3 */ 5896 , 5897 MHD_HTTP_VERSION_FUTURE = 255 /**< Future HTTP version */ 5898 }; 5899 5900 #define MHD_HTTP_PROTOCOL_VER_DEFINED 1 5901 #endif /* ! MHD_HTTP_PROTOCOL_VER_DEFINED */ 5902 5903 /** 5904 * Return the string representation of the requested HTTP version. 5905 * Note: this is suitable mainly for logging and similar purposes as 5906 * HTTP/2 (and later) is not used inside the HTTP protocol. 5907 * @param pv the protocol version 5908 * @return the string representation of the protocol version, 5909 * NULL for invalid values 5910 */ 5911 MHD_EXTERN_ const struct MHD_String * 5912 MHD_protocol_version_to_string (enum MHD_HTTP_ProtocolVersion pv) 5913 MHD_FN_CONST_; 5914 5915 /** 5916 * HTTP/1.0 identification string 5917 */ 5918 #define MHD_HTTP_VERSION_1_0_STR "HTTP/1.0" 5919 /** 5920 * HTTP/1.1 identification string 5921 */ 5922 #define MHD_HTTP_VERSION_1_1_STR "HTTP/1.1" 5923 /** 5924 * Identification string for clients claiming HTTP/1.2 - HTTP/1.9 5925 * Not used by the HTTP protocol, useful for logs and similar purposes. 5926 */ 5927 #define MHD_HTTP_VERSION_1_2P_STR "HTTP/1.2+" 5928 /** 5929 * HTTP/2 identification string. 5930 * Not used by the HTTP protocol (except non-TLS handshake), useful for logs and 5931 * similar purposes. 5932 */ 5933 #define MHD_HTTP_VERSION_2_STR "HTTP/2" 5934 /** 5935 * HTTP/3 identification string. 5936 * Not used by the HTTP protocol, useful for logs and similar purposes. 5937 */ 5938 #define MHD_HTTP_VERSION_3_STR "HTTP/3" 5939 5940 /** @} */ /* end of group versions */ 5941 5942 5943 /** 5944 * Resume handling of network data for suspended request. 5945 * It is safe to resume a suspended request at any time. 5946 * Calling this function on a request that was not previously suspended will 5947 * result in undefined behaviour. 5948 * 5949 * @param[in,out] request the request to resume 5950 */ 5951 MHD_EXTERN_ void 5952 MHD_request_resume (struct MHD_Request *request) 5953 MHD_FN_PAR_NONNULL_ALL_; 5954 5955 5956 /* ************** Action and Response manipulation functions **************** */ 5957 5958 /** 5959 * @defgroup response Response objects control 5960 */ 5961 5962 5963 /** 5964 * Name with value pair as C strings 5965 */ 5966 struct MHD_NameValueCStr 5967 { 5968 /** 5969 * The name (key) of the field. 5970 * Must never be NULL. 5971 * Some types (kinds) allow empty strings. 5972 */ 5973 const char *name; 5974 /** 5975 * The value of the field. 5976 * Some types (kinds) allow absence of the value. The absence is indicated 5977 * by NULL pointer. 5978 */ 5979 const char *value; 5980 }; 5981 5982 /** 5983 * Data transmitted in response to an HTTP request. 5984 * Usually the final action taken in response to 5985 * receiving a request. 5986 */ 5987 struct MHD_Response; 5988 5989 5990 /** 5991 * Suspend handling of network data for a given request. This can 5992 * be used to dequeue a request from MHD's event loop for a while. 5993 * 5994 * Suspended requests continue to count against the total number of 5995 * requests allowed (per daemon, as well as per IP, if such limits 5996 * are set). Suspended requests will NOT time out; timeouts will 5997 * restart when the request handling is resumed. While a 5998 * request is suspended, MHD may not detect disconnects by the 5999 * client. 6000 * 6001 * At most one action can be created for any request. 6002 * 6003 * @param[in,out] request the request for which the action is generated 6004 * @return action to cause a request to be suspended, 6005 * NULL if any action has been already created for the @a request 6006 * @ingroup action 6007 */ 6008 MHD_EXTERN_ const struct MHD_Action * 6009 MHD_action_suspend (struct MHD_Request *request) 6010 MHD_FN_PAR_NONNULL_ALL_; 6011 6012 6013 /** 6014 * Converts a @a response to an action. If #MHD_R_O_REUSABLE 6015 * is not set, the reference to the @a response is consumed 6016 * by the conversion. If #MHD_R_O_REUSABLE is #MHD_YES, 6017 * then the @a response can be used again to create actions in 6018 * the future. 6019 * However, the @a response is frozen by this step and 6020 * must no longer be modified (i.e. by setting headers). 6021 * 6022 * At most one action can be created for any request. 6023 * 6024 * @param request the request to create the action for 6025 * @param[in] response the response to convert, 6026 * if NULL then this function is equivalent to 6027 * #MHD_action_abort_connection() call 6028 * @return pointer to the action, the action must be consumed 6029 * otherwise response object may leak; 6030 * NULL if failed (no memory) or if any action has been already 6031 * created for the @a request; 6032 * when failed the response object is consumed and need not 6033 * to be "destroyed" 6034 * @ingroup action 6035 */ 6036 MHD_EXTERN_ const struct MHD_Action * 6037 MHD_action_from_response (struct MHD_Request *MHD_RESTRICT request, 6038 struct MHD_Response *MHD_RESTRICT response) 6039 MHD_FN_PAR_NONNULL_ (1); 6040 6041 6042 /** 6043 * Action telling MHD to close the connection hard 6044 * (kind-of breaking HTTP specification). 6045 * 6046 * @param req the request to make an action 6047 * @return action operation, always NULL 6048 * @ingroup action 6049 */ 6050 #define MHD_action_abort_request(req) \ 6051 MHD_STATIC_CAST_ (const struct MHD_Action *, NULL) 6052 6053 6054 /** 6055 * Set the requested options for the response. 6056 * 6057 * If any option fail other options may be or may be not applied. 6058 * @param response the response to set the options 6059 * @param[in] options the pointer to the array with the options; 6060 * the array processing stops at the first ::MHD_D_O_END 6061 * option, but not later than after processing 6062 * @a options_max_num entries 6063 * @param options_max_num the maximum number of entries in the @a options, 6064 * use #MHD_OPTIONS_ARRAY_MAX_SIZE if options processing 6065 * must stop only at zero-termination option 6066 * @return ::MHD_SC_OK on success, 6067 * error code otherwise 6068 */ 6069 MHD_EXTERN_ enum MHD_StatusCode 6070 MHD_response_set_options ( 6071 struct MHD_Response *MHD_RESTRICT response, 6072 const struct MHD_ResponseOptionAndValue *MHD_RESTRICT options, 6073 size_t options_max_num) 6074 MHD_FN_PAR_NONNULL_ALL_; 6075 6076 6077 /** 6078 * Set the requested single option for the response. 6079 * 6080 * @param response the response to set the option 6081 * @param[in] option_ptr the pointer to the option 6082 * @return ::MHD_SC_OK on success, 6083 * error code otherwise 6084 * @ingroup response 6085 */ 6086 #define MHD_response_set_option(response,option_ptr) \ 6087 MHD_response_set_options (response,option_ptr,1) 6088 6089 6090 /* *INDENT-OFF* */ 6091 #ifdef MHD_USE_VARARG_MACROS 6092 MHD_NOWARN_VARIADIC_MACROS_ 6093 # if defined(MHD_USE_COMPOUND_LITERALS) && \ 6094 defined(MHD_USE_COMP_LIT_FUNC_PARAMS) 6095 /** 6096 * Set the requested options for the response. 6097 * 6098 * If any option fail other options may be or may be not applied. 6099 * 6100 * It should be used with helpers that creates required options, for example: 6101 * 6102 * MHD_RESPONSE_SET_OPTIONS(r, MHD_R_OPTION_REUSABLE(MHD_YES), 6103 * MHD_R_OPTION_TERMINATION_CALLBACK(func, cls)) 6104 * 6105 * @param response the response to set the option 6106 * @param ... the list of the options, each option must be created 6107 * by helpers MHD_RESPONSE_OPTION_NameOfOption(option_value) 6108 * @return ::MHD_SC_OK on success, 6109 * error code otherwise 6110 */ 6111 # define MHD_RESPONSE_SET_OPTIONS(response,...) \ 6112 MHD_NOWARN_COMPOUND_LITERALS_ \ 6113 MHD_response_set_options ( \ 6114 response, \ 6115 ((const struct MHD_ResponseOptionAndValue[]) \ 6116 {__VA_ARGS__, MHD_R_OPTION_TERMINATE ()}), \ 6117 MHD_OPTIONS_ARRAY_MAX_SIZE) \ 6118 MHD_RESTORE_WARN_COMPOUND_LITERALS_ 6119 # elif defined(MHD_USE_CPP_INIT_LIST) 6120 MHD_C_DECLARATIONS_FINISH_HERE_ 6121 # include <vector> 6122 MHD_C_DECLARATIONS_START_HERE_ 6123 /** 6124 * Set the requested options for the response. 6125 * 6126 * If any option fail other options may be or may be not applied. 6127 * 6128 * It should be used with helpers that creates required options, for example: 6129 * 6130 * MHD_RESPONSE_SET_OPTIONS(r, MHD_R_OPTION_REUSABLE(MHD_YES), 6131 * MHD_R_OPTION_TERMINATION_CALLBACK(func, cls)) 6132 * 6133 * @param response the response to set the option 6134 * @param ... the list of the options, each option must be created 6135 * by helpers MHD_RESPONSE_OPTION_NameOfOption(option_value) 6136 * @return ::MHD_SC_OK on success, 6137 * error code otherwise 6138 */ 6139 # define MHD_RESPONSE_SET_OPTIONS(response,...) \ 6140 MHD_NOWARN_CPP_INIT_LIST_ \ 6141 MHD_response_set_options ( \ 6142 response, \ 6143 (std::vector<struct MHD_ResponseOptionAndValue> \ 6144 {__VA_ARGS__,MHD_R_OPTION_TERMINATE ()}).data (), \ 6145 MHD_OPTIONS_ARRAY_MAX_SIZE) \ 6146 MHD_RESTORE_WARN_CPP_INIT_LIST_ 6147 # endif 6148 MHD_RESTORE_WARN_VARIADIC_MACROS_ 6149 #endif /* MHD_USE_VARARG_MACROS && MHD_USE_COMP_LIT_FUNC_PARAMS */ 6150 /* *INDENT-ON* */ 6151 6152 #ifndef MHD_FREECALLBACK_DEFINED 6153 6154 /** 6155 * This method is called by libmicrohttpd when response with dynamic content 6156 * is being destroyed. It should be used to free resources associated 6157 * with the dynamic content. 6158 * 6159 * @param[in] free_cls closure 6160 * @ingroup response 6161 */ 6162 typedef void 6163 (*MHD_FreeCallback) (void *free_cls); 6164 6165 #define MHD_FREECALLBACK_DEFINED 1 6166 #endif /* ! MHD_FREECALLBACK_DEFINED */ 6167 #ifndef MHD_DYNCONTENTZCIOVEC_DEFINED 6168 6169 6170 /** 6171 * Structure for iov type of the response. 6172 * Used for zero-copy response content data. 6173 */ 6174 struct MHD_DynContentZCIoVec 6175 { 6176 /** 6177 * The number of elements in @a iov 6178 */ 6179 unsigned int iov_count; 6180 /** 6181 * The pointer to the array with @a iov_count elements. 6182 */ 6183 const struct MHD_IoVec *iov; 6184 /** 6185 * The callback to free resources. 6186 * It is called once the full array of iov elements is sent. 6187 * No callback is called if NULL. 6188 */ 6189 MHD_FreeCallback iov_fcb; 6190 /** 6191 * The parameter for @a iov_fcb 6192 */ 6193 void *iov_fcb_cls; 6194 }; 6195 6196 #define MHD_DYNCONTENTZCIOVEC_DEFINED 1 6197 #endif /* ! MHD_DYNCONTENTZCIOVEC_DEFINED */ 6198 6199 /** 6200 * The action type returned by Dynamic Content Creator callback 6201 */ 6202 struct MHD_DynamicContentCreatorAction; 6203 6204 /** 6205 * The context used for Dynamic Content Creator callback 6206 */ 6207 struct MHD_DynamicContentCreatorContext; 6208 6209 6210 /** 6211 * Create "continue processing" action with optional chunk-extension. 6212 * The data is provided in the buffer and/or in the zero-copy @a iov_data. 6213 * 6214 * If data is provided both in the buffer and @a ivo_data then 6215 * data in the buffer sent first, following the iov data. 6216 * The total size of the data in the buffer and in @a iov_data must 6217 * be non-zero. 6218 * If response content size is known and total size of content provided earlier 6219 * for this request combined with the size provided by this action is larger 6220 * then known response content size, then NULL is returned. 6221 * 6222 * At most one DCC action can be created for one content callback. 6223 * 6224 * @param[in,out] ctx the pointer the context as provided to the callback 6225 * @param data_size the amount of the data placed to the provided buffer, 6226 * cannot be larger than provided buffer size, 6227 * must be non-zero if @a iov_data is NULL or has no data, 6228 * @param iov_data the optional pointer to the iov data, 6229 * must not be NULL and have non-zero size data if @a data_size 6230 * is zero, 6231 * @param chunk_ext the optional pointer to chunk extension string, 6232 * can be NULL to not use chunk extension, 6233 * ignored if chunked encoding is not used 6234 * @return the pointer to the action if succeed, 6235 * NULL (equivalent of MHD_DCC_action_abort())in case of any error 6236 */ 6237 MHD_EXTERN_ const struct MHD_DynamicContentCreatorAction * 6238 MHD_DCC_action_continue_zc ( 6239 struct MHD_DynamicContentCreatorContext *ctx, 6240 size_t data_size, 6241 const struct MHD_DynContentZCIoVec *iov_data, 6242 const char *MHD_RESTRICT chunk_ext) 6243 MHD_FN_PAR_NONNULL_ (1) 6244 MHD_FN_PAR_CSTR_ (4); 6245 6246 6247 /** 6248 * Create "continue processing" action with optional chunk-extension. 6249 * The data is provided in the buffer. 6250 * 6251 * At most one DCC action can be created for one content callback. 6252 * 6253 * @param[in,out] ctx the pointer the context as provided to the callback 6254 * @param data_size the amount of the data placed to the provided buffer (not @a iov_data), 6255 * cannot be larger than provided buffer size, 6256 * must be non-zero. 6257 * @param chunk_ext the optional pointer to chunk extension string, 6258 * can be NULL to not use chunk extension, 6259 * ignored if chunked encoding is not used 6260 * @return the pointer to the action if succeed, 6261 * NULL (equivalent of MHD_DCC_action_abort())in case of any error 6262 */ 6263 #define MHD_DCC_action_continue_ce(ctx,data_size,chunk_ext) \ 6264 MHD_DCC_action_continue_zc ((ctx), (data_size), NULL, (chunk_ext)) 6265 6266 6267 /** 6268 * Create "continue processing" action, the data is provided in the buffer. 6269 * 6270 * At most one DCC action can be created for one content callback. 6271 * 6272 * @param[in,out] ctx the pointer the context as provided to the callback 6273 * @param data_size the amount of the data placed to the provided buffer; 6274 * cannot be larger than provided buffer size, 6275 * must be non-zero. 6276 * 6277 * @return the pointer to the action if succeed, 6278 * NULL (equivalent of MHD_DCC_action_abort())in case of any error 6279 */ 6280 #define MHD_DCC_action_continue(ctx,data_size) \ 6281 MHD_DCC_action_continue_ce ((ctx), (data_size), NULL) 6282 6283 6284 /** 6285 * Create "finished" action with optional footers. 6286 * If function failed for any reason, the action is automatically 6287 * set to "stop with error". 6288 * 6289 * At most one DCC action can be created for one content callback. 6290 * 6291 * @param[in,out] ctx the pointer the context as provided to the callback 6292 * @param num_footers number of elements in the @a footers array, 6293 * must be zero if @a footers is NULL 6294 * @param footers the optional pointer to the array of the footers (the strings 6295 * are copied and does not need to be valid after return from 6296 * this function), 6297 * can be NULL if @a num_footers is zero 6298 * @return the pointer to the action if succeed, 6299 * NULL (equivalent of MHD_DCC_action_abort())in case of any error 6300 */ 6301 MHD_EXTERN_ const struct MHD_DynamicContentCreatorAction * 6302 MHD_DCC_action_finish_with_footer ( 6303 struct MHD_DynamicContentCreatorContext *ctx, 6304 size_t num_footers, 6305 const struct MHD_NameValueCStr *MHD_RESTRICT footers) 6306 MHD_FN_PAR_NONNULL_ (1); 6307 6308 6309 /** 6310 * Create "finished" action. 6311 * If function failed for any reason, the action is automatically 6312 * set to "stop with error". 6313 * 6314 * At most one DCC action can be created for one content callback. 6315 * 6316 * @param[in,out] ctx the pointer the context as provided to the callback 6317 * @return the pointer to the action if succeed, 6318 * NULL (equivalent of MHD_DCC_action_abort())in case of any error 6319 */ 6320 #define MHD_DCC_action_finish(ctx) \ 6321 MHD_DCC_action_finish_with_footer ((ctx), 0, NULL) 6322 6323 6324 /** 6325 * Create "suspend" action. 6326 * If function failed for any reason, the action is automatically 6327 * set to "stop with error". 6328 * 6329 * At most one DCC action can be created for one content callback. 6330 * 6331 * @param[in,out] ctx the pointer the context as provided to the callback 6332 * @return the pointer to the action if succeed, 6333 * NULL (equivalent of MHD_DCC_action_abort())in case of any error 6334 */ 6335 MHD_EXTERN_ const struct MHD_DynamicContentCreatorAction * 6336 MHD_DCC_action_suspend (struct MHD_DynamicContentCreatorContext *ctx) 6337 MHD_FN_PAR_NONNULL_ (1); 6338 6339 /** 6340 * Create "stop with error" action. 6341 * @param[in,out] ctx the pointer the context as provided to the callback 6342 * @return always NULL (the action "stop with error") 6343 */ 6344 #define MHD_DCC_action_abort(ctx) \ 6345 MHD_STATIC_CAST_ (const struct MHD_DynamicContentCreatorAction *, NULL) 6346 6347 /** 6348 * Callback used by libmicrohttpd in order to obtain content. The 6349 * callback is to copy at most @a max bytes of content into @a buf or 6350 * provide zero-copy data for #MHD_DCC_action_continue_zc(). 6351 * 6352 * @param dyn_cont_cls closure argument to the callback 6353 * @param ctx the context to produce the action to return, 6354 * the pointer is only valid until the callback returns 6355 * @param pos position in the datastream to access; 6356 * note that if a `struct MHD_Response` object is re-used, 6357 * it is possible for the same content reader to 6358 * be queried multiple times for the same data; 6359 * however, if a `struct MHD_Response` is not re-used, 6360 * libmicrohttpd guarantees that "pos" will be 6361 * the sum of all data sizes provided by this callback 6362 * @param[out] buf where to copy the data 6363 * @param max maximum number of bytes to copy to @a buf (size of @a buf), 6364 if the size of the content of the response is known then size 6365 of the buffer is never larger than amount of the content left 6366 * @return action to use, 6367 * NULL in case of any error (the response will be aborted) 6368 */ 6369 typedef const struct MHD_DynamicContentCreatorAction * 6370 (MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_NONNULL_ (4) 6371 *MHD_DynamicContentCreator)(void *dyn_cont_cls, 6372 struct MHD_DynamicContentCreatorContext *ctx, 6373 uint_fast64_t pos, 6374 void *buf, 6375 size_t max); 6376 6377 6378 /** 6379 * Create a response. The response object can be extended with 6380 * header information. 6381 * 6382 * @param sc status code to return 6383 * @param size size of the data portion of the response, #MHD_SIZE_UNKNOWN for unknown 6384 * @param dyn_cont callback to use to obtain response data 6385 * @param dyn_cont_cls extra argument to @a crc 6386 * @param dyn_cont_fc callback to call to free @a dyn_cont_cls resources 6387 * @return NULL on error (i.e. invalid arguments, out of memory) 6388 * FIXME: Call free callback on error? 6389 * @ingroup response 6390 */ 6391 MHD_EXTERN_ struct MHD_Response * 6392 MHD_response_from_callback (enum MHD_HTTP_StatusCode sc, 6393 uint_fast64_t size, 6394 MHD_DynamicContentCreator dyn_cont, 6395 void *dyn_cont_cls, 6396 MHD_FreeCallback dyn_cont_fc); 6397 6398 6399 /** 6400 * Create a response object. The response object can be extended with 6401 * header information. 6402 * 6403 * @param sc status code to use for the response; 6404 * #MHD_HTTP_STATUS_NO_CONTENT is only valid if @a size is 0; 6405 * @param buffer_size the size of the data portion of the response 6406 * @param buffer the @a size bytes containing the response's data portion, 6407 * needs to be valid while the response is used 6408 * @param free_cb the callback to free any allocated data, called 6409 * when response is being destroyed, can be NULL 6410 * to skip the free/cleanup callback; 6411 * @param free_cb_cls the parameter for @a free_cb 6412 * @return NULL on error (i.e. invalid arguments, out of memory) 6413 * on error, @a free_cb is NOT called 6414 * @ingroup response 6415 */ 6416 MHD_EXTERN_ struct MHD_Response * 6417 MHD_response_from_buffer ( 6418 enum MHD_HTTP_StatusCode sc, 6419 size_t buffer_size, 6420 const char *buffer, 6421 MHD_FreeCallback free_cb, 6422 void *free_cb_cls) 6423 MHD_FN_PAR_IN_SIZE_ (3,2); 6424 6425 6426 /** 6427 * Create a response object with body that is a 6428 * statically allocated buffer that never needs to 6429 * be freed as its lifetime exceeds that of the 6430 * daemon. 6431 * 6432 * The response object can be extended with header information and then be used 6433 * any number of times. 6434 * @param sc status code to use for the response 6435 * @param len number of bytes in @a buf 6436 * @param buf buffer with response payload 6437 */ 6438 #define MHD_response_from_buffer_static(sc, len, buf) \ 6439 MHD_response_from_buffer (sc, len, buf, NULL, NULL) 6440 6441 6442 /** 6443 * Create a response object with empty (zero size) body. 6444 * 6445 * The response object can be extended with header information and then be used 6446 * any number of times. 6447 * @param sc status code to use for the response 6448 */ 6449 #define MHD_response_from_empty(sc) \ 6450 MHD_response_from_buffer_static (sc, 0, "") 6451 6452 6453 /** 6454 * Create a response object. The response object can be extended with 6455 * header information. 6456 * 6457 * @param sc status code to use for the response 6458 * @param buffer_size the size of the data portion of the response 6459 * @param buffer the @a size bytes containing the response's data portion, 6460 * an internal copy will be made, there is no need to 6461 * keep this data after return from this function 6462 * @return NULL on error (i.e. invalid arguments, out of memory) 6463 * FIXME: Call free callback on error? 6464 * @ingroup response 6465 */ 6466 MHD_EXTERN_ struct MHD_Response * 6467 MHD_response_from_buffer_copy ( 6468 enum MHD_HTTP_StatusCode sc, 6469 size_t buffer_size, 6470 const char buffer[MHD_FN_PAR_DYN_ARR_SIZE_ (buffer_size)]) 6471 MHD_FN_PAR_IN_SIZE_ (3,2); 6472 6473 6474 /** 6475 * I/O vector type. Provided for use with #MHD_response_from_iovec(). 6476 * @ingroup response 6477 */ 6478 struct MHD_IoVec 6479 { 6480 /** 6481 * The pointer to the memory region for I/O. 6482 */ 6483 const void *iov_base; 6484 6485 /** 6486 * The size in bytes of the memory region for I/O. 6487 */ 6488 size_t iov_len; 6489 }; 6490 6491 6492 /** 6493 * Create a response object with an array of memory buffers 6494 * used as the response body. 6495 * 6496 * The response object can be extended with header information. 6497 * 6498 * If response object is used to answer HEAD request then the body 6499 * of the response is not used, while all headers (including automatic 6500 * headers) are used. 6501 * 6502 * @param sc status code to use for the response 6503 * @param iov_count the number of elements in @a iov 6504 * @param iov the array for response data buffers, an internal copy of this 6505 * will be made 6506 * @param free_cb the callback to clean up any data associated with @a iov when 6507 * the response is destroyed. 6508 * @param free_cb_cls the argument passed to @a free_cb 6509 * @return NULL on error (i.e. invalid arguments, out of memory) 6510 * FIXME: Call free callback on error? 6511 * @ingroup response 6512 */ 6513 MHD_EXTERN_ struct MHD_Response * 6514 MHD_response_from_iovec ( 6515 enum MHD_HTTP_StatusCode sc, 6516 unsigned int iov_count, 6517 const struct MHD_IoVec iov[MHD_FN_PAR_DYN_ARR_SIZE_ (iov_count)], 6518 MHD_FreeCallback free_cb, 6519 void *free_cb_cls); 6520 6521 6522 /** 6523 * Create a response object based on an @a fd from which 6524 * data is read. The response object can be extended with 6525 * header information. 6526 * 6527 * @param sc status code to return 6528 * @param fd file descriptor referring to a file on disk with the 6529 * data; will be closed when response is destroyed; 6530 * fd should be in 'blocking' mode 6531 * @param offset offset to start reading from in the file; 6532 * reading file beyond 2 GiB may be not supported by OS or 6533 * MHD build; see #MHD_LIB_INFO_FIXED_HAS_LARGE_FILE 6534 * @param size size of the data portion of the response; 6535 * sizes larger than 2 GiB may be not supported by OS or 6536 * MHD build; see #MHD_LIB_INFO_FIXED_HAS_LARGE_FILE 6537 * @return NULL on error (i.e. invalid arguments, out of memory) 6538 * FIXME: Close FD on error? 6539 * @ingroup response 6540 */ 6541 MHD_EXTERN_ struct MHD_Response * 6542 MHD_response_from_fd (enum MHD_HTTP_StatusCode sc, 6543 int fd, 6544 uint_fast64_t offset, 6545 uint_fast64_t size) 6546 MHD_FN_PAR_FD_READ_ (2); 6547 6548 /** 6549 * Create a response object with the response body created by reading 6550 * the provided pipe. 6551 * 6552 * The response object can be extended with header information and 6553 * then be used ONLY ONCE. 6554 * 6555 * If response object is used to answer HEAD request then the body 6556 * of the response is not used, while all headers (including automatic 6557 * headers) are used. 6558 * 6559 * @param sc status code to use for the response 6560 * @param fd file descriptor referring to a read-end of a pipe with the 6561 * data; will be closed when response is destroyed; 6562 * fd should be in 'blocking' mode 6563 * @return NULL on error (i.e. invalid arguments, out of memory) 6564 * FIXME: Close pipe FD on error? 6565 * @ingroup response 6566 */ 6567 MHD_EXTERN_ struct MHD_Response * 6568 MHD_response_from_pipe (enum MHD_HTTP_StatusCode sc, 6569 int fd) 6570 MHD_FN_PAR_FD_READ_ (2); 6571 6572 6573 /** 6574 * Destroy response. 6575 * Should be called if response was created but not consumed. 6576 * Also must be called if response has #MHD_R_O_REUSABLE set. 6577 * The actual destroy can be happen later, if the response 6578 * is still being used in any request. 6579 * The function does not block. 6580 * 6581 * @param[in] response the response to destroy 6582 * @ingroup response 6583 */ 6584 MHD_EXTERN_ void 6585 MHD_response_destroy (struct MHD_Response *response) 6586 MHD_FN_PAR_NONNULL_ (1); 6587 6588 6589 /** 6590 * Add a header line to the response. 6591 * 6592 * @param response response to add a header to, NULL is tolerated 6593 * @param name the name of the header to add, 6594 * an internal copy of the string will be made 6595 * @param value the value of the header to add, 6596 * an internal copy of the string will be made 6597 * @return #MHD_SC_OK on success, 6598 * error code otherwise 6599 * @ingroup response 6600 */ 6601 MHD_EXTERN_ enum MHD_StatusCode 6602 MHD_response_add_header (struct MHD_Response *MHD_RESTRICT response, 6603 const char *MHD_RESTRICT name, 6604 const char *MHD_RESTRICT value) 6605 MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2) 6606 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_CSTR_ (3); 6607 6608 6609 /** 6610 * Add a header with predefined (standard) name to the response. 6611 * 6612 * @param response response to add a header to 6613 * @param stk the code of the predefined header 6614 * @param content the value of the header to add, 6615 * an internal copy of the string will be made 6616 * @return #MHD_SC_OK on success, 6617 * error code otherwise 6618 * @ingroup response 6619 */ 6620 MHD_EXTERN_ enum MHD_StatusCode 6621 MHD_response_add_predef_header (struct MHD_Response *MHD_RESTRICT response, 6622 enum MHD_PredefinedHeader stk, 6623 const char *MHD_RESTRICT content) 6624 MHD_FN_PAR_NONNULL_ (1) 6625 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_CSTR_ (3); 6626 6627 6628 /* ************ (b) Upload and PostProcessor functions ********************** */ 6629 6630 6631 /** 6632 * Suspend handling of network data for a given request. This can 6633 * be used to dequeue a request from MHD's event loop for a while. 6634 * 6635 * Suspended requests continue to count against the total number of 6636 * requests allowed (per daemon, as well as per IP, if such limits 6637 * are set). Suspended requests will NOT time out; timeouts will 6638 * restart when the request handling is resumed. While a 6639 * request is suspended, MHD may not detect disconnects by the 6640 * client. 6641 * 6642 * At most one upload action can be created for one upload callback. 6643 * 6644 * @param[in,out] request the request for which the action is generated 6645 * @return action to cause a request to be suspended, 6646 * NULL if any action has been already created for the @a request 6647 * @ingroup action 6648 */ 6649 MHD_EXTERN_ const struct MHD_UploadAction * 6650 MHD_upload_action_suspend (struct MHD_Request *request) 6651 MHD_FN_PAR_NONNULL_ALL_; 6652 6653 /** 6654 * Converts a @a response to an action. If #MHD_R_O_REUSABLE 6655 * is not set, the reference to the @a response is consumed 6656 * by the conversion. If #MHD_R_O_REUSABLE is #MHD_YES, 6657 * then the @a response can be used again to create actions in 6658 * the future. 6659 * However, the @a response is frozen by this step and 6660 * must no longer be modified (i.e. by setting headers). 6661 * 6662 * At most one upload action can be created for one upload callback. 6663 * 6664 * @param request the request to create the action for 6665 * @param[in] response the response to convert, 6666 * if NULL then this function is equivalent to 6667 * #MHD_upload_action_abort_request() call 6668 * @return pointer to the action, the action must be consumed 6669 * otherwise response object may leak; 6670 * NULL if failed (no memory) or if any action has been already 6671 * created for the @a request; 6672 * when failed the response object is consumed and need not 6673 * to be "destroyed" 6674 * @ingroup action 6675 */ 6676 MHD_EXTERN_ const struct MHD_UploadAction * 6677 MHD_upload_action_from_response (struct MHD_Request *MHD_RESTRICT request, 6678 struct MHD_Response *MHD_RESTRICT response) 6679 MHD_FN_PAR_NONNULL_ (1); 6680 6681 /** 6682 * Action telling MHD to continue processing the upload. 6683 * Valid only for incremental upload processing. 6684 * Works as #MHD_upload_action_abort_request() if used for full upload callback 6685 * or for the final (with zero data) incremental callback. 6686 * 6687 * At most one upload action can be created for one upload callback. 6688 * 6689 * @param request the request to make an action 6690 * @return action operation, 6691 * NULL if any action has been already created for the @a request 6692 * @ingroup action 6693 */ 6694 MHD_EXTERN_ const struct MHD_UploadAction * 6695 MHD_upload_action_continue (struct MHD_Request *request) 6696 MHD_FN_PAR_NONNULL_ (1); 6697 6698 6699 /** 6700 * Action telling MHD to close the connection hard 6701 * (kind-of breaking HTTP specification). 6702 * 6703 * @param req the request to make an action 6704 * @return action operation, always NULL 6705 * @ingroup action 6706 */ 6707 #define MHD_upload_action_abort_request(req) \ 6708 MHD_STATIC_CAST_ (const struct MHD_UploadAction *, NULL) 6709 6710 #ifndef MHD_UPLOADCALLBACK_DEFINED 6711 6712 /** 6713 * Function to process data uploaded by a client. 6714 * 6715 * @param upload_cls the argument given together with the function 6716 * pointer when the handler was registered with MHD 6717 * @param request the request is being processed 6718 * @param content_data_size the size of the @a content_data, 6719 * zero when all data have been processed 6720 * @param[in] content_data the uploaded content data, 6721 * may be modified in the callback, 6722 * valid only until return from the callback, 6723 * NULL when all data have been processed 6724 * @return action specifying how to proceed: 6725 * #MHD_upload_action_continue() to continue upload (for incremental 6726 * upload processing only), 6727 * #MHD_upload_action_suspend() to stop reading the upload until 6728 * the request is resumed, 6729 * #MHD_upload_action_abort_request() to close the socket, 6730 * or a response to discard the rest of the upload and transmit 6731 * the response 6732 * @ingroup action 6733 */ 6734 typedef const struct MHD_UploadAction * 6735 (MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_INOUT_SIZE_ (4,3) 6736 *MHD_UploadCallback)(void *upload_cls, 6737 struct MHD_Request *request, 6738 size_t content_data_size, 6739 void *content_data); 6740 6741 #define MHD_UPLOADCALLBACK_DEFINED 1 6742 #endif /* ! MHD_UPLOADCALLBACK_DEFINED */ 6743 6744 /** 6745 * Create an action that handles an upload. 6746 * 6747 * If @a uc_inc is NULL and upload cannot fit the allocated buffer 6748 * then request is aborted without response. 6749 * 6750 * At most one action can be created for any request. 6751 * 6752 * @param request the request to create action for 6753 * @param large_buffer_size how large should the upload buffer be. 6754 * May allocate memory from the shared "large" 6755 * memory pool if necessary and non-zero is given. 6756 * Must be zero if @a uc_full is NULL. 6757 * @param uc_full the function to call when complete upload 6758 * is received (only if fit @a upload_buffer_size), 6759 * can be NULL if uc_inc is not NULL, 6760 * must be NULL is @a upload_buffer_size is zero. 6761 * @param uc_full_cls closure for @a uc_full 6762 * @param uc_inc the function to incrementally process the upload data 6763 * if the upload if larger than @a upload_buffer_size or 6764 * @a upload_buffer_size cannot be allocated or 6765 * @a uc_full is NULL, 6766 * can be NULL if uc_full is not NULL 6767 * @param uc_inc_cls closure for @a uc_inc 6768 * @return NULL on error (out of memory, invalid parameters) 6769 * @return pointer to the action, 6770 * NULL if failed (no memory) or if any action has been already 6771 * created for the @a request. 6772 * @sa #MHD_D_OPTION_LARGE_POOL_SIZE() 6773 * @ingroup action 6774 */ 6775 MHD_EXTERN_ const struct MHD_Action * 6776 MHD_action_process_upload ( 6777 struct MHD_Request *request, 6778 size_t large_buffer_size, 6779 MHD_UploadCallback uc_full, 6780 void *uc_full_cls, 6781 MHD_UploadCallback uc_inc, 6782 void *uc_inc_cls) 6783 MHD_FN_PAR_NONNULL_ (1); 6784 6785 /** 6786 * Create an action that handles an upload as full upload data. 6787 * 6788 * @param request the request to create action for 6789 * @param buff_size how large should the upload buffer be. May allocate memory 6790 * from the large memory pool if necessary. Must not be zero. 6791 * @param uc the function to call when complete upload 6792 * is received (only if fit @a upload_buffer_size) 6793 * @param uc_cls closure for @a uc 6794 * @return NULL on error (out of memory. both @a uc is NULL) 6795 * @ingroup action 6796 */ 6797 #define MHD_action_process_upload_full(request,buff_size,uc,uc_cls) \ 6798 MHD_action_process_upload (request, buff_size, uc, uc_cls, NULL, NULL) 6799 6800 /** 6801 * Create an action that handles an upload incrementally. 6802 * 6803 * @param request the request to create action for 6804 * @param uc the function to incrementally process the upload data 6805 * @param uc_cls closure for @a uc 6806 * @return NULL on error (out of memory. both @a uc is NULL) 6807 * @ingroup action 6808 */ 6809 #define MHD_action_process_upload_inc(request,uc,uc_cls) \ 6810 MHD_action_process_upload (request, 0, NULL, NULL, uc, uc_cls) 6811 6812 #ifndef MHD_POST_PARSE_RESULT_DEFINED 6813 6814 /** 6815 * The result of POST data parsing 6816 */ 6817 enum MHD_FIXED_ENUM_MHD_SET_ MHD_PostParseResult 6818 { 6819 /** 6820 * The POST data parsed successfully and completely. 6821 */ 6822 MHD_POST_PARSE_RES_OK = 0 6823 , 6824 /** 6825 * The POST request has no content or zero-length content. 6826 */ 6827 MHD_POST_PARSE_RES_REQUEST_EMPTY = 1 6828 , 6829 /** 6830 * The POST data parsed successfully, but has missing or incorrect 6831 * termination. 6832 * The last parsed field may have incorrect data. 6833 */ 6834 MHD_POST_PARSE_RES_OK_BAD_TERMINATION = 2 6835 , 6836 /** 6837 * Parsing of the POST data is incomplete because client used incorrect 6838 * format of POST encoding. 6839 * The last parsed field may have incorrect data. 6840 * Some POST data is available or has been provided via callback. 6841 */ 6842 MHD_POST_PARSE_RES_PARTIAL_INVALID_POST_FORMAT = 3 6843 , 6844 /** 6845 * The POST data cannot be parsed completely because the stream has 6846 * no free pool memory. 6847 * Some POST data may be parsed. 6848 */ 6849 MHD_POST_PARSE_RES_FAILED_NO_POOL_MEM = 60 6850 , 6851 /** 6852 * The POST data cannot be parsed completely because no "large shared buffer" 6853 * space is available. 6854 * Some POST data may be parsed. 6855 */ 6856 MHD_POST_PARSE_RES_FAILED_NO_LARGE_BUF_MEM = 61 6857 , 6858 /** 6859 * The POST data cannot be parsed because 'Content-Type:' is unknown. 6860 */ 6861 MHD_POST_PARSE_RES_FAILED_UNKNOWN_CNTN_TYPE = 80 6862 , 6863 /** 6864 * The POST data cannot be parsed because 'Content-Type:' header is not set. 6865 */ 6866 MHD_POST_PARSE_RES_FAILED_NO_CNTN_TYPE = 81 6867 , 6868 /** 6869 * The POST data cannot be parsed because "Content-Type:" request header has 6870 * no "boundary" parameter for "multipart/form-data" 6871 */ 6872 MHD_POST_PARSE_RES_FAILED_HEADER_NO_BOUNDARY = 82 6873 , 6874 /** 6875 * The POST data cannot be parsed because "Content-Type: multipart/form-data" 6876 * request header is misformed 6877 */ 6878 MHD_POST_PARSE_RES_FAILED_HEADER_MISFORMED = 83 6879 , 6880 /** 6881 * The application set POST encoding to "multipart/form-data", but the request 6882 * has no "Content-Type: multipart/form-data" header which is required 6883 * to find "boundary" used in this encoding 6884 */ 6885 MHD_POST_PARSE_RES_FAILED_HEADER_NOT_MPART = 84 6886 , 6887 /** 6888 * The POST data cannot be parsed because client used incorrect format 6889 * of POST encoding. 6890 */ 6891 MHD_POST_PARSE_RES_FAILED_INVALID_POST_FORMAT = 90 6892 6893 }; 6894 6895 #define MHD_POST_PARSE_RESULT_DEFINED 1 6896 #endif /* ! MHD_POST_PARSE_RESULT_DEFINED */ 6897 6898 #ifndef MHD_POST_DATA_READER_DEFINED 6899 6900 /** 6901 * "Stream" reader for POST data. 6902 * This callback is called to incrementally process parsed POST data sent by 6903 * the client. 6904 * The pointers to the MHD_String and MHD_StringNullable are valid only until 6905 * return from this callback. 6906 * The pointers to the strings and the @a data are valid only until return from 6907 * this callback. 6908 * 6909 * @param req the request 6910 * @param cls user-specified closure 6911 * @param name the name of the POST field 6912 * @param filename the name of the uploaded file, @a cstr member is NULL if not 6913 * known / not provided 6914 * @param content_type the mime-type of the data, cstr member is NULL if not 6915 * known / not provided 6916 * @param encoding the encoding of the data, cstr member is NULL if not known / 6917 * not provided 6918 * @param size the number of bytes in @a data available, may be zero if 6919 * the @a final_data is #MHD_YES 6920 * @param data the pointer to @a size bytes of data at the specified 6921 * @a off offset, NOT zero-terminated 6922 * @param off the offset of @a data in the overall value, always equal to 6923 * the sum of sizes of previous calls for the same field / file; 6924 * client may provide more than one field with the same name and 6925 * the same filename, the new filed (or file) is indicated by zero 6926 * value of @a off (and the end is indicated by @a final_data) 6927 * @param final_data if set to #MHD_YES then full field data is provided, 6928 * if set to #MHD_NO then more field data may be provided 6929 * @return action specifying how to proceed: 6930 * #MHD_upload_action_continue() if all is well, 6931 * #MHD_upload_action_suspend() to stop reading the upload until 6932 * the request is resumed, 6933 * #MHD_upload_action_abort_request() to close the socket, 6934 * or a response to discard the rest of the upload and transmit 6935 * the response 6936 * @ingroup action 6937 */ 6938 typedef const struct MHD_UploadAction * 6939 (MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_NONNULL_ (4) 6940 MHD_FN_PAR_NONNULL_ (5) MHD_FN_PAR_NONNULL_ (6) 6941 *MHD_PostDataReader) (struct MHD_Request *req, 6942 void *cls, 6943 const struct MHD_String *name, 6944 const struct MHD_StringNullable *filename, 6945 const struct MHD_StringNullable *content_type, 6946 const struct MHD_StringNullable *encoding, 6947 size_t size, 6948 const void *data, 6949 uint_fast64_t off, 6950 enum MHD_Bool final_data); 6951 6952 6953 /** 6954 * The callback to be called when finished with processing 6955 * of the postprocessor upload data. 6956 * @param req the request 6957 * @param cls the closure 6958 * @param parsing_result the result of POST data parsing 6959 * @return the action to proceed 6960 */ 6961 typedef const struct MHD_UploadAction * 6962 (MHD_FN_PAR_NONNULL_ (1) 6963 *MHD_PostDataFinished) (struct MHD_Request *req, 6964 void *cls, 6965 enum MHD_PostParseResult parsing_result); 6966 6967 #define MHD_POST_DATA_READER_DEFINED 1 6968 #endif /* ! MHD_POST_DATA_READER_DEFINED */ 6969 6970 /** 6971 * Create an action to parse the POSTed content from the client. 6972 * 6973 * The action starts parsing of the POST data. Any value that does not fit 6974 * @a buffer_size or larger that @a auto_stream_size is given to 6975 * @a stream_reader (if it is not NULL). 6976 * 6977 * If @a buffer_size is zero, then buffers will be limited to the connection's 6978 * memory pool. To force all POST data process via @a stream_reader 6979 * set @a auto_stream_size to zero. 6980 * 6981 * At most one action can be created for any request. 6982 * 6983 * @param request the request to create action for 6984 * @param buffer_size the maximum size allowed for the buffers to parse this 6985 * request POST data. Within the set limit the buffer is 6986 * allocated automatically from the "large" shared memory 6987 * pool if necessary. 6988 * @param max_nonstream_size the size of the field (in encoded form) above which 6989 * values are not buffered and provided for 6990 * the @a steam_reader automatically; 6991 * useful to have large data (like file uploads) 6992 * processed incrementally, while keeping buffer space 6993 * for small fields only; 6994 * ignored if @a stream_reader is NULL 6995 * @param enc the data encoding to use, 6996 * use #MHD_HTTP_POST_ENCODING_OTHER to detect automatically 6997 * @param stream_reader the function to call for "oversize" values in 6998 * the stream; can be NULL if @a auto_stream_size is 6999 * not zero 7000 * @param reader_cls the closure for the @a stream_reader 7001 * @param done_cb called once all data has been processed for 7002 * the final action; values smaller than @a auto_stream_size that 7003 * fit into @a buffer_size will be available via 7004 * #MHD_request_get_values_cb(), #MHD_request_get_values_list() and 7005 * #MHD_request_get_post_data_cb(), #MHD_request_get_post_data_list() 7006 * @param done_cb_cls the closure for the @a done_cb 7007 * @return pointer to the action, 7008 * NULL if failed (no memory) or if any action has been already 7009 * created for the @a request. 7010 * @sa #MHD_D_OPTION_LARGE_POOL_SIZE() 7011 * @ingroup action 7012 */ 7013 MHD_EXTERN_ const struct MHD_Action * 7014 MHD_action_parse_post (struct MHD_Request *request, 7015 size_t buffer_size, 7016 size_t max_nonstream_size, 7017 enum MHD_HTTP_PostEncoding enc, 7018 MHD_PostDataReader stream_reader, 7019 void *reader_cls, 7020 MHD_PostDataFinished done_cb, 7021 void *done_cb_cls) 7022 MHD_FN_PAR_NONNULL_ (1); 7023 7024 7025 #ifndef MHD_POSTFILED_DEFINED 7026 7027 /** 7028 * Post data element. 7029 * If any member is not provided/set then pointer to C string is NULL. 7030 * If any member is set to empty string then pointer to C string not NULL, 7031 * but the length is zero. 7032 */ 7033 struct MHD_PostField 7034 { 7035 /** 7036 * The name of the field 7037 */ 7038 struct MHD_String name; 7039 /** 7040 * The field data 7041 * If not set or defined then to C string is NULL. 7042 * If set to empty string then pointer to C string not NULL, 7043 * but the length is zero. 7044 */ 7045 struct MHD_StringNullable value; 7046 /** 7047 * The filename if provided (only for "multipart/form-data") 7048 * If not set or defined then to C string is NULL. 7049 * If set to empty string then pointer to C string not NULL, 7050 * but the length is zero. 7051 */ 7052 struct MHD_StringNullable filename; 7053 /** 7054 * The Content-Type if provided (only for "multipart/form-data") 7055 * If not set or defined then to C string is NULL. 7056 * If set to empty string then pointer to C string not NULL, 7057 * but the length is zero. 7058 */ 7059 struct MHD_StringNullable content_type; 7060 /** 7061 * The Transfer-Encoding if provided (only for "multipart/form-data") 7062 * If not set or defined then to C string is NULL. 7063 * If set to empty string then pointer to C string not NULL, 7064 * but the length is zero. 7065 */ 7066 struct MHD_StringNullable transfer_encoding; 7067 }; 7068 7069 #define MHD_POSTFILED_DEFINED 1 7070 #endif /* ! MHD_POSTFILED_DEFINED */ 7071 7072 7073 /** 7074 * Iterator over POST data. 7075 * 7076 * The @a data pointer is valid only until return from this function. 7077 * 7078 * The pointers to the strings in @a data are valid until any MHD_UploadAction 7079 * is provided. If the data is needed beyond this point, it should be copied. 7080 * 7081 * @param cls closure 7082 * @param data the element of the post data, the pointer is valid only until 7083 * return from this function 7084 * @return #MHD_YES to continue iterating, 7085 * #MHD_NO to abort the iteration 7086 * @ingroup request 7087 */ 7088 typedef enum MHD_Bool 7089 (MHD_FN_PAR_NONNULL_ (2) 7090 *MHD_PostDataIterator)(void *cls, 7091 const struct MHD_PostField *data); 7092 7093 /** 7094 * Get all of the post data from the request via request. 7095 * 7096 * @param request the request to get data for 7097 * @param iterator callback to call on each header; 7098 * maybe NULL (then just count headers) 7099 * @param iterator_cls extra argument to @a iterator 7100 * @return number of entries iterated over 7101 * @ingroup request 7102 */ 7103 MHD_EXTERN_ size_t 7104 MHD_request_get_post_data_cb (struct MHD_Request *request, 7105 MHD_PostDataIterator iterator, 7106 void *iterator_cls) 7107 MHD_FN_PAR_NONNULL_ (1); 7108 7109 /** 7110 * Get all of the post data from the request. 7111 * 7112 * The pointers to the strings in @a elements are valid until any 7113 * MHD_UploadAction is provided. If the data is needed beyond this point, 7114 * it should be copied. 7115 * @param request the request to get data for 7116 * @param num_elements the number of elements in @a elements array 7117 * @param[out] elements the array of @a num_elements to get the data 7118 * @return the number of elements stored in @a elements, 7119 * zero if no data or postprocessor was not used. 7120 * @ingroup request 7121 */ 7122 MHD_EXTERN_ size_t 7123 MHD_request_get_post_data_list ( 7124 struct MHD_Request *request, 7125 size_t num_elements, 7126 struct MHD_PostField elements[MHD_FN_PAR_DYN_ARR_SIZE_ (num_elements)]) 7127 MHD_FN_PAR_NONNULL_ (1) 7128 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_SIZE_ (3,2); 7129 7130 /* ***************** (c) WebSocket support ********** */ 7131 7132 /** 7133 * Handle given to the application to manage special 7134 * actions relating to MHD responses that "upgrade" 7135 * the HTTP protocol (i.e. to WebSockets). 7136 */ 7137 struct MHD_UpgradedHandle; 7138 7139 7140 #ifndef MHD_UPGRADEHANDLER_DEFINED 7141 7142 /** 7143 * Function called after a protocol "upgrade" response was sent successfully 7144 * and the connection is being switched to other protocol. 7145 * 7146 * The newly provided handle @a urh can be used to send and receive the data 7147 * by #MHD_upgraded_send() and #MHD_upgraded_recv(). The handle must be closed 7148 * by #MHD_upgraded_close() before destroying the daemon. 7149 * 7150 * "Upgraded" connection will not time out, but still counted for daemon 7151 * global connections limit and for per-IP limit (if set). 7152 * 7153 * Except when in 'thread-per-connection' mode, implementations 7154 * of this function should never block (as it will still be called 7155 * from within the main event loop). 7156 * 7157 * @param cls closure, whatever was given to #MHD_action_upgrade(). 7158 * @param request original HTTP request handle, 7159 * giving the function a last chance 7160 * to inspect the original HTTP request 7161 * @param urh argument for #MHD_upgrade_operation() on this @a response. 7162 * Applications must eventually use this callback to (indirectly) 7163 * perform the close() action on the @a sock. 7164 */ 7165 typedef void 7166 (MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_NONNULL_ (3) 7167 *MHD_UpgradeHandler)(void *cls, 7168 struct MHD_Request *MHD_RESTRICT request, 7169 struct MHD_UpgradedHandle *MHD_RESTRICT urh); 7170 7171 #define MHD_UPGRADEHANDLER_DEFINED 1 7172 #endif /* ! MHD_UPGRADEHANDLER_DEFINED */ 7173 7174 7175 /** 7176 * Create a action object that can be used for 101 Upgrade 7177 * responses, for example to implement WebSockets. After sending the 7178 * response, control over the data stream is given to the callback (which 7179 * can then, for example, start some bi-directional communication). 7180 * The callback will ONLY be called after the response header was successfully 7181 * passed to the OS; if there are communication errors before, the usual MHD 7182 * connection error handling code will be performed. 7183 * 7184 * At most one action can be created for any request. 7185 * 7186 * @param request the request to create action for 7187 * @param upgrade_hdr_value the value of the "Upgrade:" header, mandatory 7188 string 7189 * @param upgrade_handler function to call with the "upgraded" socket 7190 * @param upgrade_handler_cls closure for @a upgrade_handler 7191 * @param num_headers number of elements in the @a headers array, 7192 * must be zero if @a headers is NULL 7193 * @param headers the optional pointer to the array of the headers (the strings 7194 * are copied and does not need to be valid after return from 7195 * this function), 7196 * can be NULL if @a num_headers is zero 7197 * @return NULL on error (i.e. invalid arguments, out of memory) 7198 * @ingroup action 7199 */ 7200 MHD_EXTERN_ const struct MHD_Action * 7201 MHD_action_upgrade (struct MHD_Request *MHD_RESTRICT request, 7202 const char *MHD_RESTRICT upgrade_hdr_value, 7203 MHD_UpgradeHandler upgrade_handler, 7204 void *upgrade_handler_cls, 7205 size_t num_headers, 7206 const struct MHD_NameValueCStr *MHD_RESTRICT headers) 7207 MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2) 7208 MHD_FN_PAR_IN_SIZE_ (6,5); 7209 7210 7211 /** 7212 * Create a action object that can be used for 101 Upgrade 7213 * responses, for example to implement WebSockets. After sending the 7214 * response, control over the data stream is given to the callback (which 7215 * can then, for example, start some bi-directional communication). 7216 * The callback will ONLY be called after the response header was successfully 7217 * passed to the OS; if there are communication errors before, the usual MHD 7218 * connection error handling code will be performed. 7219 * 7220 * At most one action can be created for any request. 7221 * 7222 * @param request the request to create action for 7223 * @param upgrade_hdr_value the value of the "Upgrade:" header, mandatory 7224 string 7225 * @param upgrade_handler function to call with the "upgraded" socket 7226 * @param upgrade_handler_cls closure for @a upgrade_handler 7227 * @param num_headers number of elements in the @a headers array, 7228 * must be zero if @a headers is NULL 7229 * @param headers the optional pointer to the array of the headers (the strings 7230 * are copied and does not need to be valid after return from 7231 * this function), 7232 * can be NULL if @a num_headers is zero 7233 * @return NULL on error (i.e. invalid arguments, out of memory) 7234 * @ingroup action 7235 */ 7236 MHD_EXTERN_ const struct MHD_UploadAction * 7237 MHD_upload_action_upgrade ( 7238 struct MHD_Request *MHD_RESTRICT request, 7239 const char *MHD_RESTRICT upgrade_hdr_value, 7240 MHD_UpgradeHandler upgrade_handler, 7241 void *upgrade_handler_cls, 7242 size_t num_headers, 7243 const struct MHD_NameValueCStr *MHD_RESTRICT headers) 7244 MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2) 7245 MHD_FN_PAR_IN_SIZE_ (6,5); 7246 7247 7248 /** 7249 * Receive data on the HTTP-Upgraded connection. 7250 * 7251 * The function finished if one of the following happens: 7252 * + ANY amount of data has been received, 7253 * + timeout reached, 7254 * + network error occurs 7255 * 7256 * @param urh the HTTP-Upgraded handle 7257 * @param recv_buf_size the size of the @a recv_buf 7258 * @param recv_buf the buffer to receive the data 7259 * @param received_size the pointer to variable to get amount of received data 7260 * @param max_wait_millisec the maximum wait time for the data, 7261 * non-blocking operation if set to zero, 7262 * wait indefinitely if larger or equal to 7263 * #MHD_WAIT_INDEFINITELY, 7264 * the function may return earlier if waiting is 7265 * interrupted or by other reasons 7266 * @return #MHD_SC_OK if ANY data received (check the @a received_size) or 7267 * remote shut down send side (indicated by @a received_size 7268 * set to zero), 7269 * #MHD_SC_UPGRADED_NET_TIMEOUT if NO data received but timeout expired, 7270 * #MHD_SC_UPGRADED_NET_CONN_CLOSED if network connection has been 7271 * closed, 7272 * #MHD_SC_UPGRADED_NET_CONN_BROKEN if broken network connection has 7273 * been detected, 7274 * #MHD_SC_UPGRADED_TLS_ERROR if TLS error occurs (only for TLS), 7275 * #MHD_SC_UPGRADED_NET_HARD_ERROR if any other network or sockets 7276 * unrecoverable error occurs, 7277 * #MHD_SC_UPGRADED_HANDLE_INVALID if @a urh is invalid, 7278 * #MHD_SC_UPGRADED_WAITING_NOT_SUPPORTED if timed wait is not supported 7279 * by this MHD build or platform 7280 */ 7281 MHD_EXTERN_ enum MHD_StatusCode 7282 MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh, 7283 size_t recv_buf_size, 7284 void *MHD_RESTRICT recv_buf, 7285 size_t *MHD_RESTRICT received_size, 7286 uint_fast64_t max_wait_millisec) 7287 MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3,2) 7288 MHD_FN_PAR_OUT_ (4); 7289 7290 7291 /** 7292 * Send data on the HTTP-Upgraded connection. 7293 * 7294 * The function finished if one of the following happens: 7295 * + ALL provided data has been sent, 7296 * + timeout reached, 7297 * + network error occurs 7298 * 7299 * Parameter @a more_data_to_come controls network buffering. When set to 7300 * #MHD_YES, the OS waits shortly for additional data and tries to use 7301 * the network more effeciently delaying the last network packet, if it is 7302 * incomplete, to combine it with the next data provided. 7303 * 7304 * @param urh the HTTP-Upgraded handle 7305 * @param send_buf_size the amount of data in the @a send_buf 7306 * @param send_buf the buffer with the data to send 7307 * @param sent_size the pointer to get the amout of sent data 7308 * @param max_wait_millisec the maximum wait time for the data, 7309 * non-blocking operation if set to zero, 7310 * wait indefinitely if larger or equal to 7311 * #MHD_WAIT_INDEFINITELY 7312 * @param more_data_to_come set to #MHD_YES if the provided data in 7313 * the @a send_buf is part of a larger data package, 7314 * like an incomplete message or streamed 7315 * (not the final) part of some file, and more data 7316 * expected to be sent soon over the same connection, 7317 * set to #MHD_NO the data in the @a send_buf is 7318 * the complete message or the final part of 7319 * the message (or file) and it should be pushed 7320 * to the network (and to the client) as soon 7321 * as possible 7322 * @return #MHD_SC_OK if ANY data sent (check the @a sent_size), 7323 * #MHD_SC_UPGRADED_NET_TIMEOUT if NO data sent but timeout expired, 7324 * #MHD_SC_UPGRADED_NET_CONN_CLOSED if network connection has been 7325 * closed, 7326 * #MHD_SC_UPGRADED_NET_CONN_BROKEN if broken network connection has 7327 * been detected, 7328 * #MHD_SC_UPGRADED_TLS_ERROR if TLS error occurs (only for TLS), 7329 * #MHD_SC_UPGRADED_NET_HARD_ERROR if any other network or sockets 7330 * unrecoverable error occurs, 7331 * #MHD_SC_UPGRADED_HANDLE_INVALID if @a urh is invalid, 7332 * #MHD_SC_UPGRADED_WAITING_NOT_SUPPORTED if timed wait is not supported 7333 * by this MHD build or platform 7334 */ 7335 MHD_EXTERN_ enum MHD_StatusCode 7336 MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh, 7337 size_t send_buf_size, 7338 const void *MHD_RESTRICT send_buf, 7339 size_t *MHD_RESTRICT sent_size, 7340 uint_fast64_t max_wait_millisec, 7341 enum MHD_Bool more_data_to_come) 7342 MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3,2) 7343 MHD_FN_PAR_OUT_ (4); 7344 7345 7346 /** 7347 * Close HTTP-Upgraded connection handle. 7348 * 7349 * The handle cannot be used after successful return from this function. 7350 * 7351 * The function cannot fail if called correctly (the daemon is not destroyed 7352 * and the upgraded connection has not been closed yet). 7353 * 7354 * @param urh the handle to close 7355 * @return #MHD_SC_OK on success, 7356 * error code otherwise 7357 */ 7358 MHD_EXTERN_ enum MHD_StatusCode 7359 MHD_upgraded_close (struct MHD_UpgradedHandle *urh) 7360 MHD_FN_PAR_NONNULL_ (1); 7361 7362 7363 /* ********************** (e) Client auth ********************** */ 7364 7365 7366 /** 7367 * Length of the binary output of the MD5 hash function. 7368 * @sa #MHD_digest_get_hash_size() 7369 * @ingroup authentication 7370 */ 7371 #define MHD_MD5_DIGEST_SIZE 16 7372 7373 /** 7374 * Length of the binary output of the SHA-256 hash function. 7375 * @sa #MHD_digest_get_hash_size() 7376 * @ingroup authentication 7377 */ 7378 #define MHD_SHA256_DIGEST_SIZE 32 7379 7380 /** 7381 * Length of the binary output of the SHA-512/256 hash function. 7382 * @warning While this value is the same as the #MHD_SHA256_DIGEST_SIZE, 7383 * the calculated digests for SHA-256 and SHA-512/256 are different. 7384 * @sa #MHD_digest_get_hash_size() 7385 * @ingroup authentication 7386 */ 7387 #define MHD_SHA512_256_DIGEST_SIZE 32 7388 7389 /** 7390 * Base type of hash calculation. 7391 * Used as part of #MHD_DigestAuthAlgo values. 7392 * 7393 * @warning Not used directly by MHD API. 7394 */ 7395 enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_DigestBaseAlgo 7396 { 7397 /** 7398 * Invalid hash algorithm value 7399 */ 7400 MHD_DIGEST_BASE_ALGO_INVALID = 0 7401 , 7402 /** 7403 * MD5 hash algorithm. 7404 * As specified by RFC1321 7405 */ 7406 MHD_DIGEST_BASE_ALGO_MD5 = (1u << 0) 7407 , 7408 /** 7409 * SHA-256 hash algorithm. 7410 * As specified by FIPS PUB 180-4 7411 */ 7412 MHD_DIGEST_BASE_ALGO_SHA256 = (1u << 1) 7413 , 7414 /** 7415 * SHA-512/256 hash algorithm. 7416 * As specified by FIPS PUB 180-4 7417 */ 7418 MHD_DIGEST_BASE_ALGO_SHA512_256 = (1u << 2) 7419 }; 7420 7421 /** 7422 * The flag indicating non-session algorithm types, 7423 * like 'MD5', 'SHA-256' or 'SHA-512-256'. 7424 */ 7425 #define MHD_DIGEST_AUTH_ALGO_NON_SESSION (1u << 6) 7426 7427 /** 7428 * The flag indicating session algorithm types, 7429 * like 'MD5-sess', 'SHA-256-sess' or 'SHA-512-256-sess'. 7430 */ 7431 #define MHD_DIGEST_AUTH_ALGO_SESSION (1u << 7) 7432 7433 /** 7434 * Digest algorithm identification 7435 */ 7436 enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_DigestAuthAlgo 7437 { 7438 /** 7439 * Unknown or wrong algorithm type. 7440 * Used in struct MHD_AuthDigestInfo to indicate client value that 7441 * cannot by identified. 7442 */ 7443 MHD_DIGEST_AUTH_ALGO_INVALID = 0 7444 , 7445 /** 7446 * The 'MD5' algorithm, non-session version. 7447 */ 7448 MHD_DIGEST_AUTH_ALGO_MD5 = 7449 MHD_DIGEST_BASE_ALGO_MD5 | MHD_DIGEST_AUTH_ALGO_NON_SESSION 7450 , 7451 /** 7452 * The 'MD5-sess' algorithm. 7453 * Not supported by MHD for authentication. 7454 */ 7455 MHD_DIGEST_AUTH_ALGO_MD5_SESSION = 7456 MHD_DIGEST_BASE_ALGO_MD5 | MHD_DIGEST_AUTH_ALGO_SESSION 7457 , 7458 /** 7459 * The 'SHA-256' algorithm, non-session version. 7460 */ 7461 MHD_DIGEST_AUTH_ALGO_SHA256 = 7462 MHD_DIGEST_BASE_ALGO_SHA256 | MHD_DIGEST_AUTH_ALGO_NON_SESSION 7463 , 7464 /** 7465 * The 'SHA-256-sess' algorithm. 7466 * Not supported by MHD for authentication. 7467 */ 7468 MHD_DIGEST_AUTH_ALGO_SHA256_SESSION = 7469 MHD_DIGEST_BASE_ALGO_SHA256 | MHD_DIGEST_AUTH_ALGO_SESSION 7470 , 7471 /** 7472 * The 'SHA-512-256' (SHA-512/256) algorithm. 7473 */ 7474 MHD_DIGEST_AUTH_ALGO_SHA512_256 = 7475 MHD_DIGEST_BASE_ALGO_SHA512_256 | MHD_DIGEST_AUTH_ALGO_NON_SESSION 7476 , 7477 /** 7478 * The 'SHA-512-256-sess' (SHA-512/256 session) algorithm. 7479 * Not supported by MHD for authentication. 7480 */ 7481 MHD_DIGEST_AUTH_ALGO_SHA512_256_SESSION = 7482 MHD_DIGEST_BASE_ALGO_SHA512_256 | MHD_DIGEST_AUTH_ALGO_SESSION 7483 }; 7484 7485 7486 /** 7487 * Get digest size in bytes for specified algorithm. 7488 * 7489 * The size of the digest specifies the size of the userhash, userdigest 7490 * and other parameters which size depends on used hash algorithm. 7491 * @param algo the algorithm to check 7492 * @return the size (in bytes) of the digest (either #MHD_MD5_DIGEST_SIZE or 7493 * #MHD_SHA256_DIGEST_SIZE/MHD_SHA512_256_DIGEST_SIZE) 7494 * or zero if the input value is not supported or not valid 7495 * @sa #MHD_digest_auth_calc_userdigest() 7496 * @sa #MHD_digest_auth_calc_userhash(), #MHD_digest_auth_calc_userhash_hex() 7497 * @ingroup authentication 7498 */ 7499 MHD_EXTERN_ size_t 7500 MHD_digest_get_hash_size (enum MHD_DigestAuthAlgo algo) 7501 MHD_FN_CONST_; 7502 7503 /** 7504 * Digest algorithm identification, allow multiple selection. 7505 * 7506 * #MHD_DigestAuthAlgo always can be casted to #MHD_DigestAuthMultiAlgo, but 7507 * not vice versa. 7508 */ 7509 enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_DigestAuthMultiAlgo 7510 { 7511 /** 7512 * Unknown or wrong algorithm type. 7513 */ 7514 MHD_DIGEST_AUTH_MULT_ALGO_INVALID = MHD_DIGEST_AUTH_ALGO_INVALID 7515 , 7516 /** 7517 * The 'MD5' algorithm, non-session version. 7518 */ 7519 MHD_DIGEST_AUTH_MULT_ALGO_MD5 = MHD_DIGEST_AUTH_ALGO_MD5 7520 , 7521 /** 7522 * The 'MD5-sess' algorithm. 7523 * Not supported by MHD for authentication. 7524 * Reserved value. 7525 */ 7526 MHD_DIGEST_AUTH_MULT_ALGO_MD5_SESSION = MHD_DIGEST_AUTH_ALGO_MD5_SESSION 7527 , 7528 /** 7529 * The 'SHA-256' algorithm, non-session version. 7530 */ 7531 MHD_DIGEST_AUTH_MULT_ALGO_SHA256 = MHD_DIGEST_AUTH_ALGO_SHA256 7532 , 7533 /** 7534 * The 'SHA-256-sess' algorithm. 7535 * Not supported by MHD for authentication. 7536 * Reserved value. 7537 */ 7538 MHD_DIGEST_AUTH_MULT_ALGO_SHA256_SESSION = 7539 MHD_DIGEST_AUTH_ALGO_SHA256_SESSION 7540 , 7541 /** 7542 * The 'SHA-512-256' (SHA-512/256) algorithm, non-session version. 7543 */ 7544 MHD_DIGEST_AUTH_MULT_ALGO_SHA512_256 = MHD_DIGEST_AUTH_ALGO_SHA512_256 7545 , 7546 /** 7547 * The 'SHA-512-256-sess' (SHA-512/256 session) algorithm. 7548 * Not supported by MHD for authentication. 7549 * Reserved value. 7550 */ 7551 MHD_DIGEST_AUTH_MULT_ALGO_SHA512_256_SESSION = 7552 MHD_DIGEST_AUTH_ALGO_SHA512_256_SESSION 7553 , 7554 /** 7555 * SHA-256 or SHA-512/256 non-session algorithm, MHD will choose 7556 * the preferred or the matching one. 7557 */ 7558 MHD_DIGEST_AUTH_MULT_ALGO_SHA_ANY_NON_SESSION = 7559 MHD_DIGEST_AUTH_ALGO_SHA256 | MHD_DIGEST_AUTH_ALGO_SHA512_256 7560 , 7561 /** 7562 * Any non-session algorithm, MHD will choose the preferred or 7563 * the matching one. 7564 */ 7565 MHD_DIGEST_AUTH_MULT_ALGO_ANY_NON_SESSION = 7566 (0x3F) | MHD_DIGEST_AUTH_ALGO_NON_SESSION 7567 , 7568 /** 7569 * The SHA-256 or SHA-512/256 session algorithm. 7570 * Not supported by MHD. 7571 * Reserved value. 7572 */ 7573 MHD_DIGEST_AUTH_MULT_ALGO_SHA_ANY_SESSION = 7574 MHD_DIGEST_AUTH_ALGO_SHA256_SESSION 7575 | MHD_DIGEST_AUTH_ALGO_SHA512_256_SESSION 7576 , 7577 /** 7578 * Any session algorithm. 7579 * Not supported by MHD. 7580 * Reserved value. 7581 */ 7582 MHD_DIGEST_AUTH_MULT_ALGO_ANY_SESSION = 7583 (0x3F) | MHD_DIGEST_AUTH_ALGO_SESSION 7584 , 7585 /** 7586 * The MD5 algorithm, session or non-session. 7587 * Currently supported as non-session only. 7588 */ 7589 MHD_DIGEST_AUTH_MULT_ALGO_MD5_ANY = 7590 MHD_DIGEST_AUTH_MULT_ALGO_MD5 | MHD_DIGEST_AUTH_MULT_ALGO_MD5_SESSION 7591 , 7592 /** 7593 * The SHA-256 algorithm, session or non-session. 7594 * Currently supported as non-session only. 7595 */ 7596 MHD_DIGEST_AUTH_MULT_ALGO_SHA256_ANY = 7597 MHD_DIGEST_AUTH_MULT_ALGO_SHA256 7598 | MHD_DIGEST_AUTH_MULT_ALGO_SHA256_SESSION 7599 , 7600 /** 7601 * The SHA-512/256 algorithm, session or non-session. 7602 * Currently supported as non-session only. 7603 */ 7604 MHD_DIGEST_AUTH_MULT_ALGO_SHA512_256_ANY = 7605 MHD_DIGEST_AUTH_MULT_ALGO_SHA512_256 7606 | MHD_DIGEST_AUTH_MULT_ALGO_SHA512_256_SESSION 7607 , 7608 /** 7609 * The SHA-256 or SHA-512/256 algorithm, session or non-session. 7610 * Currently supported as non-session only. 7611 */ 7612 MHD_DIGEST_AUTH_MULT_ALGO_SHA_ANY_ANY = 7613 MHD_DIGEST_AUTH_MULT_ALGO_SHA_ANY_NON_SESSION 7614 | MHD_DIGEST_AUTH_MULT_ALGO_SHA_ANY_SESSION 7615 , 7616 /** 7617 * Any algorithm, MHD will choose the preferred or the matching one. 7618 */ 7619 MHD_DIGEST_AUTH_MULT_ALGO_ANY = 7620 (0x3F) | MHD_DIGEST_AUTH_ALGO_NON_SESSION | MHD_DIGEST_AUTH_ALGO_SESSION 7621 }; 7622 7623 7624 /** 7625 * Calculate "userhash", return it as binary data. 7626 * 7627 * The "userhash" is the hash of the string "username:realm". 7628 * 7629 * The "userhash" could be used to avoid sending username in cleartext in Digest 7630 * Authorization client's header. 7631 * 7632 * Userhash is not designed to hide the username in local database or files, 7633 * as username in cleartext is required for #MHD_digest_auth_check() function 7634 * to check the response, but it can be used to hide username in HTTP headers. 7635 * 7636 * This function could be used when the new username is added to the username 7637 * database to save the "userhash" alongside with the username (preferably) or 7638 * when loading list of the usernames to generate the userhash for every loaded 7639 * username (this will cause delays at the start with the long lists). 7640 * 7641 * Once "userhash" is generated it could be used to identify users by clients 7642 * with "userhash" support. 7643 * Avoid repetitive usage of this function for the same username/realm 7644 * combination as it will cause excessive CPU load; save and reuse the result 7645 * instead. 7646 * 7647 * @param algo the algorithm for userhash calculations 7648 * @param username the username 7649 * @param realm the realm 7650 * @param[out] userhash_bin the output buffer for userhash as binary data; 7651 * if this function succeeds, then this buffer has 7652 * #MHD_digest_get_hash_size() bytes of userhash 7653 * upon return 7654 * @param bin_buf_size the size of the @a userhash_bin buffer, must be 7655 * at least #MHD_digest_get_hash_size() bytes long 7656 * @return #MHD_SC_OK on success, 7657 * #MHD_SC_OUT_BUFF_TOO_SMALL if @a bin_buf_size is too small, 7658 * #MHD_SC_HASH_FAILED if hashing failed, 7659 * #MHD_SC_AUTH_DIGEST_ALGO_NOT_SUPPORTED if requested @a algo is 7660 * unknown or unsupported. 7661 * @sa #MHD_digest_auth_calc_userhash_hex() 7662 * @ingroup authentication 7663 */ 7664 MHD_EXTERN_ enum MHD_StatusCode 7665 MHD_digest_auth_calc_userhash (enum MHD_DigestAuthAlgo algo, 7666 const char *MHD_RESTRICT username, 7667 const char *MHD_RESTRICT realm, 7668 size_t bin_buf_size, 7669 void *MHD_RESTRICT userhash_bin) 7670 MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (2) 7671 MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_OUT_SIZE_ (5,4); 7672 7673 7674 /** 7675 * Calculate "userhash", return it as hexadecimal string. 7676 * 7677 * The "userhash" is the hash of the string "username:realm". 7678 * 7679 * The "userhash" could be used to avoid sending username in cleartext in Digest 7680 * Authorization client's header. 7681 * 7682 * Userhash is not designed to hide the username in local database or files, 7683 * as username in cleartext is required for #MHD_digest_auth_check() function 7684 * to check the response, but it can be used to hide username in HTTP headers. 7685 * 7686 * This function could be used when the new username is added to the username 7687 * database to save the "userhash" alongside with the username (preferably) or 7688 * when loading list of the usernames to generate the userhash for every loaded 7689 * username (this will cause delays at the start with the long lists). 7690 * 7691 * Once "userhash" is generated it could be used to identify users by clients 7692 * with "userhash" support. 7693 * Avoid repetitive usage of this function for the same username/realm 7694 * combination as it will cause excessive CPU load; save and reuse the result 7695 * instead. 7696 * 7697 * @param algo the algorithm for userhash calculations 7698 * @param username the username 7699 * @param realm the realm 7700 * @param hex_buf_size the size of the @a userhash_hex buffer, must be 7701 * at least #MHD_digest_get_hash_size()*2+1 chars long 7702 * @param[out] userhash_hex the output buffer for userhash as hex string; 7703 * if this function succeeds, then this buffer has 7704 * #MHD_digest_get_hash_size()*2 chars long 7705 * userhash string plus one zero-termination char 7706 * @return #MHD_SC_OK on success, 7707 * #MHD_SC_OUT_BUFF_TOO_SMALL if @a bin_buf_size is too small, 7708 * #MHD_SC_HASH_FAILED if hashing failed, 7709 * #MHD_SC_AUTH_DIGEST_ALGO_NOT_SUPPORTED if requested @a algo is 7710 * unknown or unsupported. 7711 * @sa #MHD_digest_auth_calc_userhash() 7712 * @ingroup authentication 7713 */ 7714 MHD_EXTERN_ enum MHD_StatusCode 7715 MHD_digest_auth_calc_userhash_hex ( 7716 enum MHD_DigestAuthAlgo algo, 7717 const char *MHD_RESTRICT username, 7718 const char *MHD_RESTRICT realm, 7719 size_t hex_buf_size, 7720 char userhash_hex[MHD_FN_PAR_DYN_ARR_SIZE_ (hex_buf_size)]) 7721 MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (2) 7722 MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_OUT_SIZE_ (5,4); 7723 7724 7725 /** 7726 * The type of username used by client in Digest Authorization header 7727 * 7728 * Values are sorted so simplified checks could be used. 7729 * For example: 7730 * * (value <= MHD_DIGEST_AUTH_UNAME_TYPE_INVALID) is true if no valid username 7731 * is provided by the client (not used currently) 7732 * * (value >= MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH) is true if username is 7733 * provided in any form 7734 * * (value >= MHD_DIGEST_AUTH_UNAME_TYPE_STANDARD) is true if username is 7735 * provided in clear text (no userhash matching is needed) 7736 */ 7737 enum MHD_FIXED_ENUM_MHD_SET_ MHD_DigestAuthUsernameType 7738 { 7739 /** 7740 * No username parameter is in Digest Authorization header. 7741 * Not used currently. Value #MHD_SC_REQ_AUTH_DATA_BROKEN is returned 7742 * by #MHD_request_get_info_dynamic_sz() if the request has no username. 7743 */ 7744 MHD_DIGEST_AUTH_UNAME_TYPE_MISSING = 0 7745 , 7746 /** 7747 * The 'username' parameter is used to specify the username. 7748 */ 7749 MHD_DIGEST_AUTH_UNAME_TYPE_STANDARD = (1u << 2) 7750 , 7751 /** 7752 * The username is specified by 'username*' parameter with 7753 * the extended notation (see RFC 5987, section-3.2.1). 7754 * The only difference between standard and extended types is 7755 * the way how username value is encoded in the header. 7756 */ 7757 MHD_DIGEST_AUTH_UNAME_TYPE_EXTENDED = (1u << 3) 7758 , 7759 /** 7760 * The username provided in form of 'userhash' as 7761 * specified by RFC 7616, section-3.4.4. 7762 * @sa #MHD_digest_auth_calc_userhash_hex(), #MHD_digest_auth_calc_userhash() 7763 */ 7764 MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH = (1u << 1) 7765 , 7766 /** 7767 * The invalid combination of username parameters are used by client. 7768 * Either: 7769 * + both 'username' and 'username*' are used 7770 * + 'username*' is used with 'userhash=true' 7771 * + 'username*' used with invalid extended notation 7772 * + 'username' is not hexadecimal string, while 'userhash' set to 'true' 7773 * Not used currently. Value #MHD_SC_REQ_AUTH_DATA_BROKEN is returned 7774 * by #MHD_request_get_info_dynamic_sz() if the request has broken username. 7775 */ 7776 MHD_DIGEST_AUTH_UNAME_TYPE_INVALID = (1u << 0) 7777 }; 7778 7779 /** 7780 * The QOP ('quality of protection') types. 7781 */ 7782 enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_DigestAuthQOP 7783 { 7784 /** 7785 * Invalid/unknown QOP. 7786 * Used in struct MHD_AuthDigestInfo to indicate client value that 7787 * cannot by identified. 7788 */ 7789 MHD_DIGEST_AUTH_QOP_INVALID = 0 7790 , 7791 /** 7792 * No QOP parameter. 7793 * As described in old RFC 2069 original specification. 7794 * This mode is not allowed by latest RFCs and should be used only to 7795 * communicate with clients that do not support more modern modes (with QOP 7796 * parameter). 7797 * This mode is less secure than other modes and inefficient. 7798 */ 7799 MHD_DIGEST_AUTH_QOP_NONE = (1u << 0) 7800 , 7801 /** 7802 * The 'auth' QOP type. 7803 */ 7804 MHD_DIGEST_AUTH_QOP_AUTH = (1u << 1) 7805 , 7806 /** 7807 * The 'auth-int' QOP type. 7808 * Not supported by MHD for authentication. 7809 */ 7810 MHD_DIGEST_AUTH_QOP_AUTH_INT = (1u << 2) 7811 }; 7812 7813 /** 7814 * The QOP ('quality of protection') types, multiple selection. 7815 * 7816 * #MHD_DigestAuthQOP always can be casted to #MHD_DigestAuthMultiQOP, but 7817 * not vice versa. 7818 */ 7819 enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_DigestAuthMultiQOP 7820 { 7821 /** 7822 * Invalid/unknown QOP. 7823 */ 7824 MHD_DIGEST_AUTH_MULT_QOP_INVALID = MHD_DIGEST_AUTH_QOP_INVALID 7825 , 7826 /** 7827 * No QOP parameter. 7828 * As described in old RFC 2069 original specification. 7829 * This mode is not allowed by latest RFCs and should be used only to 7830 * communicate with clients that do not support more modern modes (with QOP 7831 * parameter). 7832 * This mode is less secure than other modes and inefficient. 7833 */ 7834 MHD_DIGEST_AUTH_MULT_QOP_NONE = MHD_DIGEST_AUTH_QOP_NONE 7835 , 7836 /** 7837 * The 'auth' QOP type. 7838 */ 7839 MHD_DIGEST_AUTH_MULT_QOP_AUTH = MHD_DIGEST_AUTH_QOP_AUTH 7840 , 7841 /** 7842 * The 'auth-int' QOP type. 7843 * Not supported by MHD. 7844 * Reserved value. 7845 */ 7846 MHD_DIGEST_AUTH_MULT_QOP_AUTH_INT = MHD_DIGEST_AUTH_QOP_AUTH_INT 7847 , 7848 /** 7849 * The 'auth' QOP type OR the old RFC2069 (no QOP) type. 7850 * In other words: any types except 'auth-int'. 7851 * RFC2069-compatible mode is allowed, thus this value should be used only 7852 * when it is really necessary. 7853 */ 7854 MHD_DIGEST_AUTH_MULT_QOP_ANY_NON_INT = 7855 MHD_DIGEST_AUTH_QOP_NONE | MHD_DIGEST_AUTH_QOP_AUTH 7856 , 7857 /** 7858 * Any 'auth' QOP type ('auth' or 'auth-int'). 7859 * Currently supported as 'auth' QOP type only. 7860 */ 7861 MHD_DIGEST_AUTH_MULT_QOP_AUTH_ANY = 7862 MHD_DIGEST_AUTH_QOP_AUTH | MHD_DIGEST_AUTH_QOP_AUTH_INT 7863 }; 7864 7865 /** 7866 * The type of 'nc' (nonce count) value provided in the request 7867 */ 7868 enum MHD_FIXED_ENUM_MHD_SET_ MHD_DigestAuthNC 7869 { 7870 /** 7871 * Readable hexdecimal non-zero number. 7872 * The decoded value is placed in @a nc member of struct MHD_AuthDigestInfo 7873 */ 7874 MHD_DIGEST_AUTH_NC_NUMBER = 1 7875 , 7876 /** 7877 * Readable zero number. 7878 * Compliant clients should not use such values. 7879 * Can be treated as invalid request. 7880 */ 7881 MHD_DIGEST_AUTH_NC_ZERO = 2 7882 , 7883 /** 7884 * 'nc' value is not provided by the client. 7885 * Unless old RFC 2069 mode is allowed, this should be treated as invalid 7886 * request. 7887 */ 7888 MHD_DIGEST_AUTH_NC_NONE = 3 7889 , 7890 /** 7891 * 'nc' value is too long to be decoded. 7892 * Compliant clients should not use such values. 7893 * Can be treated as invalid request. 7894 */ 7895 MHD_DIGEST_AUTH_NC_TOO_LONG = 4 7896 , 7897 /** 7898 * 'nc' value is too large for uint32_t. 7899 * Compliant clients should not use such values. 7900 * Can be treated as request with a stale nonce or as invalid request. 7901 */ 7902 MHD_DIGEST_AUTH_NC_TOO_LARGE = 5 7903 }; 7904 7905 7906 /** 7907 * Information from Digest Authorization client's header. 7908 * 7909 * @see #MHD_REQUEST_INFO_DYNAMIC_AUTH_DIGEST_INFO 7910 */ 7911 struct MHD_AuthDigestInfo 7912 { 7913 /** 7914 * The algorithm as defined by client. 7915 * Set automatically to MD5 if not specified by client. 7916 */ 7917 enum MHD_DigestAuthAlgo algo; 7918 7919 /** 7920 * The type of username used by client. 7921 */ 7922 enum MHD_DigestAuthUsernameType uname_type; 7923 7924 /** 7925 * The username string. 7926 * Used only if username type is standard or extended, always NULL otherwise. 7927 * If extended notation is used, this string is pct-decoded string 7928 * with charset and language tag removed (i.e. it is original username 7929 * extracted from the extended notation). 7930 * When userhash is used by the client, the string pointer is NULL and 7931 * @a userhash_hex and @a userhash_bin are set. 7932 */ 7933 struct MHD_StringNullable username; 7934 7935 /** 7936 * The userhash string. 7937 * Valid only if username type is userhash. 7938 * This is unqoted string without decoding of the hexadecimal 7939 * digits (as provided by the client). 7940 * @sa #MHD_digest_auth_calc_userhash_hex() 7941 */ 7942 struct MHD_StringNullable userhash_hex; 7943 7944 /** 7945 * The userhash decoded to binary form. 7946 * Used only if username type is userhash, always NULL otherwise. 7947 * When not NULL, this points to binary sequence @a userhash_bin_size bytes 7948 * long. 7949 * The valid size should be #MHD_digest_get_hash_size() bytes. 7950 * @warning This is a binary data, no zero termination. 7951 * @warning To avoid buffer overruns, always check the size of the data before 7952 * use, because @a userhash_bin can point even to zero-sized 7953 * data. 7954 * @sa #MHD_digest_auth_calc_userhash() 7955 */ 7956 const uint8_t *userhash_bin; 7957 7958 /** 7959 * The size of the data pointed by @a userhash_bin. 7960 * Always zero when @a userhash_bin is NULL. 7961 */ 7962 size_t userhash_bin_size; 7963 7964 /** 7965 * The 'opaque' parameter value, as specified by client. 7966 * If not specified by client then string pointer is NULL. 7967 */ 7968 struct MHD_StringNullable opaque; 7969 7970 /** 7971 * The 'realm' parameter value, as specified by client. 7972 * If not specified by client then string pointer is NULL. 7973 */ 7974 struct MHD_StringNullable realm; 7975 7976 /** 7977 * The 'qop' parameter value. 7978 */ 7979 enum MHD_DigestAuthQOP qop; 7980 7981 /** 7982 * The length of the 'cnonce' parameter value, including possible 7983 * backslash-escape characters. 7984 * 'cnonce' is used in hash calculation, which is CPU-intensive procedure. 7985 * An application may want to reject too large cnonces to limit the CPU load. 7986 * A few kilobytes is a reasonable limit, typically cnonce is just 32-160 7987 * characters long. 7988 */ 7989 size_t cnonce_len; 7990 7991 /** 7992 * The type of 'nc' (nonce count) value provided in the request. 7993 */ 7994 enum MHD_DigestAuthNC nc_type; 7995 7996 /** 7997 * The nc (nonce count) parameter value. 7998 * Can be used by application to limit the number of nonce re-uses. If @a nc 7999 * is higher than application wants to allow, then "auth required" response 8000 * with 'stale=true' could be used to force client to retry with the fresh 8001 * 'nonce'. 8002 * Set to zero when @a nc_type is not set to #MHD_DIGEST_AUTH_NC_NUMBER. 8003 */ 8004 uint_fast32_t nc; 8005 }; 8006 8007 /** 8008 * The result of digest authentication of the client. 8009 * 8010 * All error values are zero or negative. 8011 */ 8012 enum MHD_FIXED_ENUM_MHD_SET_ MHD_DigestAuthResult 8013 { 8014 /** 8015 * Authentication OK. 8016 */ 8017 MHD_DAUTH_OK = 1 8018 , 8019 /** 8020 * General error, like "out of memory". 8021 * Authentication may be valid, but cannot be checked. 8022 */ 8023 MHD_DAUTH_ERROR = 0 8024 , 8025 /** 8026 * No "Authorization" header for Digest Authentication. 8027 */ 8028 MHD_DAUTH_HEADER_MISSING = -1 8029 , 8030 /** 8031 * Wrong format of the header. 8032 * Also returned if required parameters in Authorization header are missing 8033 * or broken (in invalid format). 8034 */ 8035 MHD_DAUTH_HEADER_BROKEN = -9 8036 , 8037 /** 8038 * Unsupported algorithm. 8039 */ 8040 MHD_DAUTH_UNSUPPORTED_ALGO = -10 8041 , 8042 /** 8043 * Unsupported 'qop'. 8044 */ 8045 MHD_DAUTH_UNSUPPORTED_QOP = -11 8046 , 8047 /** 8048 * Incorrect userdigest size. 8049 */ 8050 MHD_DAUTH_INVALID_USERDIGEST_SIZE = -15 8051 , 8052 /** 8053 * Wrong 'username'. 8054 */ 8055 MHD_DAUTH_WRONG_USERNAME = -17 8056 , 8057 /** 8058 * Wrong 'realm'. 8059 */ 8060 MHD_DAUTH_WRONG_REALM = -18 8061 , 8062 /** 8063 * Wrong 'URI' (or URI parameters). 8064 */ 8065 MHD_DAUTH_WRONG_URI = -19 8066 , 8067 /** 8068 * Wrong 'qop'. 8069 */ 8070 MHD_DAUTH_WRONG_QOP = -20 8071 , 8072 /** 8073 * Wrong 'algorithm'. 8074 */ 8075 MHD_DAUTH_WRONG_ALGO = -21 8076 , 8077 /** 8078 * Too large (>64 KiB) Authorization parameter value. 8079 */ 8080 MHD_DAUTH_TOO_LARGE = -22 8081 , 8082 /* The different form of naming is intentionally used for the results below, 8083 * as they are more important */ 8084 8085 /** 8086 * The 'nonce' is too old. Suggest the client to retry with the same 8087 * username and password to get the fresh 'nonce'. 8088 * The validity of the 'nonce' may be not checked. 8089 */ 8090 MHD_DAUTH_NONCE_STALE = -25 8091 , 8092 /** 8093 * The 'nonce' is wrong. May indicate an attack attempt. 8094 */ 8095 MHD_DAUTH_NONCE_WRONG = -33 8096 , 8097 /** 8098 * The 'response' is wrong. May indicate a wrong password used or 8099 * an attack attempt. 8100 */ 8101 MHD_DAUTH_RESPONSE_WRONG = -34 8102 }; 8103 8104 8105 /** 8106 * Authenticates the authorization header sent by the client. 8107 * 8108 * If RFC2069 mode is allowed by setting bit #MHD_DIGEST_AUTH_QOP_NONE in 8109 * @a mqop and the client uses this mode, then server generated nonces are 8110 * used as one-time nonces because nonce-count is not supported in this old RFC. 8111 * Communication in this mode is very inefficient, especially if the client 8112 * requests several resources one-by-one as for every request a new nonce must 8113 * be generated and client repeats all requests twice (first time to get a new 8114 * nonce and second time to perform an authorised request). 8115 * 8116 * @param request the request 8117 * @param realm the realm for authorization of the client 8118 * @param username the username to be authenticated, must be in clear text 8119 * even if userhash is used by the client 8120 * @param password the password matching the @a username (and the @a realm) 8121 * @param max_nc the maximum allowed nc (Nonce Count) value, if client's nc 8122 * exceeds the specified value then MHD_DAUTH_NONCE_STALE is 8123 * returned; 8124 * if zero is specified then daemon default value is used. 8125 * @param mqop the QOP to use 8126 * @param malgo digest algorithms allowed to use, fail if algorithm used 8127 * by the client is not allowed by this parameter 8128 * @return #MHD_DAUTH_OK if authenticated, 8129 * the error code otherwise 8130 * @ingroup authentication 8131 */ 8132 MHD_EXTERN_ enum MHD_DigestAuthResult 8133 MHD_digest_auth_check (struct MHD_Request *MHD_RESTRICT request, 8134 const char *MHD_RESTRICT realm, 8135 const char *MHD_RESTRICT username, 8136 const char *MHD_RESTRICT password, 8137 uint_fast32_t max_nc, 8138 enum MHD_DigestAuthMultiQOP mqop, 8139 enum MHD_DigestAuthMultiAlgo malgo) 8140 MHD_FN_PAR_NONNULL_ALL_ 8141 MHD_FN_PAR_CSTR_ (2) MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_CSTR_ (4); 8142 8143 8144 /** 8145 * Calculate userdigest, return it as a binary data. 8146 * 8147 * The "userdigest" is the hash of the "username:realm:password" string. 8148 * 8149 * The "userdigest" can be used to avoid storing the password in clear text 8150 * in database/files 8151 * 8152 * This function is designed to improve security of stored credentials, 8153 * the "userdigest" does not improve security of the authentication process. 8154 * 8155 * The results can be used to store username & userdigest pairs instead of 8156 * username & password pairs. To further improve security, application may 8157 * store username & userhash & userdigest triplets. 8158 * 8159 * @param algo the digest algorithm 8160 * @param username the username 8161 * @param realm the realm 8162 * @param password the password 8163 * @param bin_buf_size the size of the @a userdigest_bin buffer, must be 8164 * at least #MHD_digest_get_hash_size() bytes long 8165 * @param[out] userdigest_bin the output buffer for userdigest; 8166 * if this function succeeds, then this buffer has 8167 * #MHD_digest_get_hash_size() bytes of 8168 * userdigest upon return 8169 * @return #MHD_SC_OK on success, 8170 * #MHD_SC_OUT_BUFF_TOO_SMALL if @a bin_buf_size is too small, 8171 * #MHD_SC_HASH_FAILED if hashing failed, 8172 * #MHD_SC_AUTH_DIGEST_ALGO_NOT_SUPPORTED if requested @a algo is 8173 * unknown or unsupported. 8174 * @sa #MHD_digest_auth_check_digest() 8175 * @ingroup authentication 8176 */ 8177 MHD_EXTERN_ enum MHD_StatusCode 8178 MHD_digest_auth_calc_userdigest (enum MHD_DigestAuthAlgo algo, 8179 const char *MHD_RESTRICT username, 8180 const char *MHD_RESTRICT realm, 8181 const char *MHD_RESTRICT password, 8182 size_t bin_buf_size, 8183 void *MHD_RESTRICT userdigest_bin) 8184 MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ 8185 MHD_FN_PAR_CSTR_ (2) 8186 MHD_FN_PAR_CSTR_ (3) 8187 MHD_FN_PAR_CSTR_ (4) 8188 MHD_FN_PAR_OUT_SIZE_ (6,5); 8189 8190 8191 /** 8192 * Authenticates the authorization header sent by the client by using 8193 * hash of "username:realm:password". 8194 * 8195 * If RFC2069 mode is allowed by setting bit #MHD_DIGEST_AUTH_QOP_NONE in 8196 * @a mqop and the client uses this mode, then server generated nonces are 8197 * used as one-time nonces because nonce-count is not supported in this old RFC. 8198 * Communication in this mode is very inefficient, especially if the client 8199 * requests several resources one-by-one as for every request a new nonce must 8200 * be generated and client repeats all requests twice (first time to get a new 8201 * nonce and second time to perform an authorised request). 8202 * 8203 * @param request the request 8204 * @param realm the realm for authorization of the client 8205 * @param username the username to be authenticated, must be in clear text 8206 * even if userhash is used by the client 8207 * @param userdigest_size the size of the @a userdigest in bytes, must match the 8208 * hashing algorithm (see #MHD_MD5_DIGEST_SIZE, 8209 * #MHD_SHA256_DIGEST_SIZE, #MHD_SHA512_256_DIGEST_SIZE, 8210 * #MHD_digest_get_hash_size()) 8211 * @param userdigest the precalculated binary hash of the string 8212 * "username:realm:password", 8213 * see #MHD_digest_auth_calc_userdigest() 8214 * @param max_nc the maximum allowed nc (Nonce Count) value, if client's nc 8215 * exceeds the specified value then MHD_DAUTH_NONCE_STALE is 8216 * returned; 8217 * if zero is specified then daemon default value is used. 8218 * @param mqop the QOP to use 8219 * @param malgo digest algorithms allowed to use, fail if algorithm used 8220 * by the client is not allowed by this parameter; 8221 * more than one base algorithms (MD5, SHA-256, SHA-512/256) 8222 * cannot be used at the same time for this function 8223 * as @a userdigest must match specified algorithm 8224 * @return #MHD_DAUTH_OK if authenticated, 8225 * the error code otherwise 8226 * @sa #MHD_digest_auth_calc_userdigest() 8227 * @ingroup authentication 8228 */ 8229 MHD_EXTERN_ enum MHD_DigestAuthResult 8230 MHD_digest_auth_check_digest (struct MHD_Request *MHD_RESTRICT request, 8231 const char *MHD_RESTRICT realm, 8232 const char *MHD_RESTRICT username, 8233 size_t userdigest_size, 8234 const void *MHD_RESTRICT userdigest, 8235 uint_fast32_t max_nc, 8236 enum MHD_DigestAuthMultiQOP mqop, 8237 enum MHD_DigestAuthMultiAlgo malgo) 8238 MHD_FN_PAR_NONNULL_ALL_ 8239 MHD_FN_PAR_CSTR_ (2) 8240 MHD_FN_PAR_CSTR_ (3) 8241 MHD_FN_PAR_IN_SIZE_ (5, 4); 8242 8243 8244 /** 8245 * Add Digest Authentication "challenge" to the response. 8246 * 8247 * The response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code. 8248 * 8249 * If @a mqop allows both RFC 2069 (#MHD_DIGEST_AUTH_QOP_NONE) and other QOP 8250 * values, then the "challenge" is formed like if MHD_DIGEST_AUTH_QOP_NONE bit 8251 * was not set, because such "challenge" should be backward-compatible with 8252 * RFC 2069. 8253 * 8254 * If @a mqop allows only MHD_DIGEST_AUTH_MULT_QOP_NONE, then the response is 8255 * formed in strict accordance with RFC 2069 (no 'qop', no 'userhash', no 8256 * 'charset'). For better compatibility with clients, it is recommended (but 8257 * not required) to set @a domain to NULL in this mode. 8258 * 8259 * New nonces are generated each time when the resulting response is used. 8260 * 8261 * See RFC 7616, section 3.3 for details. 8262 * 8263 * @param response the response to update; should contain the "access denied" 8264 * body; 8265 * note: this function sets the "WWW Authenticate" header and 8266 * the caller should not set this header; 8267 * the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status 8268 * code; 8269 * the NULL is tolerated (the result is 8270 * #MHD_SC_RESP_POINTER_NULL) 8271 * @param realm the realm presented to the client 8272 * @param opaque the string for opaque value, can be NULL, but NULL is 8273 * not recommended for better compatibility with clients; 8274 * the recommended format is hex or Base64 encoded string 8275 * @param domain the optional space-separated list of URIs for which the 8276 * same authorisation could be used, URIs can be in form 8277 * "path-absolute" (the path for the same host with initial slash) 8278 * or in form "absolute-URI" (the full path with protocol), in 8279 * any case client may assume that URI is in the same "protection 8280 * space" if it starts with any of values specified here; 8281 * could be NULL (clients typically assume that the same 8282 * credentials could be used for any URI on the same host); 8283 * this list provides information for the client only and does 8284 * not actually restrict anything on the server side 8285 * @param indicate_stale if set to #MHD_YES then indication of stale nonce used 8286 * in the client's request is indicated by adding 8287 * 'stale=true' to the authentication header, this 8288 * instructs the client to retry immediately with the new 8289 * nonce and the same credentials, without asking user 8290 * for the new password 8291 * @param mqop the QOP to use 8292 * @param malgo digest algorithm to use; if several algorithms are allowed 8293 * then one challenge for each allowed algorithm is added 8294 * @param userhash_support if set to #MHD_YES then support of userhash is 8295 * indicated, allowing client to provide 8296 * hash("username:realm") instead of the username in 8297 * clear text; 8298 * note that clients are allowed to provide the username 8299 * in cleartext even if this parameter set to non-zero; 8300 * when userhash is used, application must be ready to 8301 * identify users by provided userhash value instead of 8302 * username; see #MHD_digest_auth_calc_userhash() and 8303 * #MHD_digest_auth_calc_userhash_hex() 8304 * @param prefer_utf8 if not set to #MHD_NO, parameter 'charset=UTF-8' is 8305 * added, indicating for the client that UTF-8 encoding for 8306 * the username is preferred 8307 * @return #MHD_SC_OK if succeed, 8308 * #MHD_SC_TOO_LATE if the response has been already "frozen" (used to 8309 * create an action), 8310 * #MHD_SC_RESP_HEADERS_CONFLICT if Digest Authentication "challenge" 8311 * has been added already, 8312 * #MHD_SC_RESP_POINTER_NULL if @a response is NULL, 8313 * #MHD_SC_RESP_HTTP_CODE_NOT_SUITABLE is response status code is wrong, 8314 * #MHD_SC_RESP_HEADER_VALUE_INVALID if @a realm, @a opaque or @a domain 8315 * have wrong characters or zero length (for @a realm), 8316 * #MHD_SC_RESP_HEADER_MEM_ALLOC_FAILED if memory allocation failed, 8317 * or other error code if failed 8318 * @ingroup authentication 8319 */ 8320 MHD_EXTERN_ enum MHD_StatusCode 8321 MHD_response_add_auth_digest_challenge ( 8322 struct MHD_Response *MHD_RESTRICT response, 8323 const char *MHD_RESTRICT realm, 8324 const char *MHD_RESTRICT opaque, 8325 const char *MHD_RESTRICT domain, 8326 enum MHD_Bool indicate_stale, 8327 enum MHD_DigestAuthMultiQOP mqop, 8328 enum MHD_DigestAuthMultiAlgo malgo, 8329 enum MHD_Bool userhash_support, 8330 enum MHD_Bool prefer_utf8) 8331 MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2) 8332 MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_CSTR_ (4); 8333 8334 8335 /* Application may define MHD_NO_STATIC_INLINE macro before including 8336 libmicrohttpd headers to disable static inline functions in the headers. */ 8337 #ifndef MHD_NO_STATIC_INLINE 8338 8339 /** 8340 * Create action to reply with Digest Authentication "challenge". 8341 * 8342 * The @a response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code. 8343 * 8344 * See RFC 7616, section 3.3 for details. 8345 * 8346 * @param request the request to create the action for 8347 * @param realm the realm presented to the client 8348 * @param opaque the string for opaque value, can be NULL, but NULL is 8349 * not recommended for better compatibility with clients; 8350 * the recommended format is hex or Base64 encoded string 8351 * @param domain the optional space-separated list of URIs for which the 8352 * same authorisation could be used, URIs can be in form 8353 * "path-absolute" (the path for the same host with initial slash) 8354 * or in form "absolute-URI" (the full path with protocol), in 8355 * any case client may assume that URI is in the same "protection 8356 * space" if it starts with any of values specified here; 8357 * could be NULL (clients typically assume that the same 8358 * credentials could be used for any URI on the same host); 8359 * this list provides information for the client only and does 8360 * not actually restrict anything on the server side 8361 * @param indicate_stale if set to #MHD_YES then indication of stale nonce used 8362 * in the client's request is indicated by adding 8363 * 'stale=true' to the authentication header, this 8364 * instructs the client to retry immediately with the new 8365 * nonce and the same credentials, without asking user 8366 * for the new password 8367 * @param mqop the QOP to use 8368 * @param malgo digest algorithm to use; if several algorithms are allowed 8369 * then one challenge for each allowed algorithm is added 8370 * @param userhash_support if set to #MHD_YES then support of userhash is 8371 * indicated, allowing client to provide 8372 * hash("username:realm") instead of the username in 8373 * clear text; 8374 * note that clients are allowed to provide the username 8375 * in cleartext even if this parameter set to non-zero; 8376 * when userhash is used, application must be ready to 8377 * identify users by provided userhash value instead of 8378 * username; see #MHD_digest_auth_calc_userhash() and 8379 * #MHD_digest_auth_calc_userhash_hex() 8380 * @param prefer_utf8 if not set to #MHD_NO, parameter 'charset=UTF-8' is 8381 * added, indicating for the client that UTF-8 encoding for 8382 * the username is preferred 8383 * @param response the response to update; should contain the "access denied" 8384 * body; 8385 * note: this function sets the "WWW Authenticate" header and 8386 * the caller should not set this header; 8387 * the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status 8388 * code; 8389 * the NULL is tolerated (the result is 8390 * #MHD_SC_RESP_POINTER_NULL) 8391 * @param abort_if_failed if set to #MHD_NO the response will be used even if 8392 * failed to add Basic Authentication "challenge", 8393 * if not set to #MHD_NO the request will be aborted 8394 * if the "challenge" could not be added. 8395 * @return pointer to the action, the action must be consumed 8396 * otherwise response object may leak; 8397 * NULL if failed or if any action has been already created for 8398 * the @a request; 8399 * when failed the response object is consumed and need not 8400 * to be "destroyed" 8401 * @ingroup authentication 8402 */ 8403 MHD_STATIC_INLINE_ 8404 MHD_FN_PAR_NONNULL_ (1) 8405 MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2) 8406 const struct MHD_Action * 8407 MHD_action_digest_auth_challenge (struct MHD_Request *MHD_RESTRICT request, 8408 const char *MHD_RESTRICT realm, 8409 const char *MHD_RESTRICT opaque, 8410 const char *MHD_RESTRICT domain, 8411 enum MHD_Bool indicate_stale, 8412 enum MHD_DigestAuthMultiQOP mqop, 8413 enum MHD_DigestAuthMultiAlgo malgo, 8414 enum MHD_Bool userhash_support, 8415 enum MHD_Bool prefer_utf8, 8416 struct MHD_Response *MHD_RESTRICT response, 8417 enum MHD_Bool abort_if_failed) 8418 { 8419 if ((MHD_SC_OK != 8420 MHD_response_add_auth_digest_challenge (response, realm, opaque, domain, 8421 indicate_stale, mqop, malgo, 8422 userhash_support, prefer_utf8)) 8423 && (MHD_NO != abort_if_failed)) 8424 { 8425 MHD_response_destroy (response); 8426 return MHD_action_abort_request (request); 8427 } 8428 return MHD_action_from_response (request, response); 8429 } 8430 8431 8432 MHD_STATIC_INLINE_END_ 8433 8434 /** 8435 * Create action to reply with Digest Authentication "challenge". 8436 * 8437 * The @a response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code. 8438 * 8439 * If the @a response object cannot be extended with the "challenge", 8440 * the @a response is used to reply without the "challenge". 8441 * 8442 * @param request the request to create the action for 8443 * @param realm the realm presented to the client 8444 * @param opaque the string for opaque value, can be NULL, but NULL is 8445 * not recommended for better compatibility with clients; 8446 * the recommended format is hex or Base64 encoded string 8447 * @param domain the optional space-separated list of URIs for which the 8448 * same authorisation could be used, URIs can be in form 8449 * "path-absolute" (the path for the same host with initial slash) 8450 * or in form "absolute-URI" (the full path with protocol), in 8451 * any case client may assume that URI is in the same "protection 8452 * space" if it starts with any of values specified here; 8453 * could be NULL (clients typically assume that the same 8454 * credentials could be used for any URI on the same host); 8455 * this list provides information for the client only and does 8456 * not actually restrict anything on the server side 8457 * @param indicate_stale if set to #MHD_YES then indication of stale nonce used 8458 * in the client's request is indicated by adding 8459 * 'stale=true' to the authentication header, this 8460 * instructs the client to retry immediately with the new 8461 * nonce and the same credentials, without asking user 8462 * for the new password 8463 * @param mqop the QOP to use 8464 * @param algo digest algorithm to use; if several algorithms are allowed 8465 * then one challenge for each allowed algorithm is added 8466 * @param userhash_support if set to #MHD_YES then support of userhash is 8467 * indicated, allowing client to provide 8468 * hash("username:realm") instead of the username in 8469 * clear text; 8470 * note that clients are allowed to provide the username 8471 * in cleartext even if this parameter set to non-zero; 8472 * when userhash is used, application must be ready to 8473 * identify users by provided userhash value instead of 8474 * username; see #MHD_digest_auth_calc_userhash() and 8475 * #MHD_digest_auth_calc_userhash_hex() 8476 * @param prefer_utf8 if not set to #MHD_NO, parameter 'charset=UTF-8' is 8477 * added, indicating for the client that UTF-8 encoding for 8478 * the username is preferred 8479 * @param response the response to update; should contain the "access denied" 8480 * body; 8481 * note: this function sets the "WWW Authenticate" header and 8482 * the caller should not set this header; 8483 * the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status 8484 * code; 8485 * the NULL is tolerated (the result is 8486 * #MHD_SC_RESP_POINTER_NULL) 8487 * @return pointer to the action, the action must be consumed 8488 * otherwise response object may leak; 8489 * NULL if failed or if any action has been already created for 8490 * the @a request; 8491 * when failed the response object is consumed and need not 8492 * to be "destroyed" 8493 * @ingroup authentication 8494 */ 8495 #define MHD_action_digest_auth_challenge_p(rq,rlm,opq,dmn,stl,mqop,malgo, \ 8496 uh,utf,resp) \ 8497 MHD_action_digest_auth_challenge ((rq),(rlm),(opq),(dmn),(stl),(mqop), \ 8498 (malgo),(uh),(utf),(resp),MHD_NO) 8499 8500 8501 /** 8502 * Create action to reply with Digest Authentication "challenge". 8503 * 8504 * The @a response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code. 8505 * 8506 * If the @a response object cannot be extended with the "challenge", 8507 * the @a response is aborted. 8508 * 8509 * @param request the request to create the action for 8510 * @param realm the realm presented to the client 8511 * @param opaque the string for opaque value, can be NULL, but NULL is 8512 * not recommended for better compatibility with clients; 8513 * the recommended format is hex or Base64 encoded string 8514 * @param domain the optional space-separated list of URIs for which the 8515 * same authorisation could be used, URIs can be in form 8516 * "path-absolute" (the path for the same host with initial slash) 8517 * or in form "absolute-URI" (the full path with protocol), in 8518 * any case client may assume that URI is in the same "protection 8519 * space" if it starts with any of values specified here; 8520 * could be NULL (clients typically assume that the same 8521 * credentials could be used for any URI on the same host); 8522 * this list provides information for the client only and does 8523 * not actually restrict anything on the server side 8524 * @param indicate_stale if set to #MHD_YES then indication of stale nonce used 8525 * in the client's request is indicated by adding 8526 * 'stale=true' to the authentication header, this 8527 * instructs the client to retry immediately with the new 8528 * nonce and the same credentials, without asking user 8529 * for the new password 8530 * @param mqop the QOP to use 8531 * @param algo digest algorithm to use; if several algorithms are allowed 8532 * then one challenge for each allowed algorithm is added 8533 * @param userhash_support if set to #MHD_YES then support of userhash is 8534 * indicated, allowing client to provide 8535 * hash("username:realm") instead of the username in 8536 * clear text; 8537 * note that clients are allowed to provide the username 8538 * in cleartext even if this parameter set to non-zero; 8539 * when userhash is used, application must be ready to 8540 * identify users by provided userhash value instead of 8541 * username; see #MHD_digest_auth_calc_userhash() and 8542 * #MHD_digest_auth_calc_userhash_hex() 8543 * @param prefer_utf8 if not set to #MHD_NO, parameter 'charset=UTF-8' is 8544 * added, indicating for the client that UTF-8 encoding for 8545 * the username is preferred 8546 * @param response the response to update; should contain the "access denied" 8547 * body; 8548 * note: this function sets the "WWW Authenticate" header and 8549 * the caller should not set this header; 8550 * the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status 8551 * code; 8552 * the NULL is tolerated (the result is 8553 * #MHD_SC_RESP_POINTER_NULL) 8554 * @return pointer to the action, the action must be consumed 8555 * otherwise response object may leak; 8556 * NULL if failed or if any action has been already created for 8557 * the @a request; 8558 * when failed the response object is consumed and need not 8559 * to be "destroyed" 8560 * @ingroup authentication 8561 */ 8562 #define MHD_action_digest_auth_challenge_a(rq,rlm,opq,dmn,stl,mqop,malgo, \ 8563 uh,utf,resp) \ 8564 MHD_action_digest_auth_challenge ((rq),(rlm),(opq),(dmn),(stl),(mqop), \ 8565 (malgo),(uh),(utf),(resp),MHD_YES) 8566 8567 #endif /* ! MHD_NO_STATIC_INLINE */ 8568 8569 8570 /** 8571 * Add Basic Authentication "challenge" to the response. 8572 * 8573 * The response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code. 8574 * 8575 * If access to any resource should be limited to specific users, authenticated 8576 * by Basic Authentication mechanism, and the request for this resource does not 8577 * have Basic Authentication information (see #MHD_AuthBasicCreds), then response 8578 * with Basic Authentication "challenge" should be sent. This works as 8579 * an indication that Basic Authentication should be used for the access. 8580 * 8581 * See RFC 7617, section-2 for details. 8582 * 8583 * @param response the reply to send; should contain the "access denied" 8584 * body; 8585 * note: this function sets the "WWW Authenticate" header and 8586 * the caller should not set this header; 8587 * the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status 8588 * code; 8589 * the NULL is tolerated (the result is 8590 * #MHD_SC_RESP_POINTER_NULL) 8591 * @param realm the realm presented to the client 8592 * @param prefer_utf8 if not set to #MHD_NO, parameter'charset="UTF-8"' will 8593 * be added, indicating for client that UTF-8 encoding 8594 * is preferred 8595 * @return #MHD_SC_OK if succeed, 8596 * #MHD_SC_TOO_LATE if the response has been already "frozen" (used to 8597 * create an action), 8598 * #MHD_SC_RESP_HEADERS_CONFLICT if Basic Authentication "challenge" 8599 * has been added already, 8600 * #MHD_SC_RESP_POINTER_NULL if @a response is NULL, 8601 * #MHD_SC_RESP_HTTP_CODE_NOT_SUITABLE is response status code is wrong, 8602 * #MHD_SC_RESP_HEADER_VALUE_INVALID if realm is zero-length or has CR 8603 * or LF characters, 8604 * #MHD_SC_RESP_HEADER_MEM_ALLOC_FAILED if memory allocation failed, 8605 * or other error code if failed 8606 * @ingroup authentication 8607 */ 8608 MHD_EXTERN_ enum MHD_StatusCode 8609 MHD_response_add_auth_basic_challenge ( 8610 struct MHD_Response *MHD_RESTRICT response, 8611 const char *MHD_RESTRICT realm, 8612 enum MHD_Bool prefer_utf8) 8613 MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2); 8614 8615 /* Application may define MHD_NO_STATIC_INLINE macro before including 8616 libmicrohttpd headers to disable static inline functions in the headers. */ 8617 #ifndef MHD_NO_STATIC_INLINE 8618 8619 /** 8620 * Create action to reply with Basic Authentication "challenge". 8621 * 8622 * The @a response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code. 8623 * 8624 * If access to any resource should be limited to specific users, authenticated 8625 * by Basic Authentication mechanism, and the request for this resource does not 8626 * have Basic Authentication information (see #MHD_AuthBasicCreds), then response 8627 * with Basic Authentication "challenge" should be sent. This works as 8628 * an indication that Basic Authentication should be used for the access. 8629 * 8630 * See RFC 7617, section-2 for details. 8631 * 8632 * @param request the request to create the action for 8633 * @param realm the realm presented to the client 8634 * @param prefer_utf8 if not set to #MHD_NO, parameter'charset="UTF-8"' will 8635 * be added, indicating for client that UTF-8 encoding 8636 * is preferred 8637 * @param response the reply to send; should contain the "access denied" 8638 * body; 8639 * note: this function adds the "WWW Authenticate" header in 8640 * the response and the caller should not set this header; 8641 * the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status 8642 * code; 8643 * the NULL is tolerated (the result is 8644 * #MHD_action_abort_request()) 8645 * @param abort_if_failed if set to #MHD_NO the response will be used even if 8646 * failed to add Basic Authentication "challenge", 8647 * if not set to #MHD_NO the request will be aborted 8648 * if the "challenge" could not be added. 8649 * @return pointer to the action, the action must be consumed 8650 * otherwise response object may leak; 8651 * NULL if failed or if any action has been already created for 8652 * the @a request; 8653 * when failed the response object is consumed and need not 8654 * to be "destroyed" 8655 * @ingroup authentication 8656 */ 8657 MHD_STATIC_INLINE_ 8658 MHD_FN_PAR_NONNULL_ (1) 8659 MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2) 8660 const struct MHD_Action * 8661 MHD_action_basic_auth_challenge (struct MHD_Request *MHD_RESTRICT request, 8662 const char *MHD_RESTRICT realm, 8663 enum MHD_Bool prefer_utf8, 8664 struct MHD_Response *MHD_RESTRICT response, 8665 enum MHD_Bool abort_if_failed) 8666 { 8667 if ((MHD_SC_OK != 8668 MHD_response_add_auth_basic_challenge (response, realm, prefer_utf8)) 8669 && (MHD_NO != abort_if_failed)) 8670 { 8671 MHD_response_destroy (response); 8672 return MHD_action_abort_request (request); 8673 } 8674 return MHD_action_from_response (request, response); 8675 } 8676 8677 8678 MHD_STATIC_INLINE_END_ 8679 8680 8681 /** 8682 * Create action to reply with Basic Authentication "challenge". 8683 * 8684 * The @a response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code. 8685 * 8686 * If the @a response object cannot be extended with the "challenge", 8687 * the @a response will be used to reply without the "challenge". 8688 * 8689 * @param request the request to create the action for 8690 * @param realm the realm presented to the client 8691 * @param prefer_utf8 if not set to #MHD_NO, parameter'charset="UTF-8"' will 8692 * be added, indicating for client that UTF-8 encoding 8693 * is preferred 8694 * @param response the reply to send; should contain the "access denied" 8695 * body; 8696 * note: this function adds the "WWW Authenticate" header in 8697 * the response and the caller should not set this header; 8698 * the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status 8699 * code; 8700 * the NULL is tolerated (the result is 8701 * #MHD_action_abort_request()) 8702 * @return pointer to the action, the action must be consumed 8703 * otherwise response object may leak; 8704 * NULL if failed or if any action has been already created for 8705 * the @a request; 8706 * when failed the response object is consumed and need not 8707 * to be "destroyed" 8708 * @ingroup authentication 8709 */ 8710 #define MHD_action_basic_auth_challenge_p(request,realm,prefer_utf8,response) \ 8711 MHD_action_basic_auth_challenge ((request), (realm), (prefer_utf8), \ 8712 (response), MHD_NO) 8713 8714 /** 8715 * Create action to reply with Basic Authentication "challenge". 8716 * 8717 * The @a response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code. 8718 * 8719 * If the @a response object cannot be extended with the "challenge", 8720 * the request will be aborted. 8721 * 8722 * @param request the request to create the action for 8723 * @param realm the realm presented to the client 8724 * @param prefer_utf8 if not set to #MHD_NO, parameter'charset="UTF-8"' will 8725 * be added, indicating for client that UTF-8 encoding 8726 * is preferred 8727 * @param response the reply to send; should contain the "access denied" 8728 * body; 8729 * note: this function adds the "WWW Authenticate" header in 8730 * the response and the caller should not set this header; 8731 * the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status 8732 * code; 8733 * the NULL is tolerated (the result is 8734 * #MHD_action_abort_request()) 8735 * @return pointer to the action, the action must be consumed 8736 * otherwise response object may leak; 8737 * NULL if failed or if any action has been already created for 8738 * the @a request; 8739 * when failed the response object is consumed and need not 8740 * to be "destroyed" 8741 * @ingroup authentication 8742 */ 8743 #define MHD_action_basic_auth_challenge_a(request,realm,prefer_utf8,response) \ 8744 MHD_action_basic_auth_challenge ((request), (realm), (prefer_utf8), \ 8745 (response), MHD_YES) 8746 8747 #endif /* ! MHD_NO_STATIC_INLINE */ 8748 8749 8750 /** 8751 * Information decoded from Basic Authentication client's header. 8752 * 8753 * @see #MHD_REQUEST_INFO_DYNAMIC_AUTH_BASIC_CREDS 8754 */ 8755 struct MHD_AuthBasicCreds 8756 { 8757 /** 8758 * The username 8759 */ 8760 struct MHD_String username; 8761 8762 /** 8763 * The password, string pointer may be NULL if password is not encoded 8764 * by the client. 8765 */ 8766 struct MHD_StringNullable password; 8767 }; 8768 8769 /* ********************** (f) Introspection ********************** */ 8770 8771 8772 /** 8773 * Types of information about MHD, used by #MHD_lib_get_info_fixed_sz(). 8774 * This information is not changed at run-time. 8775 */ 8776 enum MHD_FIXED_ENUM_APP_SET_ MHD_LibInfoFixed 8777 { 8778 /* * Basic MHD information * */ 8779 8780 /** 8781 * Get the MHD version as a number. 8782 * The result is placed in @a v_version_num_uint32 member. 8783 */ 8784 MHD_LIB_INFO_FIXED_VERSION_NUM = 0 8785 , 8786 /** 8787 * Get the MHD version as a string. 8788 * The result is placed in @a v_version_string member. 8789 */ 8790 MHD_LIB_INFO_FIXED_VERSION_STRING = 1 8791 , 8792 8793 /* * Basic MHD features, buid-time configurable * */ 8794 /* These features should be always available unless the library was 8795 * not compiled specifically for some embedded project. 8796 * Exceptions are marked explicitly in the description. */ 8797 8798 /** 8799 * Get whether messages are supported. If supported then messages can be 8800 * printed to stderr or to an external logger. 8801 * The result is placed in @a v_support_log_messages_bool member. 8802 */ 8803 MHD_LIB_INFO_FIXED_SUPPORT_LOG_MESSAGES = 11 8804 , 8805 /** 8806 * Get whether detailed automatic HTTP reply messages are supported. 8807 * If supported then automatic responses have bodies with text explaining 8808 * the error details. 8809 * Automatic responses are sent by MHD automatically when client is violating 8810 * HTTP specification, for example, the request header has whitespace in 8811 * header name or request's "Content-Length" header has non-number value. 8812 * The result is placed in @a v_support_auto_replies_bodies_bool member. 8813 */ 8814 MHD_LIB_INFO_FIXED_SUPPORT_AUTO_REPLIES_BODIES = 12 8815 , 8816 /** 8817 * Get whether MHD was built with debug asserts disabled. 8818 * These asserts enabled only on special debug builds. 8819 * For debug builds the error log is always enabled. 8820 * The result is placed in @a v_is_non_debug_bool member. 8821 */ 8822 MHD_LIB_INFO_FIXED_IS_NON_DEBUG = 13 8823 , 8824 /** 8825 * Get whether MHD supports threads. 8826 * The result is placed in @a v_support_threads_bool member. 8827 */ 8828 MHD_LIB_INFO_FIXED_SUPPORT_THREADS = 14 8829 , 8830 /** 8831 * Get whether automatic parsing of HTTP Cookie header is supported. 8832 * If disabled, no #MHD_VK_COOKIE will be generated by MHD. 8833 * The result is placed in @a v_support_cookie_parser_bool member. 8834 */ 8835 MHD_LIB_INFO_FIXED_SUPPORT_COOKIE_PARSER = 15 8836 , 8837 /** 8838 * Get whether postprocessor is supported. If supported then 8839 * #MHD_action_post_processor() can be used. 8840 * The result is placed in @a v_support_post_parser_bool member. 8841 */ 8842 MHD_LIB_INFO_FIXED_SUPPORT_POST_PARSER = 16 8843 , 8844 /** 8845 * Get whether HTTP "Upgrade" is supported. 8846 * If supported then #MHD_action_upgrade() can be used. 8847 * The result is placed in @a v_support_upgrade_bool member. 8848 */ 8849 MHD_LIB_INFO_FIXED_SUPPORT_UPGRADE = 17 8850 , 8851 /** 8852 * Get whether HTTP Basic authorization is supported. If supported 8853 * then functions #MHD_action_basic_auth_required_response () 8854 * and #MHD_REQUEST_INFO_DYNAMIC_AUTH_BASIC_CREDS can be used. 8855 * The result is placed in @a v_support_auth_basic_bool member. 8856 */ 8857 MHD_LIB_INFO_FIXED_SUPPORT_AUTH_BASIC = 20 8858 , 8859 /** 8860 * Get whether HTTP Digest authorization is supported. If 8861 * supported then options #MHD_D_O_RANDOM_ENTROPY, 8862 * #MHD_D_O_DAUTH_MAP_SIZE and functions 8863 * #MHD_action_digest_auth_required_response () and 8864 * #MHD_digest_auth_check() can be used. 8865 * The result is placed in @a v_support_auth_digest_bool member. 8866 */ 8867 MHD_LIB_INFO_FIXED_SUPPORT_AUTH_DIGEST = 21 8868 , 8869 /** 8870 * Get whether the early version the Digest Authorization (RFC 2069) is 8871 * supported (digest authorisation without QOP parameter). 8872 * Currently it is always supported if Digest Auth module is built. 8873 * The result is placed in @a v_support_digest_auth_rfc2069_bool member. 8874 */ 8875 MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_RFC2069 = 22 8876 , 8877 /** 8878 * Get whether the MD5-based hashing algorithms are supported for Digest 8879 * Authorization and the type of the implementation if supported. 8880 * Currently it is always supported if Digest Auth module is built 8881 * unless manually disabled in a custom build. 8882 * The result is placed in @a v_type_digest_auth_md5_algo_type member. 8883 */ 8884 MHD_LIB_INFO_FIXED_TYPE_DIGEST_AUTH_MD5 = 23 8885 , 8886 /** 8887 * Get whether the SHA-256-based hashing algorithms are supported for Digest 8888 * Authorization and the type of the implementation if supported. 8889 * Currently it is always supported if Digest Auth module is built 8890 * unless manually disabled in a custom build. 8891 * The result is placed in @a v_type_digest_auth_sha256_algo_type member. 8892 */ 8893 MHD_LIB_INFO_FIXED_TYPE_DIGEST_AUTH_SHA256 = 24 8894 , 8895 /** 8896 * Get whether the SHA-512/256-based hashing algorithms are supported 8897 * Authorization and the type of the implementation if supported. 8898 * Currently it is always supported if Digest Auth module is built 8899 * unless manually disabled in a custom build. 8900 * The result is placed in @a v_type_digest_auth_sha512_256_algo_type member. 8901 */ 8902 MHD_LIB_INFO_FIXED_TYPE_DIGEST_AUTH_SHA512_256 = 25 8903 , 8904 /** 8905 * Get whether QOP with value 'auth-int' (authentication with integrity 8906 * protection) is supported for Digest Authorization. 8907 * Currently it is always not supported. 8908 * The result is placed in @a v_support_digest_auth_auth_int_bool member. 8909 */ 8910 MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_AUTH_INT = 28 8911 , 8912 /** 8913 * Get whether 'session' algorithms (like 'MD5-sess') are supported for Digest 8914 * Authorization. 8915 * Currently it is always not supported. 8916 * The result is placed in @a v_support_digest_auth_algo_session_bool member. 8917 */ 8918 MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_ALGO_SESSION = 29 8919 , 8920 /** 8921 * Get whether 'userhash' is supported for Digest Authorization. 8922 * Currently it is always supported if Digest Auth module is built. 8923 * The result is placed in @a v_support_digest_auth_userhash_bool member. 8924 */ 8925 MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_USERHASH = 30 8926 , 8927 8928 /* * Platform-dependent features, some are configurable at build-time * */ 8929 /* These features depends on the platform, third-party libraries and 8930 * the toolchain. 8931 * Some of the features can be disabled or selected at build-time. */ 8932 /** 8933 * Get sockets polling functions/techniques supported by this MHD build. 8934 * Some functions can be disabled (like epoll) in kernel, this is not 8935 * checked. 8936 * The result is placed in @a v_types_sockets_polling member. 8937 */ 8938 MHD_LIB_INFO_FIXED_TYPES_SOCKETS_POLLING = 60 8939 , 8940 /** 8941 * Get whether aggregate FD external polling is supported. 8942 * The result is placed in @a v_support_aggregate_fd_bool member. 8943 */ 8944 MHD_LIB_INFO_FIXED_SUPPORT_AGGREGATE_FD = 61 8945 , 8946 /** 8947 * Get whether IPv6 is supported on the platform and IPv6-only listen socket 8948 * can be used. 8949 * The result is placed in @a v_ipv6 member. 8950 * @note The platform may have disabled IPv6 at run-time, it is not checked 8951 * by this information type. 8952 */ 8953 MHD_LIB_INFO_FIXED_TYPE_IPV6 = 62 8954 , 8955 /** 8956 * Get whether TCP Fast Open is supported by MHD build. 8957 * If supported then option #MHD_D_O_TCP_FASTOPEN can be used. 8958 * The result is placed in @a v_support_tcp_fastopen_bool member. 8959 */ 8960 MHD_LIB_INFO_FIXED_SUPPORT_TCP_FASTOPEN = 64 8961 , 8962 /** 8963 * Get whether MHD support automatic detection of bind port number. 8964 * @sa #MHD_D_O_BIND_PORT 8965 * The result is placed in @a v_has_autodetect_bind_port_bool member. 8966 */ 8967 MHD_LIB_INFO_FIXED_HAS_AUTODETECT_BIND_PORT = 65 8968 , 8969 /** 8970 * Get whether MHD use system's sendfile() function to send 8971 * file-FD based responses over non-TLS connections. 8972 * The result is placed in @a v_has_sendfile_bool member. 8973 */ 8974 MHD_LIB_INFO_FIXED_HAS_SENDFILE = 66 8975 , 8976 /** 8977 * Get whether MHD supports automatic SIGPIPE suppression within internal 8978 * events loop (MHD's managed threads). 8979 * If SIGPIPE suppression is not supported, application must handle 8980 * SIGPIPE signal by itself whem using MHD with internal events loop. 8981 * If the platform does not have SIGPIPE the result is #MHD_YES. 8982 * The result is placed in @a v_has_autosuppress_sigpipe_int_bool member. 8983 */ 8984 MHD_LIB_INFO_FIXED_HAS_AUTOSUPPRESS_SIGPIPE_INT = 80 8985 , 8986 /** 8987 * Get whether MHD supports automatic SIGPIPE suppression when used with 8988 * extenal events loop (in application thread). 8989 * If SIGPIPE suppression is not supported, application must handle 8990 * SIGPIPE signal by itself whem using MHD with external events loop. 8991 * If the platform does not have SIGPIPE the result is #MHD_YES. 8992 * The result is placed in @a v_has_autosuppress_sigpipe_ext_bool member. 8993 */ 8994 MHD_LIB_INFO_FIXED_HAS_AUTOSUPPRESS_SIGPIPE_EXT = 81 8995 , 8996 /** 8997 * Get whether MHD sets names on generated threads. 8998 * The result is placed in @a v_has_thread_names_bool member. 8999 */ 9000 MHD_LIB_INFO_FIXED_HAS_THREAD_NAMES = 82 9001 , 9002 /** 9003 * Get the type of supported inter-thread communication. 9004 * The result is placed in @a v_type_itc member. 9005 */ 9006 MHD_LIB_INFO_FIXED_TYPE_ITC = 83 9007 , 9008 /** 9009 * Get whether reading files beyond 2 GiB boundary is supported. 9010 * If supported then #MHD_response_from_fd() can be used with sizes and 9011 * offsets larger than 2 GiB. If not supported value of size+offset could be 9012 * limited to 2 GiB. 9013 * The result is placed in @a v_support_large_file_bool member. 9014 */ 9015 MHD_LIB_INFO_FIXED_SUPPORT_LARGE_FILE = 84 9016 , 9017 9018 /* * Platform-dependent features, some set on startup and some are 9019 * configurable at build-time * */ 9020 /* These features depends on the platform, third-party libraries availability 9021 * and configuration. The features can be enabled/disabled during startup 9022 * of the library depending on conditions. 9023 * Some of the features can be disabled or selected at build-time. */ 9024 /** 9025 * Get whether HTTPS and which types of TLS backend(s) supported by 9026 * this build. 9027 * The result is placed in @a v_tls_backends member. 9028 */ 9029 MHD_LIB_INFO_FIXED_TLS_BACKENDS = 100 9030 , 9031 /** 9032 * Get whether password encrypted private key for HTTPS daemon is 9033 * supported by TLS backends. 9034 * If supported then option #MHD_D_OPTION_TLS_KEY_CERT can be used with 9035 * non-NULL @a mem_pass. 9036 * The result is placed in @a v_tls_key_password_backends member. 9037 */ 9038 MHD_LIB_INFO_FIXED_TLS_KEY_PASSWORD_BACKENDS = 102 9039 , 9040 9041 /* * Sentinel * */ 9042 /** 9043 * The sentinel value. 9044 * This value enforces specific underlying integer type for the enum. 9045 * Do not use. 9046 */ 9047 MHD_LIB_INFO_FIXED_SENTINEL = 65535 9048 }; 9049 9050 /** 9051 * The type of the data for digest algorithm implementations. 9052 */ 9053 enum MHD_FIXED_ENUM_MHD_SET_ MHD_LibInfoFixedDigestAlgoType 9054 { 9055 /** 9056 * The algorithm is not implemented or disabled at the build time. 9057 */ 9058 MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_NOT_AVAILABLE = 0 9059 , 9060 /** 9061 * The algorithm is implemented by MHD internal code. 9062 * MHD implementation of hashing can never fail. 9063 */ 9064 MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_BUILT_IN = 1 9065 , 9066 /** 9067 * The algorithm is implemented by external code that never fails. 9068 */ 9069 MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_EXTERNAL_NEVER_FAIL = 2 9070 , 9071 /** 9072 * The algorithm is implemented by external code that may hypothetically fail. 9073 */ 9074 MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_EXTERNAL_MAY_FAIL = 3 9075 }; 9076 9077 /** 9078 * The types of the sockets polling functions/techniques supported 9079 */ 9080 struct MHD_LibInfoFixedPollingFunc 9081 { 9082 /** 9083 * select() function for sockets polling 9084 */ 9085 enum MHD_Bool func_select; 9086 /** 9087 * poll() function for sockets polling 9088 */ 9089 enum MHD_Bool func_poll; 9090 /** 9091 * epoll technique for sockets polling 9092 */ 9093 enum MHD_Bool tech_epoll; 9094 /** 9095 * kqueue technique for sockets polling 9096 */ 9097 enum MHD_Bool tech_kqueue; 9098 }; 9099 9100 /** 9101 * The types of IPv6 supported 9102 */ 9103 enum MHD_FIXED_ENUM_MHD_SET_ MHD_LibInfoFixedIPv6Type 9104 { 9105 /** 9106 * IPv6 is not supported by this MHD build 9107 */ 9108 MHD_LIB_INFO_FIXED_IPV6_TYPE_NONE = 0 9109 , 9110 /** 9111 * IPv6 is supported only as "dual stack". 9112 * IPv4 connections can be received by IPv6 listen socket. 9113 */ 9114 MHD_LIB_INFO_FIXED_IPV6_TYPE_DUAL_ONLY = 1 9115 , 9116 /** 9117 * IPv6 can be used as IPv6-only (without getting IPv4 incoming connections). 9118 * The platform may support "dual stack" too. 9119 */ 9120 MHD_LIB_INFO_FIXED_IPV6_TYPE_IPV6_PURE = 2 9121 }; 9122 9123 /** 9124 * The types of inter-thread communication 9125 * @note the enum can be extended in future versions with new values 9126 */ 9127 enum MHD_FIXED_ENUM_MHD_SET_ MHD_LibInfoFixedITCType 9128 { 9129 /** 9130 * No ITC used. 9131 * This value is returned if MHD is built without threads support 9132 */ 9133 MHD_LIB_INFO_FIXED_ITC_TYPE_NONE = 0 9134 , 9135 /** 9136 * The pair of sockets are used as inter-thread communication. 9137 * The is the least efficient method of communication. 9138 */ 9139 MHD_LIB_INFO_FIXED_ITC_TYPE_SOCKETPAIR = 1 9140 , 9141 /** 9142 * The pipe is used as inter-thread communication. 9143 */ 9144 MHD_LIB_INFO_FIXED_ITC_TYPE_PIPE = 2 9145 , 9146 /** 9147 * The EventFD is used as inter-thread communication. 9148 * This is the most efficient method of communication. 9149 */ 9150 MHD_LIB_INFO_FIXED_ITC_TYPE_EVENTFD = 3 9151 }; 9152 9153 9154 /** 9155 * The types of the TLS (or TLS feature) backend supported/available/enabled 9156 * @note the enum can be extended in future versions with new members 9157 */ 9158 struct MHD_LibInfoTLSType 9159 { 9160 /** 9161 * The TLS (or TLS feature) is supported/enabled. 9162 * Set to #MHD_YES if any other member is #MHD_YES. 9163 */ 9164 enum MHD_Bool tls_supported; 9165 /** 9166 * The GnuTLS backend is supported/available/enabled. 9167 */ 9168 enum MHD_Bool backend_gnutls; 9169 /** 9170 * The OpenSSL backend is supported/available/enabled. 9171 */ 9172 enum MHD_Bool backend_openssl; 9173 /** 9174 * The MbedTLS backend is supported/available/enabled. 9175 */ 9176 enum MHD_Bool backend_mbedtls; 9177 }; 9178 9179 /** 9180 * The data provided by #MHD_lib_get_info_fixed_sz() 9181 */ 9182 union MHD_LibInfoFixedData 9183 { 9184 /** 9185 * The data for the #MHD_LIB_INFO_FIXED_VERSION_NUM query 9186 */ 9187 uint_fast32_t v_version_num_uint32; 9188 /** 9189 * The data for the #MHD_LIB_INFO_FIXED_VERSION_STR query 9190 */ 9191 struct MHD_String v_version_string; 9192 /** 9193 * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_LOG_MESSAGES query 9194 */ 9195 enum MHD_Bool v_support_log_messages_bool; 9196 /** 9197 * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_AUTO_REPLIES_BODIES query 9198 */ 9199 enum MHD_Bool v_support_auto_replies_bodies_bool; 9200 /** 9201 * The data for the #MHD_LIB_INFO_FIXED_IS_NON_DEBUG query 9202 */ 9203 enum MHD_Bool v_is_non_debug_bool; 9204 /** 9205 * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_THREADS query 9206 */ 9207 enum MHD_Bool v_support_threads_bool; 9208 /** 9209 * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_COOKIE_PARSER query 9210 */ 9211 enum MHD_Bool v_support_cookie_parser_bool; 9212 /** 9213 * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_POST_PARSER query 9214 */ 9215 enum MHD_Bool v_support_post_parser_bool; 9216 /** 9217 * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_UPGRADE query 9218 */ 9219 enum MHD_Bool v_support_upgrade_bool; 9220 /** 9221 * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_AUTH_BASIC query 9222 */ 9223 enum MHD_Bool v_support_auth_basic_bool; 9224 /** 9225 * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_AUTH_DIGEST query 9226 */ 9227 enum MHD_Bool v_support_auth_digest_bool; 9228 /** 9229 * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_RFC2069 query 9230 */ 9231 enum MHD_Bool v_support_digest_auth_rfc2069_bool; 9232 /** 9233 * The data for the #MHD_LIB_INFO_FIXED_TYPE_DIGEST_AUTH_MD5 query 9234 */ 9235 enum MHD_LibInfoFixedDigestAlgoType v_type_digest_auth_md5_algo_type; 9236 /** 9237 * The data for the #MHD_LIB_INFO_FIXED_TYPE_DIGEST_AUTH_SHA256 query 9238 */ 9239 enum MHD_LibInfoFixedDigestAlgoType v_type_digest_auth_sha256_algo_type; 9240 /** 9241 * The data for the #MHD_LIB_INFO_FIXED_TYPE_DIGEST_AUTH_SHA512_256 query 9242 */ 9243 enum MHD_LibInfoFixedDigestAlgoType v_type_digest_auth_sha512_256_algo_type; 9244 /** 9245 * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_AUTH_INT query 9246 */ 9247 enum MHD_Bool v_support_digest_auth_auth_int_bool; 9248 /** 9249 * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_ALGO_SESSION query 9250 */ 9251 enum MHD_Bool v_support_digest_auth_algo_session_bool; 9252 /** 9253 * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_USERHASH query 9254 */ 9255 enum MHD_Bool v_support_digest_auth_userhash_bool; 9256 /** 9257 * The data for the #MHD_LIB_INFO_FIXED_TYPES_SOCKETS_POLLING query 9258 */ 9259 struct MHD_LibInfoFixedPollingFunc v_types_sockets_polling; 9260 /** 9261 * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_AGGREGATE_FD query 9262 */ 9263 enum MHD_Bool v_support_aggregate_fd_bool; 9264 /** 9265 * The data for the #MHD_LIB_INFO_FIXED_TYPE_IPV6 query 9266 */ 9267 enum MHD_LibInfoFixedIPv6Type v_ipv6; 9268 /** 9269 * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_TCP_FASTOPEN query 9270 */ 9271 enum MHD_Bool v_support_tcp_fastopen_bool; 9272 /** 9273 * The data for the #MHD_LIB_INFO_FIXED_HAS_AUTODETECT_BIND_PORT query 9274 */ 9275 enum MHD_Bool v_has_autodetect_bind_port_bool; 9276 /** 9277 * The data for the #MHD_LIB_INFO_FIXED_HAS_SENDFILE query 9278 */ 9279 enum MHD_Bool v_has_sendfile_bool; 9280 /** 9281 * The data for the #MHD_LIB_INFO_FIXED_HAS_AUTOSUPPRESS_SIGPIPE_INT query 9282 */ 9283 enum MHD_Bool v_has_autosuppress_sigpipe_int_bool; 9284 /** 9285 * The data for the #MHD_LIB_INFO_FIXED_HAS_AUTOSUPPRESS_SIGPIPE_EXT query 9286 */ 9287 enum MHD_Bool v_has_autosuppress_sigpipe_ext_bool; 9288 /** 9289 * The data for the #MHD_LIB_INFO_FIXED_HAS_THREAD_NAMES query 9290 */ 9291 enum MHD_Bool v_has_thread_names_bool; 9292 /** 9293 * The data for the #MHD_LIB_INFO_FIXED_TYPE_ITC query 9294 */ 9295 enum MHD_LibInfoFixedITCType v_type_itc; 9296 /** 9297 * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_LARGE_FILE query 9298 */ 9299 enum MHD_Bool v_support_large_file_bool; 9300 /** 9301 * The data for the #MHD_LIB_INFO_FIXED_TLS_BACKENDS query 9302 */ 9303 struct MHD_LibInfoTLSType v_tls_backends; 9304 /** 9305 * The data for the #MHD_LIB_INFO_FIXED_TLS_KEY_PASSWORD_BACKENDS query 9306 */ 9307 struct MHD_LibInfoTLSType v_tls_key_password_backends; 9308 }; 9309 9310 /** 9311 * Get fixed information about MHD that is not changed at run-time. 9312 * The returned information can be cached by application as it will be not 9313 * changed at run-time. 9314 * 9315 * For any valid @a info_type the only possible returned error value is 9316 * #MHD_SC_INFO_GET_BUFF_TOO_SMALL. If the buffer is large enough and 9317 * the requested type of information is valid, the function always succeeds 9318 * and returns #MHD_SC_OK. 9319 * 9320 * The wrapper macro #MHD_lib_get_info_fixed() may be more convenient. 9321 * 9322 * @param info_type the type of requested information 9323 * @param[out] output_buf the pointer to union to be set to the requested 9324 * information 9325 * @param output_buf_size the size of the memory area pointed by @a output_buf 9326 * (provided by the caller for storing the requested 9327 * information), in bytes 9328 * @return #MHD_SC_OK if succeed, 9329 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown, 9330 * #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small 9331 * @ingroup specialized 9332 */ 9333 MHD_EXTERN_ enum MHD_StatusCode 9334 MHD_lib_get_info_fixed_sz (enum MHD_LibInfoFixed info_type, 9335 union MHD_LibInfoFixedData *MHD_RESTRICT output_buf, 9336 size_t output_buf_size) 9337 MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_OUT_ (2); 9338 9339 /** 9340 * Get fixed information about MHD that is not changed at run-time. 9341 * The returned information can be cached by application as it will be not 9342 * changed at run-time. 9343 * 9344 * @param info the type of requested information 9345 * @param[out] output_buf the pointer to union to be set to the requested 9346 * information 9347 * @return #MHD_SC_OK if succeed, 9348 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown, 9349 * or other error code 9350 * @ingroup specialized 9351 */ 9352 #define MHD_lib_get_info_fixed(info,output_buf) \ 9353 MHD_lib_get_info_fixed_sz ((info),(output_buf),sizeof(*(output_buf))) 9354 9355 /* Application may define MHD_NO_STATIC_INLINE macro before including 9356 libmicrohttpd headers to disable static inline functions in the headers. */ 9357 #ifndef MHD_NO_STATIC_INLINE 9358 9359 /* 9360 * A helper below can be used in a simple check preventing use of downgraded 9361 * library version. 9362 * As new library version may introduce new functionality, and the application 9363 * may detect some functionality available at application build-time, use of 9364 * previous versions may lead to run-time failures. 9365 * To prevent run-time failures, application may use a check like: 9366 9367 if (MHD_lib_get_info_ver_num() < ((uint_fast32_t) MHD_VERSION)) 9368 handle_init_failure(); 9369 9370 */ 9371 /** 9372 * Get the library version number. 9373 * @return the library version number. 9374 */ 9375 MHD_STATIC_INLINE_ MHD_FN_PURE_ uint_fast32_t 9376 MHD_lib_get_info_ver_num (void) 9377 { 9378 union MHD_LibInfoFixedData data; 9379 data.v_version_num_uint32 = 0; /* Not really necessary */ 9380 (void) MHD_lib_get_info_fixed (MHD_LIB_INFO_FIXED_VERSION_NUM, \ 9381 &data); /* Never fail */ 9382 return data.v_version_num_uint32; 9383 } 9384 9385 9386 MHD_STATIC_INLINE_END_ 9387 9388 #endif /* ! MHD_NO_STATIC_INLINE */ 9389 9390 /** 9391 * Types of information about MHD, used by #MHD_lib_get_info_dynamic_sz(). 9392 * This information may vary over time. 9393 */ 9394 enum MHD_FIXED_ENUM_APP_SET_ MHD_LibInfoDynamic 9395 { 9396 /* * Basic MHD information * */ 9397 9398 /** 9399 * Get whether MHD has been successfully fully initialised. 9400 * MHD uses lazy initialisation: a minimal initialisation is performed at 9401 * startup, complete initialisation is performed when any daemon is created 9402 * (or when called some function which requires full initialisation). 9403 * The result is #MHD_NO when the library has been not yet initialised 9404 * completely since startup. 9405 * The result is placed in @a v_inited_fully_once_bool member. 9406 */ 9407 MHD_LIB_INFO_DYNAMIC_INITED_FULLY_ONCE = 0 9408 , 9409 /** 9410 * Get whether MHD is fully initialised. 9411 * MHD uses lazy initialisation: a minimal initialisation is performed at 9412 * startup, complete initialisation is perfromed when any daemon is created 9413 * (or when called some function which requires full initialisation). 9414 * The result is #MHD_YES if library is initialised state now (meaning 9415 * that at least one daemon is created and not destroyed or some function 9416 * required full initialisation is running). 9417 * The result is placed in @a v_inited_fully_now_bool member. 9418 */ 9419 MHD_LIB_INFO_DYNAMIC_INITED_FULLY_NOW = 1 9420 , 9421 9422 /** 9423 * Get whether HTTPS and which types of TLS backend(s) currently available. 9424 * If any MHD daemons active (created and not destroyed, not necessary 9425 * running) the result reflects the current backends availability. 9426 * If no MHD daemon is active, then this function would try to temporarily 9427 * enable backends to check for their availability. 9428 * If global library initialisation failed, the function returns 9429 * #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE error code. 9430 * The result is placed in @a v_tls_backends member. 9431 */ 9432 MHD_LIB_INFO_DYNAMIC_TYPE_TLS = 100 9433 , 9434 9435 /* * Sentinel * */ 9436 /** 9437 * The sentinel value. 9438 * This value enforces specific underlying integer type for the enum. 9439 * Do not use. 9440 */ 9441 MHD_LIB_INFO_DYNAMIC_SENTINEL = 65535 9442 }; 9443 9444 9445 /** 9446 * The data provided by #MHD_lib_get_info_dynamic_sz(). 9447 * The resulting value may vary over time. 9448 */ 9449 union MHD_LibInfoDynamicData 9450 { 9451 /** 9452 * The data for the #MHD_LIB_INFO_DYNAMIC_INITED_FULLY_ONCE query 9453 */ 9454 enum MHD_Bool v_inited_fully_once_bool; 9455 9456 /** 9457 * The data for the #MHD_LIB_INFO_DYNAMIC_INITED_FULLY_NOW query 9458 */ 9459 enum MHD_Bool v_inited_fully_now_bool; 9460 9461 /** 9462 * The data for the #MHD_LIB_INFO_DYNAMIC_TYPE_TLS query 9463 */ 9464 struct MHD_LibInfoTLSType v_tls_backends; 9465 9466 /** 9467 * Unused member. 9468 * Help enforcing future-proof alignment of the union. 9469 * Do not use. 9470 */ 9471 void *reserved; 9472 }; 9473 9474 /** 9475 * Get dynamic information about MHD that may be changed at run-time. 9476 * The wrapper macro #MHD_lib_get_info_dynamic() could be more convenient. 9477 * 9478 * @param info_type the type of requested information 9479 * @param[out] output_buf the pointer to union to be set to the requested 9480 * information 9481 * @param output_buf_size the size of the memory area pointed by @a output_buf 9482 * (provided by the caller for storing the requested 9483 * information), in bytes 9484 * @return #MHD_SC_OK if succeed, 9485 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown, 9486 * #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small, 9487 * or other error code 9488 * @ingroup specialized 9489 */ 9490 MHD_EXTERN_ enum MHD_StatusCode 9491 MHD_lib_get_info_dynamic_sz ( 9492 enum MHD_LibInfoDynamic info_type, 9493 union MHD_LibInfoDynamicData *MHD_RESTRICT output_buf, 9494 size_t output_buf_size) 9495 MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_OUT_ (2); 9496 9497 /** 9498 * Get dynamic information about MHD that may be changed at run-time. 9499 * 9500 * @param info the type of requested information 9501 * @param[out] output_buf the pointer to union to be set to the requested 9502 * information 9503 * @return #MHD_SC_OK if succeed, 9504 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown, 9505 * or other error code 9506 * @ingroup specialized 9507 */ 9508 #define MHD_lib_get_info_dynamic(info,output_buf) \ 9509 MHD_lib_get_info_dynamic_sz ((info),(output_buf),sizeof(*(output_buf))) 9510 9511 9512 /** 9513 * Values of this enum are used to specify what information about a daemon is 9514 * requested. 9515 * These types of information do not change after the start of the daemon 9516 * until the daemon is destroyed. 9517 */ 9518 enum MHD_DaemonInfoFixedType 9519 { 9520 9521 /** 9522 * Get the type of system call used for sockets polling. 9523 * The value #MHD_SPS_AUTO is never set in the returned data. 9524 * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon 9525 * does not use internal sockets polling. 9526 * The result is placed in @a v_poll_syscall member. 9527 */ 9528 MHD_DAEMON_INFO_FIXED_POLL_SYSCALL = 41 9529 , 9530 /** 9531 * Get the file descriptor for the single FD that triggered when 9532 * any MHD event happens. 9533 * This FD can be watched as aggregate indicator for all MHD events. 9534 * The provided socket must be used as 'read-only': only select() or similar 9535 * functions should be used. Any modifications (changing socket attributes, 9536 * calling accept(), closing it etc.) will lead to undefined behaviour. 9537 * The function returns #MHD_SC_INFO_GET_TYPE_NOT_SUPP_BY_BUILD if the library 9538 * does not support mode with agregate FD. 9539 * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon 9540 * is not configured to use this mode. 9541 * The result is placed in @a v_aggreagate_fd member. 9542 */ 9543 MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD = 46 9544 , 9545 /** 9546 * Get the number of worker threads when used in MHD_WM_WORKER_THREADS mode. 9547 * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon 9548 * does not use worker threads mode. 9549 * The result is placed in @a v_num_work_threads_uint member. 9550 */ 9551 MHD_DAEMON_INFO_FIXED_NUM_WORK_THREADS = 47 9552 , 9553 /** 9554 * Get the port number of daemon's listen socket. 9555 * Note: if port '0' (auto port) was specified for #MHD_D_OPTION_BIND_PORT(), 9556 * returned value will be the real port number. 9557 * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon 9558 * does not have listening socket or if listening socket is non-IP. 9559 * The function returns #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the port number 9560 * detection failed or not supported by the platform. 9561 * If the function succeed, the returned port number is never zero. 9562 * The result is placed in @a v_bind_port_uint16 member. 9563 */ 9564 MHD_DAEMON_INFO_FIXED_BIND_PORT = 80 9565 , 9566 /** 9567 * Get the file descriptor for the listening socket. 9568 * The provided socket must be used as 'read-only': only select() or similar 9569 * functions should be used. Any modifications (changing socket attributes, 9570 * calling accept(), closing it etc.) will lead to undefined behaviour. 9571 * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon 9572 * does not have listening socket. 9573 * The result is placed in @a v_listen_socket member. 9574 */ 9575 MHD_DAEMON_INFO_FIXED_LISTEN_SOCKET = 82 9576 , 9577 /** 9578 * Get the TLS backend used by the daemon. 9579 * The value #MHD_TLS_BACKEND_ANY is never set in the returned data. 9580 * The value #MHD_TLS_BACKEND_NONE is set if the daemon does not use TLS. 9581 * If MHD built without TLS support then #MHD_TLS_BACKEND_NONE is always set. 9582 * The result is placed in @a v_tls_backend member. 9583 */ 9584 MHD_DAEMON_INFO_FIXED_TLS_BACKEND = 120 9585 , 9586 /** 9587 * Get the default inactivity timeout for connections in milliseconds. 9588 * The result is placed in @a v_default_timeout_milsec_uint32 member. 9589 */ 9590 MHD_DAEMON_INFO_FIXED_DEFAULT_TIMEOUT_MILSEC = 160 9591 , 9592 /** 9593 * Get the limit of number of simutaneous network connections served by 9594 * the daemon. 9595 * The result is placed in @a v_global_connection_limit_uint member. 9596 */ 9597 MHD_DAEMON_INFO_FIXED_GLOBAL_CONNECTION_LIMIT = 161 9598 , 9599 /** 9600 * Get the limit of number of simutaneous network connections served by 9601 * the daemon for any single IP address. 9602 * The result is placed in @a v_per_ip_limit_uint member. 9603 */ 9604 MHD_DAEMON_INFO_FIXED_PER_IP_LIMIT = 162 9605 , 9606 /** 9607 * Get the setting for suppression of the 'Date:' header in replies. 9608 * The result is placed in @a v_suppress_date_header_bool member. 9609 */ 9610 MHD_DAEMON_INFO_FIXED_SUPPRESS_DATE_HEADER = 240 9611 , 9612 /** 9613 * Get the size of buffer unsed per connection. 9614 * The result is placed in @a v_conn_memory_limit_sizet member. 9615 */ 9616 MHD_DAEMON_INFO_FIXED_CONN_MEMORY_LIMIT = 280 9617 , 9618 /** 9619 * Get the limit of maximum FD value for the daemon. 9620 * The daemon rejects (closes) any sockets with FD equal or higher 9621 * the resulting number. 9622 * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon 9623 * is built for W32. 9624 * The result is placed in @a v_fd_number_limit_uint member. 9625 */ 9626 MHD_DAEMON_INFO_FIXED_FD_NUMBER_LIMIT = 283 9627 , 9628 9629 /* * Sentinel * */ 9630 /** 9631 * The sentinel value. 9632 * This value enforces specific underlying integer type for the enum. 9633 * Do not use. 9634 */ 9635 MHD_DAEMON_INFO_FIXED_SENTINEL = 65535 9636 9637 }; 9638 9639 9640 /** 9641 * Information about an MHD daemon. 9642 */ 9643 union MHD_DaemonInfoFixedData 9644 { 9645 /** 9646 * The data for the #MHD_DAEMON_INFO_FIXED_POLL_SYSCALL query 9647 */ 9648 enum MHD_SockPollSyscall v_poll_syscall; 9649 9650 /** 9651 * The data for the #MHD_DAEMON_INFO_FIXED_NUM_WORK_THREADS query 9652 */ 9653 unsigned int v_num_work_threads_uint; 9654 9655 /** 9656 * The data for the #MHD_DAEMON_INFO_FIXED_BIND_PORT query 9657 */ 9658 uint_least16_t v_bind_port_uint16; 9659 9660 /** 9661 * The data for the #MHD_DAEMON_INFO_FIXED_LISTEN_SOCKET query 9662 */ 9663 MHD_Socket v_listen_socket; 9664 9665 /** 9666 * The data for the #MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD query 9667 */ 9668 int v_aggreagate_fd; 9669 9670 /** 9671 * The data for the #MHD_DAEMON_INFO_FIXED_TLS_BACKEND query 9672 */ 9673 enum MHD_TlsBackend v_tls_backend; 9674 9675 /** 9676 * The data for the #MHD_DAEMON_INFO_FIXED_DEFAULT_TIMEOUT_MILSEC query 9677 */ 9678 uint_fast32_t v_default_timeout_milsec_uint32; 9679 9680 /** 9681 * The data for the #MHD_DAEMON_INFO_FIXED_GLOBAL_CONNECTION_LIMIT query 9682 */ 9683 unsigned int v_global_connection_limit_uint; 9684 9685 /** 9686 * The data for the #MHD_DAEMON_INFO_FIXED_PER_IP_LIMIT query 9687 */ 9688 unsigned int v_per_ip_limit_uint; 9689 9690 /** 9691 * The data for the #MHD_DAEMON_INFO_FIXED_SUPPRESS_DATE_HEADER query 9692 */ 9693 enum MHD_Bool v_suppress_date_header_bool; 9694 9695 /** 9696 * The data for the #MHD_DAEMON_INFO_FIXED_CONN_MEMORY_LIMIT query 9697 */ 9698 size_t v_conn_memory_limit_sizet; 9699 9700 /** 9701 * The data for the #MHD_DAEMON_INFO_FIXED_FD_NUMBER_LIMIT query 9702 */ 9703 MHD_Socket v_fd_number_limit_socket; 9704 9705 /** 9706 * Unused member. 9707 * Help enforcing future-proof alignment of the union. 9708 * Do not use. 9709 */ 9710 void *reserved; 9711 }; 9712 9713 9714 /** 9715 * Obtain fixed information about the given daemon. 9716 * This information is not changed at after start of the daemon until 9717 * the daemon is destroyed. 9718 * The wrapper macro #MHD_daemon_get_info_fixed() may be more convenient. 9719 * 9720 * @param daemon the daemon to get information about 9721 * @param info_type the type of information requested 9722 * @param[out] output_buf pointer to union where requested information will 9723 * be stored 9724 * @param output_buf_size the size of the memory area pointed by @a output_buf 9725 * (provided by the caller for storing the requested 9726 * information), in bytes 9727 * @return #MHD_SC_OK if succeed, 9728 * #MHD_SC_TOO_EARLY if the daemon has not been started yet, 9729 * #MHD_SC_TOO_LATE if the daemon is being stopped or has failed, 9730 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown, 9731 * #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information 9732 * is not available for this 9733 * daemon due to the daemon 9734 * configuration/mode, 9735 * #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information 9736 * should be available for 9737 * the daemon, but cannot be provided 9738 * due to some error or other 9739 * reasons, 9740 * #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small, 9741 * other error codes in case of other errors 9742 * @ingroup specialized 9743 */ 9744 MHD_EXTERN_ enum MHD_StatusCode 9745 MHD_daemon_get_info_fixed_sz ( 9746 struct MHD_Daemon *MHD_RESTRICT daemon, 9747 enum MHD_DaemonInfoFixedType info_type, 9748 union MHD_DaemonInfoFixedData *MHD_RESTRICT output_buf, 9749 size_t output_buf_size) 9750 MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1) 9751 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); 9752 9753 /** 9754 * Obtain fixed information about the given daemon. 9755 * This types of information are not changed at after start of the daemon until 9756 * the daemon is destroyed. 9757 * 9758 * @param daemon the daemon to get information about 9759 * @param info_type the type of information requested 9760 * @param[out] output_buf pointer to union where requested information will 9761 * be stored 9762 * @return #MHD_SC_OK if succeed, 9763 * #MHD_SC_TOO_EARLY if the daemon has not been started yet, 9764 * #MHD_SC_TOO_LATE if the daemon is being stopped or has failed, 9765 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown, 9766 * #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information 9767 * is not available for this 9768 * daemon due to the daemon 9769 * configuration/mode, 9770 * #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information 9771 * should be available for 9772 * the daemon, but cannot be provided 9773 * due to some error or other 9774 * reasons, 9775 * other error codes in case of other errors 9776 * @ingroup specialized 9777 */ 9778 #define MHD_daemon_get_info_fixed(daemon,info_type,output_buf) \ 9779 MHD_daemon_get_info_fixed_sz ((daemon), (info_type), (output_buf), \ 9780 sizeof(*(output_buf))) 9781 9782 9783 /** 9784 * Values of this enum are used to specify what 9785 * information about a daemon is desired. 9786 * This types of information may be changed after the start of the daemon. 9787 */ 9788 enum MHD_DaemonInfoDynamicType 9789 { 9790 /** 9791 * The the maximum number of millisecond from the current moment until 9792 * the mandatory call of the daemon data processing function (like 9793 * #MHD_daemon_process_reg_events(), #MHD_daemon_process_blocking()). 9794 * If resulting value is zero then daemon data processing function should be 9795 * called as soon as possible as some data processing is already pending. 9796 * The data processing function can also be called earlier as well. 9797 * Available only for daemons stated in #MHD_WM_EXTERNAL_PERIODIC, 9798 * #MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL, #MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE 9799 * or #MHD_WM_EXTERNAL_SINGLE_FD_WATCH modes. 9800 * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon has 9801 * internal handling of events (internal threads). 9802 * The result is placed in @a v_max_time_to_wait_uint64 member. 9803 */ 9804 MHD_DAEMON_INFO_DYNAMIC_MAX_TIME_TO_WAIT = 1 9805 , 9806 /** 9807 * Check whether the daemon has any connected network clients. 9808 * The result is placed in @a v_has_connections_bool member. 9809 */ 9810 MHD_DAEMON_INFO_DYNAMIC_HAS_CONNECTIONS = 20 9811 , 9812 /* * Sentinel * */ 9813 /** 9814 * The sentinel value. 9815 * This value enforces specific underlying integer type for the enum. 9816 * Do not use. 9817 */ 9818 MHD_DAEMON_INFO_DYNAMIC_SENTINEL = 65535 9819 }; 9820 9821 9822 /** 9823 * Information about an MHD daemon. 9824 */ 9825 union MHD_DaemonInfoDynamicData 9826 { 9827 /** 9828 * The data for the #MHD_DAEMON_INFO_DYNAMIC_MAX_TIME_TO_WAIT query 9829 */ 9830 uint_fast64_t v_max_time_to_wait_uint64; 9831 9832 /** 9833 * The data for the #MHD_DAEMON_INFO_DYNAMIC_HAS_CONNECTIONS query 9834 */ 9835 enum MHD_Bool v_has_connections_bool; 9836 9837 /** 9838 * Unused member. 9839 * Help enforcing future-proof alignment of the union. 9840 * Do not use. 9841 */ 9842 void *reserved; 9843 }; 9844 9845 9846 /** 9847 * Obtain dynamic information about the given daemon. 9848 * This information may be changed after the start of the daemon. 9849 * The wrapper macro #MHD_daemon_get_info_dynamic() could be more convenient. 9850 * 9851 * @param daemon the daemon to get information about 9852 * @param info_type the type of information requested 9853 * @param[out] output_buf the pointer to union to be set to the requested 9854 * information 9855 * @param output_buf_size the size of the memory area pointed by @a output_buf 9856 * (provided by the caller for storing the requested 9857 * information), in bytes 9858 * @return #MHD_SC_OK if succeed, 9859 * #MHD_SC_TOO_EARLY if the daemon has not been started yet, 9860 * #MHD_SC_TOO_LATE if the daemon is being stopped or has failed, 9861 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown, 9862 * #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information 9863 * is not available for this 9864 * daemon due to the daemon 9865 * configuration/mode, 9866 * #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information 9867 * should be available for 9868 * the daemon, but cannot be provided 9869 * due to some error or other 9870 * reasons, 9871 * #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small, 9872 * other error codes in case of other errors 9873 * @ingroup specialized 9874 */ 9875 MHD_EXTERN_ enum MHD_StatusCode 9876 MHD_daemon_get_info_dynamic_sz ( 9877 struct MHD_Daemon *MHD_RESTRICT daemon, 9878 enum MHD_DaemonInfoDynamicType info_type, 9879 union MHD_DaemonInfoDynamicData *MHD_RESTRICT output_buf, 9880 size_t output_buf_size) 9881 MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1) 9882 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); 9883 9884 /** 9885 * Obtain dynamic information about the given daemon. 9886 * This types of information may be changed after the start of the daemon. 9887 * 9888 * @param daemon the daemon to get information about 9889 * @param info_type the type of information requested 9890 * @param[out] output_buf the pointer to union to be set to the requested 9891 * information 9892 * @return #MHD_SC_OK if succeed, 9893 * #MHD_SC_TOO_EARLY if the daemon has not been started yet, 9894 * #MHD_SC_TOO_LATE if the daemon is being stopped or has failed, 9895 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown, 9896 * #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information 9897 * is not available for this 9898 * daemon due to the daemon 9899 * configuration/mode, 9900 * #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information 9901 * should be available for 9902 * the daemon, but cannot be provided 9903 * due to some error or other 9904 * reasons, 9905 * other error codes in case of other errors 9906 * @ingroup specialized 9907 */ 9908 #define MHD_daemon_get_info_dynamic(daemon,info_type,output_buf) \ 9909 MHD_daemon_get_info_dynamic_sz ((daemon), (info_type), (output_buf), \ 9910 sizeof(*(output_buf))) 9911 9912 9913 /** 9914 * Select which fixed information about connection is desired. 9915 * This information is not changed during the lifetime of the connection. 9916 */ 9917 enum MHD_ConnectionInfoFixedType 9918 { 9919 /** 9920 * Get the network address of the client. 9921 * If the connection does not have known remote address (was not provided 9922 * by the system or by the application in case of externally added 9923 * connection) then error code #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE is 9924 * returned if connection is IP type or unknown type or error code 9925 * #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if connection type is non-IP. 9926 * The @a sa pointer is never NULL if the function succeed (#MHD_SC_OK 9927 * returned). 9928 * The result is placed in @a v_client_address_sa_info member. 9929 * @ingroup request 9930 */ 9931 MHD_CONNECTION_INFO_FIXED_CLIENT_ADDRESS = 1 9932 , 9933 /** 9934 * Get the file descriptor for the connection socket. 9935 * The provided socket must be used as 'read-only': only select() or similar 9936 * functions should be used. Any modifications (changing socket attributes, 9937 * calling send() or recv(), closing it etc.) will lead to undefined 9938 * behaviour. 9939 * The result is placed in @a v_connection_socket member. 9940 * @ingroup request 9941 */ 9942 MHD_CONNECTION_INFO_FIXED_CONNECTION_SOCKET = 2 9943 , 9944 /** 9945 * Get the `struct MHD_Daemon *` responsible for managing this connection. 9946 * The result is placed in @a v_daemon member. 9947 * @ingroup request 9948 */ 9949 MHD_CONNECTION_INFO_FIXED_DAEMON = 20 9950 , 9951 /** 9952 * Returns the pointer to a variable pointing to connection-specific 9953 * application context data that was (possibly) set during 9954 * a #MHD_NotifyConnectionCallback or provided via @a connection_cntx 9955 * parameter of #MHD_daemon_add_connection(). 9956 * By using provided pointer application may get or set the pointer to 9957 * any data specific for the particular connection. 9958 * Note: resulting data is NOT the context pointer itself. 9959 * The result is placed in @a v_app_context_ppvoid member. 9960 * @ingroup request 9961 */ 9962 MHD_CONNECTION_INFO_FIXED_APP_CONTEXT = 30 9963 , 9964 9965 /* * Sentinel * */ 9966 /** 9967 * The sentinel value. 9968 * This value enforces specific underlying integer type for the enum. 9969 * Do not use. 9970 */ 9971 MHD_CONNECTION_INFO_FIXED_SENTINEL = 65535 9972 }; 9973 9974 /** 9975 * Socket address information data 9976 */ 9977 struct MHD_ConnInfoFixedSockAddr 9978 { 9979 /** 9980 * The size of the @a sa 9981 */ 9982 size_t sa_size; 9983 9984 /** 9985 * Socket Address type 9986 */ 9987 const struct sockaddr *sa; 9988 }; 9989 9990 /** 9991 * Information about a connection. 9992 */ 9993 union MHD_ConnectionInfoFixedData 9994 { 9995 9996 /** 9997 * The data for the #MHD_CONNECTION_INFO_FIXED_CLIENT_ADDRESS query 9998 */ 9999 struct MHD_ConnInfoFixedSockAddr v_client_address_sa_info; 10000 10001 /** 10002 * The data for the #MHD_CONNECTION_INFO_FIXED_CONNECTION_SOCKET query 10003 */ 10004 MHD_Socket v_connection_socket; 10005 10006 /** 10007 * The data for the #MHD_CONNECTION_INFO_FIXED_DAEMON query 10008 */ 10009 struct MHD_Daemon *v_daemon; 10010 10011 /** 10012 * The data for the #MHD_CONNECTION_INFO_FIXED_APP_CONTEXT query 10013 */ 10014 void **v_app_context_ppvoid; 10015 }; 10016 10017 10018 /** 10019 * Obtain fixed information about the given connection. 10020 * This information is not changed for the lifetime of the connection. 10021 * The wrapper macro #MHD_connection_get_info_fixed() may be more convenient. 10022 * 10023 * @param connection the connection to get information about 10024 * @param info_type the type of information requested 10025 * @param[out] output_buf the pointer to union to be set to the requested 10026 * information 10027 * @param output_buf_size the size of the memory area pointed by @a output_buf 10028 * (provided by the caller for storing the requested 10029 * information), in bytes 10030 * @return #MHD_SC_OK if succeed, 10031 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown, 10032 * #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information 10033 * is not available for this 10034 * connection due to the connection 10035 * configuration/mode, 10036 * #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information 10037 * should be available for 10038 * the connection, but cannot be 10039 * provided due to some error or 10040 * other reasons, 10041 * #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small, 10042 * other error codes in case of other errors 10043 * @ingroup specialized 10044 */ 10045 MHD_EXTERN_ enum MHD_StatusCode 10046 MHD_connection_get_info_fixed_sz ( 10047 struct MHD_Connection *MHD_RESTRICT connection, 10048 enum MHD_ConnectionInfoFixedType info_type, 10049 union MHD_ConnectionInfoFixedData *MHD_RESTRICT output_buf, 10050 size_t output_buf_size) 10051 MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1) 10052 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); 10053 10054 10055 /** 10056 * Obtain fixed information about the given connection. 10057 * This information is not changed for the lifetime of the connection. 10058 * 10059 * @param connection the connection to get information about 10060 * @param info_type the type of information requested 10061 * @param[out] output_buf the pointer to union to be set to the requested 10062 * information 10063 * @return #MHD_SC_OK if succeed, 10064 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown, 10065 * #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information 10066 * is not available for this 10067 * connection due to the connection 10068 * configuration/mode, 10069 * #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information 10070 * should be available for 10071 * the connection, but cannot be 10072 * provided due to some error or 10073 * other reasons, 10074 * other error codes in case of other errors 10075 * @ingroup specialized 10076 */ 10077 #define MHD_connection_get_info_fixed(connection,info_type,output_buf) \ 10078 MHD_connection_get_info_fixed_sz ((connection),(info_type), \ 10079 (output_buf), sizeof(*(output_buf))) 10080 10081 10082 /** 10083 * Select which dynamic information about connection is desired. 10084 * This information may be changed during the lifetime of the connection. 10085 */ 10086 enum MHD_ConnectionInfoDynamicType 10087 { 10088 /** 10089 * Get current version of HTTP protocol used for connection. 10090 * If connection is handling HTTP/1.x requests the function may return 10091 * error code #MHD_SC_TOO_EARLY if the full request line has not been received 10092 * yet for the current request. 10093 * The result is placed in @a v_http_ver member. 10094 * @ingroup request 10095 */ 10096 MHD_CONNECTION_INFO_DYNAMIC_HTTP_VER = 1 10097 , 10098 /** 10099 * Get connection timeout value. 10100 * This is the total number of milliseconds after which the idle 10101 * connection is automatically disconnected. 10102 * Note: the value set is NOT the number of milliseconds left before 10103 * automatic disconnection. 10104 * The result is placed in @a v_connection_timeout_uint32 member. 10105 * @ingroup request 10106 */ 10107 MHD_CONNECTION_INFO_DYNAMIC_CONNECTION_TIMEOUT_MILSEC = 10 10108 , 10109 /** 10110 * Check whether the connection is suspended. 10111 * The result is placed in @a v_connection_suspended_bool member. 10112 * @ingroup request 10113 */ 10114 MHD_CONNECTION_INFO_DYNAMIC_CONNECTION_SUSPENDED = 11 10115 , 10116 /** 10117 * Get current version of TLS transport protocol used for connection 10118 * If plain TCP connection is used then #MHD_TLS_VERSION_NO_TLS set in 10119 * the data. 10120 * It TLS handshake is not yet finished then error code #MHD_SC_TOO_EARLY is 10121 * returned. If TLS has failed or being closed then #MHD_SC_TOO_LATE error 10122 * code is returned. 10123 * If TLS version cannot be detected for any reason then error code 10124 * #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE is returned. 10125 * The result is placed in @a v_tls_ver member. 10126 * @ingroup request 10127 */ 10128 MHD_CONNECTION_INFO_DYNAMIC_TLS_VER = 105 10129 , 10130 /** 10131 * Get the TLS backend session handle. 10132 * If plain TCP connection is used then the function returns error code 10133 * #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE. 10134 * The resulting union has only one valid member. 10135 * The result is placed in @a v_tls_session member. 10136 * @ingroup request 10137 */ 10138 MHD_CONNECTION_INFO_DYNAMIC_TLS_SESSION = 140 10139 , 10140 10141 /* * Sentinel * */ 10142 /** 10143 * The sentinel value. 10144 * This value enforces specific underlying integer type for the enum. 10145 * Do not use. 10146 */ 10147 MHD_CONNECTION_INFO_DYNAMIC_SENTINEL = 65535 10148 }; 10149 10150 10151 /** 10152 * The versions of TLS protocol 10153 */ 10154 enum MHD_FIXED_ENUM_MHD_SET_ MHD_TlsVersion 10155 { 10156 10157 /** 10158 * No TLS / plain socket connection 10159 */ 10160 MHD_TLS_VERSION_NO_TLS = 0 10161 , 10162 /** 10163 * Not supported/failed to negotiate/failed to handshake TLS 10164 */ 10165 MHD_TLS_VERSION_BROKEN = 1 10166 , 10167 /** 10168 * TLS version 1.0 10169 */ 10170 MHD_TLS_VERSION_1_0 = 2 10171 , 10172 /** 10173 * TLS version 1.1 10174 */ 10175 MHD_TLS_VERSION_1_1 = 3 10176 , 10177 /** 10178 * TLS version 1.2 10179 */ 10180 MHD_TLS_VERSION_1_2 = 4 10181 , 10182 /** 10183 * TLS version 1.3 10184 */ 10185 MHD_TLS_VERSION_1_3 = 5 10186 , 10187 /** 10188 * Some unknown TLS version. 10189 * The TLS version is supported by TLS backend, but unknown to MHD. 10190 */ 10191 MHD_TLS_VERSION_UNKNOWN = 1999 10192 }; 10193 10194 /** 10195 * Connection TLS session information. 10196 * Only one member is valid. Use #MHD_DAEMON_INFO_FIXED_TLS_TYPE to find out 10197 * which member should be used. 10198 */ 10199 union MHD_ConnInfoDynamicTlsSess 10200 { 10201 /* Include <gnutls/gnutls.h> before this header to get a better type safety */ 10202 /** 10203 * GnuTLS session handle, of type "gnutls_session_t". 10204 */ 10205 #if defined(GNUTLS_VERSION_MAJOR) && GNUTLS_VERSION_MAJOR >= 3 10206 gnutls_session_t v_gnutls_session; 10207 #else 10208 void * /* gnutls_session_t */ v_gnutls_session; 10209 #endif 10210 10211 /* Include <openssl/types.h> or <openssl/crypto.h> before this header to get 10212 a better type safety */ 10213 /** 10214 * OpenSSL session handle, of type "SSL*". 10215 */ 10216 #if defined(OPENSSL_TYPES_H) && OPENSSL_VERSION_MAJOR >= 3 10217 SSL *v_openssl_session; 10218 #else 10219 void /* SSL */ *v_openssl_session; 10220 #endif 10221 10222 /* Include <mbedtls/ssl.h> before this header to get a better type safety */ 10223 /** 10224 * MbedTLS session handle, of type "mbedtls_ssl_context*". 10225 */ 10226 #if defined(MBEDTLS_SSL_H) 10227 mbedtls_ssl_context *v_mbedtls_session; 10228 #else 10229 void /* mbedtls_ssl_context */ *v_mbedtls_session; 10230 #endif 10231 }; 10232 10233 /** 10234 * Information about a connection. 10235 */ 10236 union MHD_ConnectionInfoDynamicData 10237 { 10238 /** 10239 * The data for the #MHD_CONNECTION_INFO_DYNAMIC_HTTP_VER query 10240 */ 10241 enum MHD_HTTP_ProtocolVersion v_http_ver; 10242 10243 /** 10244 * The data for the #MHD_CONNECTION_INFO_DYNAMIC_CONNECTION_TIMEOUT_MILSEC 10245 * query 10246 */ 10247 uint_fast32_t v_connection_timeout_uint32; 10248 10249 /** 10250 * The data for the #MHD_CONNECTION_INFO_DYNAMIC_CONNECTION_SUSPENDED query 10251 */ 10252 enum MHD_Bool v_connection_suspended_bool; 10253 10254 /** 10255 * The data for the #MHD_CONNECTION_INFO_DYNAMIC_CONNECTION_SUSPENDED query 10256 */ 10257 enum MHD_TlsVersion v_tls_ver; 10258 10259 /** 10260 * Connection TLS session information. 10261 * Only one member is valid. Use #MHD_DAEMON_INFO_FIXED_TLS_TYPE to find out 10262 * which member should be used. 10263 */ 10264 union MHD_ConnInfoDynamicTlsSess v_tls_session; 10265 }; 10266 10267 /** 10268 * Obtain dynamic information about the given connection. 10269 * This information may be changed during the lifetime of the connection. 10270 * 10271 * The wrapper macro #MHD_connection_get_info_dynamic() may be more convenient. 10272 * 10273 * @param connection the connection to get information about 10274 * @param info_type the type of information requested 10275 * @param[out] output_buf the pointer to union to be set to the requested 10276 * information 10277 * @param output_buf_size the size of the memory area pointed by @a output_buf 10278 * (provided by the caller for storing the requested 10279 * information), in bytes 10280 * @return #MHD_SC_OK if succeed, 10281 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown, 10282 * #MHD_SC_TOO_EARLY if the connection has not reached yet required 10283 * state, 10284 * #MHD_SC_TOO_LATE if the connection is already in state where 10285 * the requested information is not available, 10286 * #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information 10287 * is not available for this 10288 * connection due to the connection 10289 * configuration/mode, 10290 * #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small, 10291 * #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information 10292 * should be available for 10293 * the connection, but cannot be 10294 * provided due to some error or 10295 * other reasons, 10296 * other error codes in case of other errors 10297 * @ingroup specialized 10298 */ 10299 MHD_EXTERN_ enum MHD_StatusCode 10300 MHD_connection_get_info_dynamic_sz ( 10301 struct MHD_Connection *MHD_RESTRICT connection, 10302 enum MHD_ConnectionInfoDynamicType info_type, 10303 union MHD_ConnectionInfoDynamicData *MHD_RESTRICT output_buf, 10304 size_t output_buf_size) 10305 MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1) 10306 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); 10307 10308 10309 /** 10310 * Obtain dynamic information about the given connection. 10311 * This information may be changed during the lifetime of the connection. 10312 * 10313 * @param connection the connection to get information about 10314 * @param info_type the type of information requested 10315 * @param[out] output_buf the pointer to union to be set to the requested 10316 * information 10317 * @return #MHD_SC_OK if succeed, 10318 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown, 10319 * #MHD_SC_TOO_EARLY if the connection has not reached yet required 10320 * state, 10321 * #MHD_SC_TOO_LATE if the connection is already in state where 10322 * the requested information is not available, 10323 * #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information 10324 * is not available for this 10325 * connection due to the connection 10326 * configuration/mode, 10327 * #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information 10328 * should be available for 10329 * the connection, but cannot be 10330 * provided due to some error or 10331 * other reasons, 10332 * other error codes in case of other errors 10333 * @ingroup specialized 10334 */ 10335 #define MHD_connection_get_info_dynamic(connection,info_type,output_buf) \ 10336 MHD_connection_get_info_dynamic_sz ((connection),(info_type), \ 10337 (output_buf),sizeof(*(output_buf))) 10338 10339 10340 /** 10341 * Select which fixed information about stream is desired. 10342 * This information is not changed during the lifetime of the connection. 10343 */ 10344 enum MHD_FIXED_ENUM_APP_SET_ MHD_StreamInfoFixedType 10345 { 10346 /** 10347 * Get the `struct MHD_Daemon *` responsible for managing connection which 10348 * is responsible for this stream. 10349 * The result is placed in @a v_daemon member. 10350 * @ingroup request 10351 */ 10352 MHD_STREAM_INFO_FIXED_DAEMON = 20 10353 , 10354 /** 10355 * Get the `struct MHD_Connection *` responsible for managing this stream. 10356 * The result is placed in @a v_connection member. 10357 * @ingroup request 10358 */ 10359 MHD_STREAM_INFO_FIXED_CONNECTION = 21 10360 , 10361 10362 /* * Sentinel * */ 10363 /** 10364 * The sentinel value. 10365 * This value enforces specific underlying integer type for the enum. 10366 * Do not use. 10367 */ 10368 MHD_STREAM_INFO_FIXED_SENTINEL = 65535 10369 }; 10370 10371 10372 /** 10373 * Fixed information about a stream. 10374 */ 10375 union MHD_StreamInfoFixedData 10376 { 10377 /** 10378 * The data for the #MHD_STREAM_INFO_FIXED_DAEMON query 10379 */ 10380 struct MHD_Daemon *v_daemon; 10381 /** 10382 * The data for the #MHD_STREAM_INFO_FIXED_CONNECTION query 10383 */ 10384 struct MHD_Connection *v_connection; 10385 }; 10386 10387 10388 /** 10389 * Obtain fixed information about the given stream. 10390 * This information is not changed for the lifetime of the stream. 10391 * 10392 * The wrapper macro #MHD_stream_get_info_fixed() may be more convenient. 10393 * 10394 * @param stream the stream to get information about 10395 * @param info_type the type of information requested 10396 * @param[out] output_buf the pointer to union to be set to the requested 10397 * information 10398 * @param output_buf_size the size of the memory area pointed by @a output_buf 10399 * (provided by the caller for storing the requested 10400 * information), in bytes 10401 * @return #MHD_SC_OK if succeed, 10402 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown, 10403 * #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small, 10404 * other error codes in case of other errors 10405 * @ingroup specialized 10406 */ 10407 MHD_EXTERN_ enum MHD_StatusCode 10408 MHD_stream_get_info_fixed_sz ( 10409 struct MHD_Stream *MHD_RESTRICT stream, 10410 enum MHD_StreamInfoFixedType info_type, 10411 union MHD_StreamInfoFixedData *MHD_RESTRICT output_buf, 10412 size_t output_buf_size) 10413 MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1) 10414 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); 10415 10416 10417 /** 10418 * Obtain fixed information about the given stream. 10419 * This information is not changed for the lifetime of the tream. 10420 * 10421 * @param stream the stream to get information about 10422 * @param info_type the type of information requested 10423 * @param[out] output_buf the pointer to union to be set to the requested 10424 * information 10425 * @return #MHD_SC_OK if succeed, 10426 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown, 10427 * other error codes in case of other errors 10428 * @ingroup specialized 10429 */ 10430 #define MHD_stream_get_info_fixed(stream,info_type,output_buf) \ 10431 MHD_stream_get_info_fixed_sz ((stream),(info_type),(output_buf), \ 10432 sizeof(*(output_buf))) 10433 10434 10435 /** 10436 * Select which fixed information about stream is desired. 10437 * This information may be changed during the lifetime of the stream. 10438 */ 10439 enum MHD_FIXED_ENUM_APP_SET_ MHD_StreamInfoDynamicType 10440 { 10441 /** 10442 * Get the `struct MHD_Request *` for current request processed by the stream. 10443 * If no request is being processed, the error code #MHD_SC_TOO_EARLY is 10444 * returned. 10445 * The result is placed in @a v_request member. 10446 * @ingroup request 10447 */ 10448 MHD_STREAM_INFO_DYNAMIC_REQUEST = 20 10449 , 10450 10451 /* * Sentinel * */ 10452 /** 10453 * The sentinel value. 10454 * This value enforces specific underlying integer type for the enum. 10455 * Do not use. 10456 */ 10457 MHD_STREAM_INFO_DYNAMIC_SENTINEL = 65535 10458 }; 10459 10460 10461 /** 10462 * Dynamic information about stream. 10463 * This information may be changed during the lifetime of the connection. 10464 */ 10465 union MHD_StreamInfoDynamicData 10466 { 10467 /** 10468 * The data for the #MHD_STREAM_INFO_DYNAMIC_REQUEST query 10469 */ 10470 struct MHD_Request *v_request; 10471 }; 10472 10473 /** 10474 * Obtain dynamic information about the given stream. 10475 * This information may be changed during the lifetime of the stream. 10476 * 10477 * The wrapper macro #MHD_stream_get_info_dynamic() may be more convenient. 10478 * 10479 * @param stream the stream to get information about 10480 * @param info_type the type of information requested 10481 * @param[out] output_buf the pointer to union to be set to the requested 10482 * information 10483 * @param output_buf_size the size of the memory area pointed by @a output_buf 10484 * (provided by the caller for storing the requested 10485 * information), in bytes 10486 * @return #MHD_SC_OK if succeed, 10487 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown, 10488 * #MHD_SC_TOO_EARLY if the stream has not reached yet required state, 10489 * #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small, 10490 * other error codes in case of other errors 10491 * @ingroup specialized 10492 */ 10493 MHD_EXTERN_ enum MHD_StatusCode 10494 MHD_stream_get_info_dynamic_sz ( 10495 struct MHD_Stream *MHD_RESTRICT stream, 10496 enum MHD_StreamInfoDynamicType info_type, 10497 union MHD_StreamInfoDynamicData *MHD_RESTRICT output_buf, 10498 size_t output_buf_size) 10499 MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1) 10500 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); 10501 10502 10503 /** 10504 * Obtain dynamic information about the given stream. 10505 * This information may be changed during the lifetime of the stream. 10506 * 10507 * @param stream the stream to get information about 10508 * @param info_type the type of information requested 10509 * @param[out] output_buf the pointer to union to be set to the requested 10510 * information 10511 * @return #MHD_SC_OK if succeed, 10512 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown, 10513 * #MHD_SC_TOO_EARLY if the stream has not reached yet required state, 10514 * other error codes in case of other errors 10515 * @ingroup specialized 10516 */ 10517 #define MHD_stream_get_info_dynamic(stream,info_type,output_buf) \ 10518 MHD_stream_get_info_dynamic_sz ((stream),(info_type),(output_buf), \ 10519 sizeof(*(output_buf))) 10520 10521 10522 /** 10523 * Select which fixed information about request is desired. 10524 * This information is not changed during the lifetime of the request. 10525 */ 10526 enum MHD_FIXED_ENUM_APP_SET_ MHD_RequestInfoFixedType 10527 { 10528 /** 10529 * Get the version of HTTP protocol used for the request. 10530 * If request line has not been fully received yet then #MHD_SC_TOO_EARLY 10531 * error code is returned. 10532 * The result is placed in @a v_http_ver member. 10533 * @ingroup request 10534 */ 10535 MHD_REQUEST_INFO_FIXED_HTTP_VER = 1 10536 , 10537 /** 10538 * Get the HTTP method used for the request (as a enum). 10539 * The result is placed in @a v_http_method member. 10540 * @sa #MHD_REQUEST_INFO_DYNAMIC_HTTP_METHOD_STR 10541 * @ingroup request 10542 */ 10543 MHD_REQUEST_INFO_FIXED_HTTP_METHOD = 2 10544 , 10545 /** 10546 * Return MHD daemon to which the request belongs to. 10547 * The result is placed in @a v_daemon member. 10548 */ 10549 MHD_REQUEST_INFO_FIXED_DAEMON = 20 10550 , 10551 /** 10552 * Return which connection is associated with the stream which is associated 10553 * with the request. 10554 * The result is placed in @a v_connection member. 10555 */ 10556 MHD_REQUEST_INFO_FIXED_CONNECTION = 21 10557 , 10558 /** 10559 * Return which stream the request is associated with. 10560 * The result is placed in @a v_stream member. 10561 */ 10562 MHD_REQUEST_INFO_FIXED_STREAM = 22 10563 , 10564 /** 10565 * Returns the pointer to a variable pointing to request-specific 10566 * application context data. The same data is provided for 10567 * #MHD_EarlyUriLogCallback and #MHD_RequestTerminationCallback. 10568 * By using provided pointer application may get or set the pointer to 10569 * any data specific for the particular request. 10570 * Note: resulting data is NOT the context pointer itself. 10571 * The result is placed in @a v_app_context_ppvoid member. 10572 * @ingroup request 10573 */ 10574 MHD_REQUEST_INFO_FIXED_APP_CONTEXT = 30 10575 , 10576 10577 /* * Sentinel * */ 10578 /** 10579 * The sentinel value. 10580 * This value enforces specific underlying integer type for the enum. 10581 * Do not use. 10582 */ 10583 MHD_REQUEST_INFO_FIXED_SENTINEL = 65535 10584 }; 10585 10586 10587 /** 10588 * Fixed information about a request. 10589 */ 10590 union MHD_RequestInfoFixedData 10591 { 10592 10593 /** 10594 * The data for the #MHD_REQUEST_INFO_FIXED_HTTP_VER query 10595 */ 10596 enum MHD_HTTP_ProtocolVersion v_http_ver; 10597 10598 /** 10599 * The data for the #MHD_REQUEST_INFO_FIXED_HTTP_METHOD query 10600 */ 10601 enum MHD_HTTP_Method v_http_method; 10602 10603 /** 10604 * The data for the #MHD_REQUEST_INFO_FIXED_DAEMON query 10605 */ 10606 struct MHD_Daemon *v_daemon; 10607 10608 /** 10609 * The data for the #MHD_REQUEST_INFO_FIXED_CONNECTION query 10610 */ 10611 struct MHD_Connection *v_connection; 10612 10613 /** 10614 * The data for the #MHD_REQUEST_INFO_FIXED_STREAM query 10615 */ 10616 struct MHD_Stream *v_stream; 10617 10618 /** 10619 * The data for the #MHD_REQUEST_INFO_FIXED_APP_CONTEXT query 10620 */ 10621 void **v_app_context_ppvoid; 10622 }; 10623 10624 /** 10625 * Obtain fixed information about the given request. 10626 * This information is not changed for the lifetime of the request. 10627 * 10628 * The wrapper macro #MHD_request_get_info_fixed() may be more convenient. 10629 * 10630 * @param request the request to get information about 10631 * @param info_type the type of information requested 10632 * @param[out] output_buf the pointer to union to be set to the requested 10633 * information 10634 * @param output_buf_size the size of the memory area pointed by @a output_buf 10635 * (provided by the caller for storing the requested 10636 * information), in bytes 10637 * @return #MHD_SC_OK if succeed, 10638 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown, 10639 * #MHD_SC_TOO_EARLY if the request processing has not reached yet 10640 * the required state, 10641 * #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small, 10642 * other error codes in case of other errors 10643 * @ingroup specialized 10644 */ 10645 MHD_EXTERN_ enum MHD_StatusCode 10646 MHD_request_get_info_fixed_sz ( 10647 struct MHD_Request *MHD_RESTRICT request, 10648 enum MHD_RequestInfoFixedType info_type, 10649 union MHD_RequestInfoFixedData *MHD_RESTRICT output_buf, 10650 size_t output_buf_size) 10651 MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1) 10652 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); 10653 10654 10655 /** 10656 * Obtain fixed information about the given request. 10657 * This information is not changed for the lifetime of the request. 10658 * 10659 * @param request the request to get information about 10660 * @param info_type the type of information requested 10661 * @param[out] output_buf the pointer to union to be set to the requested 10662 * information 10663 * @return #MHD_SC_OK if succeed, 10664 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown, 10665 * #MHD_SC_TOO_EARLY if the request processing has not reached yet 10666 * the required state, 10667 * other error codes in case of other errors 10668 * @ingroup specialized 10669 */ 10670 #define MHD_request_get_info_fixed(request,info_type,output_buf) \ 10671 MHD_request_get_info_fixed_sz ((request), (info_type), (output_buf), \ 10672 sizeof(*(output_buf))) 10673 10674 10675 /** 10676 * Select which dynamic information about request is desired. 10677 * This information may be changed during the lifetime of the request. 10678 * Any returned string pointers are valid only until a response is provided. 10679 */ 10680 enum MHD_FIXED_ENUM_APP_SET_ MHD_RequestInfoDynamicType 10681 { 10682 /** 10683 * Get the HTTP method used for the request (as a MHD_String). 10684 * The resulting string pointer in valid only until a response is provided. 10685 * The result is placed in @a v_http_method_string member. 10686 * @sa #MHD_REQUEST_INFO_FIXED_HTTP_METHOD 10687 * @ingroup request 10688 */ 10689 MHD_REQUEST_INFO_DYNAMIC_HTTP_METHOD_STRING = 1 10690 , 10691 /** 10692 * Get the URI used for the request (as a MHD_String), excluding 10693 * the parameter part (anything after '?'). 10694 * The resulting string pointer in valid only until a response is provided. 10695 * The result is placed in @a v_uri_string member. 10696 * @ingroup request 10697 */ 10698 MHD_REQUEST_INFO_DYNAMIC_URI = 2 10699 , 10700 /** 10701 * Get the number of URI parameters (the decoded part of the original 10702 * URI string after '?'). Sometimes it is called "GET parameters". 10703 * The result is placed in @a v_number_uri_params_sizet member. 10704 * @ingroup request 10705 */ 10706 MHD_REQUEST_INFO_DYNAMIC_NUMBER_URI_PARAMS = 3 10707 , 10708 /** 10709 * Get the number of cookies in the request. 10710 * The result is placed in @a v_number_cookies_sizet member. 10711 * If cookies parsing is disabled in MHD build then the function returns 10712 * error code #MHD_SC_FEATURE_DISABLED. 10713 * If cookies parsing is disabled this daemon then the function returns 10714 * error code #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE. 10715 * @ingroup request 10716 */ 10717 MHD_REQUEST_INFO_DYNAMIC_NUMBER_COOKIES = 4 10718 , 10719 /** 10720 * Return length of the client's HTTP request header. 10721 * This is a total raw size of the header (after TLS decipher if any) 10722 * The result is placed in @a v_header_size_sizet member. 10723 * @ingroup request 10724 */ 10725 MHD_REQUEST_INFO_DYNAMIC_HEADER_SIZE = 5 10726 , 10727 /** 10728 * Get the number of decoded POST entries in the request. 10729 * The result is placed in @a v_number_post_params_sizet member. 10730 * @ingroup request 10731 */ 10732 MHD_REQUEST_INFO_DYNAMIC_NUMBER_POST_PARAMS = 6 10733 , 10734 /** 10735 * Get whether the upload content is present in the request. 10736 * The result is #MHD_YES if any upload content is present, even 10737 * if the upload content size is zero. 10738 * The result is placed in @a v_upload_present_bool member. 10739 * @ingroup request 10740 */ 10741 MHD_REQUEST_INFO_DYNAMIC_UPLOAD_PRESENT = 10 10742 , 10743 /** 10744 * Get whether the chunked upload content is present in the request. 10745 * The result is #MHD_YES if chunked upload content is present. 10746 * The result is placed in @a v_upload_chunked_bool member. 10747 * @ingroup request 10748 */ 10749 MHD_REQUEST_INFO_DYNAMIC_UPLOAD_CHUNKED = 11 10750 , 10751 /** 10752 * Get the total content upload size. 10753 * Resulted in zero if no content upload or upload content size is zero, 10754 * #MHD_SIZE_UNKNOWN if size is not known (chunked upload). 10755 * The result is placed in @a v_upload_size_total_uint64 member. 10756 * @ingroup request 10757 */ 10758 MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_TOTAL = 12 10759 , 10760 /** 10761 * Get the total size of the content upload already received from the client. 10762 * This is the total size received, could be not yet fully processed by the 10763 * application. 10764 * The result is placed in @a v_upload_size_recieved_uint64 member. 10765 * @ingroup request 10766 */ 10767 MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_RECIEVED = 13 10768 , 10769 /** 10770 * Get the total size of the content upload left to be received from 10771 * the client. 10772 * Resulted in #MHD_SIZE_UNKNOWN if total size is not known (chunked upload). 10773 * The result is placed in @a v_upload_size_to_recieve_uint64 member. 10774 * @ingroup request 10775 */ 10776 MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_TO_RECIEVE = 14 10777 , 10778 /** 10779 * Get the total size of the content upload already processed (upload callback 10780 * called and completed (if any)). 10781 * If the value is requested from #MHD_UploadCallback, then result does NOT 10782 * include the current data being processed by the callback. 10783 * The result is placed in @a v_upload_size_processed_uint64 member. 10784 * @ingroup request 10785 */ 10786 MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_PROCESSED = 15 10787 , 10788 /** 10789 * Get the total size of the content upload left to be processed. 10790 * The resulting value includes the size of the data not yet received from 10791 * the client. 10792 * If the value is requested from #MHD_UploadCallback, then result includes 10793 * the current data being processed by the callback. 10794 * Resulted in #MHD_SIZE_UNKNOWN if total size is not known (chunked upload). 10795 * The result is placed in @a v_upload_size_to_process_uint64 member. 10796 * @ingroup request 10797 */ 10798 MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_TO_PROCESS = 16 10799 , 10800 /** 10801 * Returns pointer to information about digest auth in client request. 10802 * The resulting pointer is NULL if no digest auth header is set by 10803 * the client or the format of the digest auth header is broken. 10804 * Pointers in the returned structure (if any) are valid until response 10805 * is provided for the request. 10806 * The result is placed in @a v_auth_digest_info member. 10807 */ 10808 MHD_REQUEST_INFO_DYNAMIC_AUTH_DIGEST_INFO = 42 10809 , 10810 /** 10811 * Returns information about Basic Authentication credentials in the request. 10812 * Pointers in the returned structure (if any) are valid until any MHD_Action 10813 * or MHD_UploadAction is provided. If the data is needed beyond this point, 10814 * it should be copied. 10815 * If #MHD_request_get_info_dynamic_sz() returns #MHD_SC_OK then 10816 * @a v_auth_basic_creds is NOT NULL and at least the username data 10817 * is provided. 10818 * The result is placed in @a v_auth_basic_creds member. 10819 */ 10820 MHD_REQUEST_INFO_DYNAMIC_AUTH_BASIC_CREDS = 51 10821 , 10822 /* * Sentinel * */ 10823 /** 10824 * The sentinel value. 10825 * This value enforces specific underlying integer type for the enum. 10826 * Do not use. 10827 */ 10828 MHD_REQUEST_INFO_DYNAMIC_SENTINEL = 65535 10829 }; 10830 10831 10832 /** 10833 * Dynamic information about a request. 10834 */ 10835 union MHD_RequestInfoDynamicData 10836 { 10837 10838 /** 10839 * The data for the #MHD_REQUEST_INFO_DYNAMIC_HTTP_METHOD_STRING query 10840 */ 10841 struct MHD_String v_http_method_string; 10842 10843 /** 10844 * The data for the #MHD_REQUEST_INFO_DYNAMIC_URI query 10845 */ 10846 struct MHD_String v_uri_string; 10847 10848 /** 10849 * The data for the #MHD_REQUEST_INFO_DYNAMIC_NUMBER_URI_PARAMS query 10850 */ 10851 size_t v_number_uri_params_sizet; 10852 10853 /** 10854 * The data for the #MHD_REQUEST_INFO_DYNAMIC_NUMBER_COOKIES query 10855 */ 10856 size_t v_number_cookies_sizet; 10857 10858 /** 10859 * The data for the #MHD_REQUEST_INFO_DYNAMIC_HEADER_SIZE query 10860 */ 10861 size_t v_header_size_sizet; 10862 10863 /** 10864 * The data for the #MHD_REQUEST_INFO_DYNAMIC_NUMBER_POST_PARAMS query 10865 */ 10866 size_t v_number_post_params_sizet; 10867 10868 /** 10869 * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_PRESENT query 10870 */ 10871 enum MHD_Bool v_upload_present_bool; 10872 10873 /** 10874 * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_CHUNKED query 10875 */ 10876 enum MHD_Bool v_upload_chunked_bool; 10877 10878 /** 10879 * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_TOTAL query 10880 */ 10881 uint_fast64_t v_upload_size_total_uint64; 10882 10883 /** 10884 * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_RECIEVED query 10885 */ 10886 uint_fast64_t v_upload_size_recieved_uint64; 10887 10888 /** 10889 * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_TO_RECIEVE query 10890 */ 10891 uint_fast64_t v_upload_size_to_recieve_uint64; 10892 10893 /** 10894 * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_PROCESSED query 10895 */ 10896 uint_fast64_t v_upload_size_processed_uint64; 10897 10898 /** 10899 * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_TO_PROCESS query 10900 */ 10901 uint_fast64_t v_upload_size_to_process_uint64; 10902 10903 /** 10904 * The data for the #MHD_REQUEST_INFO_DYNAMIC_AUTH_DIGEST_INFO query 10905 */ 10906 const struct MHD_AuthDigestInfo *v_auth_digest_info; 10907 10908 /** 10909 * The data for the #MHD_REQUEST_INFO_DYNAMIC_AUTH_BASIC_CREDS query 10910 */ 10911 const struct MHD_AuthBasicCreds *v_auth_basic_creds; 10912 }; 10913 10914 10915 /** 10916 * Obtain dynamic information about the given request. 10917 * This information may be changed during the lifetime of the request. 10918 * Most of the data provided is available only when the request line or complete 10919 * request headers are processed and not available if responding has been 10920 * started. 10921 * 10922 * The wrapper macro #MHD_request_get_info_dynamic() may be more convenient. 10923 * 10924 * Any pointers in the returned data are valid until any MHD_Action or 10925 * MHD_UploadAction is provided. If the data is needed beyond this point, 10926 * it should be copied. 10927 * 10928 * @param request the request to get information about 10929 * @param info_type the type of information requested 10930 * @param[out] output_buf the pointer to union to be set to the requested 10931 * information 10932 * @param output_buf_size the size of the memory area pointed by @a output_buf 10933 * (provided by the caller for storing the requested 10934 * information), in bytes 10935 * @return #MHD_SC_OK if succeed, 10936 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if requested information type is 10937 * not recognized by MHD, 10938 * #MHD_SC_TOO_LATE if request is already being closed or the response 10939 * is being sent 10940 * #MHD_SC_TOO_EARLY if requested data is not yet ready (for example, 10941 * headers are not yet received), 10942 * #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information is 10943 * not available for this request 10944 * due to used configuration/mode, 10945 * #MHD_SC_FEATURE_DISABLED if requested functionality is not supported 10946 * by this MHD build, 10947 * #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small, 10948 * #MHD_SC_AUTH_ABSENT if request does not have particular Auth data, 10949 * #MHD_SC_CONNECTION_POOL_NO_MEM_AUTH_DATA if connection memory pool 10950 * has no space to put decoded 10951 * authentication data, 10952 * #MHD_SC_REQ_AUTH_DATA_BROKEN if the format of authentication data is 10953 * incorrect or broken, 10954 * other error codes in case of other errors 10955 * @ingroup specialized 10956 */ 10957 MHD_EXTERN_ enum MHD_StatusCode 10958 MHD_request_get_info_dynamic_sz ( 10959 struct MHD_Request *MHD_RESTRICT request, 10960 enum MHD_RequestInfoDynamicType info_type, 10961 union MHD_RequestInfoDynamicData *MHD_RESTRICT output_buf, 10962 size_t output_buf_size) 10963 MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1) 10964 MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); 10965 10966 10967 /** 10968 * Obtain dynamic information about the given request. 10969 * This information may be changed during the lifetime of the request. 10970 * Most of the data provided is available only when the request line or complete 10971 * request headers are processed and not available if responding has been 10972 * started. 10973 * 10974 * Any pointers in the returned data are valid until any MHD_Action or 10975 * MHD_UploadAction is provided. If the data is needed beyond this point, 10976 * it should be copied. 10977 * 10978 * @param request the request to get information about 10979 * @param info_type the type of information requested 10980 * @param[out] output_buf the pointer to union to be set to the requested 10981 * information 10982 * @return #MHD_SC_OK if succeed, 10983 * #MHD_SC_INFO_GET_TYPE_UNKNOWN if requested information type is 10984 * not recognized by MHD, 10985 * #MHD_SC_TOO_LATE if request is already being closed or the response 10986 * is being sent 10987 * #MHD_SC_TOO_EARLY if requested data is not yet ready (for example, 10988 * headers are not yet received), 10989 * #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information is 10990 * not available for this request 10991 * due to used configuration/mode, 10992 * #MHD_SC_FEATURE_DISABLED if requested functionality is not supported 10993 * by this MHD build, 10994 * #MHD_SC_AUTH_ABSENT if request does not have particular Auth data, 10995 * #MHD_SC_CONNECTION_POOL_NO_MEM_AUTH_DATA if connection memory pool 10996 * has no space to put decoded 10997 * authentication data, 10998 * #MHD_SC_REQ_AUTH_DATA_BROKEN if the format of authentication data is 10999 * incorrect or broken, 11000 * other error codes in case of other errors 11001 * @ingroup specialized 11002 */ 11003 #define MHD_request_get_info_dynamic(request,info_type,output_buf) \ 11004 MHD_request_get_info_dynamic_sz ((request), (info_type), \ 11005 (output_buf), \ 11006 sizeof(*(output_buf))) 11007 11008 /** 11009 * Callback for serious error condition. The default action is to print 11010 * an error message and `abort()`. 11011 * The callback should not return. 11012 * Some parameters could be empty strings (the strings with zero-termination at 11013 * zero position) if MHD built without log messages (only for embedded 11014 * projects). 11015 * 11016 * @param cls user specified value 11017 * @param file where the error occurred, could be empty 11018 * @param func the name of the function, where the error occurred, may be empty 11019 * @param line where the error occurred 11020 * @param message the error details, could be empty 11021 * @ingroup logging 11022 */ 11023 typedef void 11024 (*MHD_PanicCallback) (void *cls, 11025 const char *file, 11026 const char *func, 11027 unsigned int line, 11028 const char *message); 11029 11030 11031 /** 11032 * Sets the global error handler to a different implementation. 11033 * The @a cb will only be called in the case of typically fatal, serious 11034 * internal consistency issues. 11035 * These issues should only arise in the case of serious memory corruption or 11036 * similar problems with the architecture. 11037 * The @a cb should not return. 11038 * 11039 * The default implementation that is used if no panic function is set 11040 * simply prints an error message and calls `abort()`. Alternative 11041 * implementations might call `exit()` or other similar functions. 11042 * 11043 * @param cb new error handler, NULL to reset to default handler 11044 * @param cls passed to @a cb 11045 * @ingroup logging 11046 */ 11047 MHD_EXTERN_ void 11048 MHD_lib_set_panic_func (MHD_PanicCallback cb, 11049 void *cls); 11050 11051 #define MHD_lib_set_panic_func_default() \ 11052 MHD_lib_set_panic_func (MHD_STATIC_CAST_ (MHD_PanicCallback,NULL),NULL) 11053 MHD_C_DECLARATIONS_FINISH_HERE_ 11054 11055 #endif /* ! MICROHTTPD2_H */