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