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