libtest.h (25642B)
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) 2024 Christian Grothoff 5 6 GNU libmicrohttpd is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Lesser General Public 8 License as published by the Free Software Foundation; either 9 version 2.1 of the License, or (at your option) any later version. 10 11 GNU libmicrohttpd is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Lesser General Public License for more details. 15 16 Alternatively, you can redistribute GNU libmicrohttpd and/or 17 modify it under the terms of the GNU General Public License as 18 published by the Free Software Foundation; either version 2 of 19 the License, or (at your option) any later version, together 20 with the eCos exception, as follows: 21 22 As a special exception, if other files instantiate templates or 23 use macros or inline functions from this file, or you compile this 24 file and link it with other works to produce a work based on this 25 file, this file does not by itself cause the resulting work to be 26 covered by the GNU General Public License. However the source code 27 for this file must still be made available in accordance with 28 section (3) of the GNU General Public License v2. 29 30 This exception does not invalidate any other reasons why a work 31 based on this file might be covered by the GNU General Public 32 License. 33 34 You should have received copies of the GNU Lesser General Public 35 License and the GNU General Public License along with this library; 36 if not, see <https://www.gnu.org/licenses/>. 37 */ 38 39 /** 40 * @file libtest.h 41 * @brief testing harness with clients against server 42 * @author Christian Grothoff 43 */ 44 #ifndef LIBTEST_H 45 #define LIBTEST_H 46 47 #include "mhd_sys_options.h" 48 #include <stdio.h> 49 #include <stdlib.h> 50 #include <string.h> 51 #ifdef HAVE_STDBOOL_H 52 # include <stdbool.h> 53 #endif 54 #include "microhttpd2.h" 55 56 57 /** 58 * A phase defines some server and client-side 59 * behaviors to execute. 60 */ 61 struct MHDT_Phase; 62 63 64 /** 65 * Information about the current phase. 66 */ 67 struct MHDT_PhaseContext 68 { 69 /** 70 * Base URL of the server 71 */ 72 const char *base_url; 73 74 /** 75 * Data structure to keep around during the request because 76 * Curl. 77 */ 78 struct curl_slist *hosts; 79 80 /** 81 * Specific client we are running. 82 */ 83 unsigned int client_id; 84 85 /** 86 * More details about the phase we are running. 87 */ 88 struct MHDT_Phase *phase; 89 90 }; 91 92 93 /** 94 * Function called to run some client logic against 95 * the server. 96 * 97 * @param cls closure 98 * @param pc context for the client 99 * @return error message, NULL on success 100 */ 101 typedef const char * 102 (*MHDT_ClientLogic)(const void *cls, 103 struct MHDT_PhaseContext *pc); 104 105 106 struct MHDT_Phase 107 { 108 109 /** 110 * Name of the phase, for debugging/logging. 111 */ 112 const char *label; 113 114 /** 115 * Logic for the MHD server for this phase. 116 */ 117 MHD_RequestCallback server_cb; 118 119 /** 120 * Closure for @e server_cb. 121 */ 122 void *server_cb_cls; 123 124 /** 125 * Logic for the CURL client for this phase. 126 */ 127 MHDT_ClientLogic client_cb; 128 129 /** 130 * Closure for @e client_cb. 131 */ 132 const void *client_cb_cls; 133 134 /** 135 * How long is the phase allowed to run at most before 136 * timing out. 0 for no timeout. 137 */ 138 unsigned int timeout_ms; 139 140 /** 141 * How many clients should be run in parallel. 142 * 0 to run just one client. 143 */ 144 unsigned int num_clients; 145 146 /** 147 * Set to true if clients should setup the connection to use TLS. 148 */ 149 bool use_tls; 150 151 /** 152 * Set to true if clients should check server cert. 153 */ 154 bool check_server_cert; 155 156 /** 157 * HTTP version to use. 0 = any (negotiated), 158 * 1 = HTTP/1.x, 2 = HTTP/2, 3 = HTTP/3. 159 */ 160 unsigned int http_version; 161 162 /** 163 * Client certificate to present to the server, NULL for none. 164 */ 165 const char *client_cert; 166 167 /** 168 * Client private key to use, NULL for none. 169 */ 170 const char *client_priv; 171 172 /** 173 * Server certificate to present to the client, NULL for default. 174 */ 175 const char *server_cert; 176 177 /** 178 * Server private key to use, NULL for default. 179 */ 180 const char *server_priv; 181 }; 182 183 184 /** 185 * Load PEM file from data/ folder and return data in it. 186 * 187 * @param name name of PEM file to load 188 * @return NULL on error 189 */ 190 char * 191 MHDT_load_pem (const char *name); 192 193 194 /** 195 * Run request against the root URL of the 196 * hostname given in @a cls. 197 * 198 * @param cls closure with hostname to use 199 * @param pc context for the client 200 * @return error message, NULL on success 201 */ 202 const char * 203 MHDT_client_get_host (const void *cls, 204 struct MHDT_PhaseContext *pc); 205 206 207 /** 208 * Run request against the base URL and expect the 209 * string in @a cls to be returned 210 * 211 * @param cls closure with text string to be returned 212 * @param pc context for the client 213 * @return error message, NULL on success 214 */ 215 const char * 216 MHDT_client_get_root (const void *cls, 217 struct MHDT_PhaseContext *pc); 218 219 220 /** 221 * Run request against the base URL with the 222 * query arguments from @a cls appended to it. 223 * Expect the server to return a 200 OK response. 224 * 225 * @param cls closure with query parameters to append 226 * to the base URL of the server 227 * @param pc context for the client 228 * @return error message, NULL on success 229 */ 230 const char * 231 MHDT_client_get_with_query (const void *cls, 232 struct MHDT_PhaseContext *pc); 233 234 235 /** 236 * Run request against the base URL with the 237 * custom header from @a cls set. 238 * Expect the server to return a 204 No content response. 239 * 240 * @param cls closure with custom header to set 241 * @param pc context for the client 242 * @return error message, NULL on success 243 */ 244 const char * 245 MHDT_client_set_header (const void *cls, 246 struct MHDT_PhaseContext *pc); 247 248 249 /** 250 * Run request against the base URL and expect the header from @a cls to be 251 * set in the 204 No content response. 252 * 253 * @param cls closure with custom header to set, 254 * must be of the format "$KEY:$VALUE" 255 * without space before the "$VALUE". 256 * @param pc context for the client 257 * @return error message, NULL on success 258 */ 259 const char * 260 MHDT_client_expect_header (const void *cls, 261 struct MHDT_PhaseContext *pc); 262 263 264 /** 265 * Run simple upload against the base URL and expect a 266 * 204 No Content response. 267 * 268 * @param cls 0-terminated string with data to PUT 269 * @param pc context for the client 270 * @return error message, NULL on success 271 */ 272 const char * 273 MHDT_client_put_data (const void *cls, 274 struct MHDT_PhaseContext *pc); 275 276 277 /** 278 * Run chunked upload against the base URL and expect a 279 * 204 No Content response. 280 * 281 * @param cls 0-terminated string with data to PUT 282 * @param pc context for the client 283 * @return error message, NULL on success 284 */ 285 const char * 286 MHDT_client_chunk_data (const void *cls, 287 struct MHDT_PhaseContext *pc); 288 289 290 /** 291 * Information about a result we expect from the PP. 292 */ 293 struct MHDT_PostWant 294 { 295 /** 296 * key for the result 297 */ 298 const char *key; 299 300 /** 301 * Value for the result. 302 */ 303 const char *value; 304 305 /** 306 * Filename attribute for the result, NULL for none. 307 */ 308 const char *filename; 309 310 /** 311 * Content type attribute for the result, NULL for none. 312 */ 313 const char *content_type; 314 315 /** 316 * Number of bytes in @a value, 0 if value is 0-terminated. 317 */ 318 size_t value_size; 319 320 /** 321 * Internal book-keeping for @e incremental processing. 322 */ 323 size_t value_off; 324 325 /** 326 * True if @e value may be transmitted incrementally. 327 */ 328 bool incremental; 329 330 /** 331 * Set to true if a matching record was returned. 332 */ 333 bool satisfied; 334 335 }; 336 337 338 /** 339 * Arguments and state for the #MHDT_server_reply_check_post and 340 * #MHDT_client_do_post() functions. 341 */ 342 struct MHDT_PostInstructions 343 { 344 /** 345 * Encoding to use when decoding. 346 */ 347 enum MHD_HTTP_PostEncoding enc; 348 349 /** 350 * Data to be POSTed to the server. 351 */ 352 const char *postdata; 353 354 /** 355 * HTTP header to set POST content encoding, use 356 * NULL if you want to set @e request_hdr directly. 357 */ 358 const char *postheader; 359 360 /** 361 * NULL-terminated array of expected POST data for 362 * the server. 363 */ 364 struct MHDT_PostWant *wants; 365 366 /** 367 * Number of bytes in @e postdata, use 0 for 368 * 0-terminated @e postdata. 369 */ 370 size_t postdata_size; 371 372 /** 373 * size to use for the buffer. 374 */ 375 size_t buffer_size; 376 377 /** 378 * Size above which we switch to stream processing. 379 */ 380 size_t auto_stream_size; 381 }; 382 383 384 /** 385 * Perform POST request suitable for testing the post processor and expect a 386 * 204 No Content response. 387 * 388 * Note that @a cls cannot be used by multiple commands 389 * simultaneously, so do not use this in concurrent 390 * tests aliasing @a cls. 391 * 392 * @param cls information what to post of type `struct MHDT_PostInstructions` 393 * @param pc context for the client 394 * @return error message, NULL on success 395 */ 396 const char * 397 MHDT_client_do_post ( 398 const void *cls, 399 struct MHDT_PhaseContext *pc); 400 401 402 /** 403 * Perform GET request and send some HTTP basic authentication header 404 * to authorize the request. 405 * 406 * @param cls a string with "$USERNAME:$PASSWORD" 407 * @param pc context for the client 408 * @return error message, NULL on success 409 */ 410 const char * 411 MHDT_client_send_basic_auth ( 412 const void *cls, 413 struct MHDT_PhaseContext *pc); 414 415 416 /** 417 * Perform GET request and send some HTTP basic authentication header 418 * to authorize the request. Expect authentication to fail. 419 * 420 * @param cls a string with "$USERNAME:$PASSWORD" 421 * @param pc context for the client 422 * @return error message, NULL on success 423 */ 424 const char * 425 MHDT_client_fail_basic_auth ( 426 const void *cls, 427 struct MHDT_PhaseContext *pc); 428 429 430 /** 431 * Perform GET request and send some HTTP digest authentication header 432 * to authorize the request. 433 * 434 * @param cls a string with "$USERNAME:$PASSWORD" 435 * @param pc context for the client 436 * @return error message, NULL on success 437 */ 438 const char * 439 MHDT_client_send_digest_auth ( 440 const void *cls, 441 struct MHDT_PhaseContext *pc); 442 443 444 /** 445 * Perform GET request and send some HTTP digest authentication header 446 * to authorize the request. Expect authentication to fail. 447 * 448 * @param cls a string with "$USERNAME:$PASSWORD" 449 * @param pc context for the client 450 * @return error message, NULL on success 451 */ 452 const char * 453 MHDT_client_fail_digest_auth ( 454 const void *cls, 455 struct MHDT_PhaseContext *pc); 456 457 458 /** 459 * Returns the text from @a cls as the response to any 460 * request. 461 * 462 * @param cls argument given together with the function 463 * pointer when the handler was registered with MHD 464 * @param request the request object 465 * @param path the requested uri (without arguments after "?") 466 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET, 467 * #MHD_HTTP_METHOD_PUT, etc.) 468 * @param upload_size the size of the message upload content payload, 469 * #MHD_SIZE_UNKNOWN for chunked uploads (if the 470 * final chunk has not been processed yet) 471 * @return action how to proceed, NULL 472 * if the request must be aborted due to a serious 473 * error while handling the request (implies closure 474 * of underling data stream, for HTTP/1.1 it means 475 * socket closure). 476 */ 477 const struct MHD_Action * 478 MHDT_server_reply_text ( 479 void *cls, 480 struct MHD_Request *MHD_RESTRICT request, 481 const struct MHD_String *MHD_RESTRICT path, 482 enum MHD_HTTP_Method method, 483 uint_fast64_t upload_size); 484 485 486 /** 487 * Returns the text from @a cls as the response to any 488 * request, but using chunks by returning @a cls 489 * word-wise (breaking into chunks at spaces). 490 * 491 * @param cls argument given together with the function 492 * pointer when the handler was registered with MHD 493 * @param request the request object 494 * @param path the requested uri (without arguments after "?") 495 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET, 496 * #MHD_HTTP_METHOD_PUT, etc.) 497 * @param upload_size the size of the message upload content payload, 498 * #MHD_SIZE_UNKNOWN for chunked uploads (if the 499 * final chunk has not been processed yet) 500 * @return action how to proceed, NULL 501 * if the request must be aborted due to a serious 502 * error while handling the request (implies closure 503 * of underling data stream, for HTTP/1.1 it means 504 * socket closure). 505 */ 506 const struct MHD_Action * 507 MHDT_server_reply_chunked_text ( 508 void *cls, 509 struct MHD_Request *MHD_RESTRICT request, 510 const struct MHD_String *MHD_RESTRICT path, 511 enum MHD_HTTP_Method method, 512 uint_fast64_t upload_size); 513 514 515 /** 516 * Returns writes text from @a cls to a temporary file 517 * and then uses the file descriptor to serve the 518 * content to the client. 519 * 520 * @param cls argument given together with the function 521 * pointer when the handler was registered with MHD 522 * @param request the request object 523 * @param path the requested uri (without arguments after "?") 524 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET, 525 * #MHD_HTTP_METHOD_PUT, etc.) 526 * @param upload_size the size of the message upload content payload, 527 * #MHD_SIZE_UNKNOWN for chunked uploads (if the 528 * final chunk has not been processed yet) 529 * @return action how to proceed, NULL 530 * if the request must be aborted due to a serious 531 * error while handling the request (implies closure 532 * of underling data stream, for HTTP/1.1 it means 533 * socket closure). 534 */ 535 const struct MHD_Action * 536 MHDT_server_reply_file ( 537 void *cls, 538 struct MHD_Request *MHD_RESTRICT request, 539 const struct MHD_String *MHD_RESTRICT path, 540 enum MHD_HTTP_Method method, 541 uint_fast64_t upload_size); 542 543 544 /** 545 * Returns an emtpy response with a custom header 546 * set from @a cls and the #MHD_HTTP_STATUS_NO_CONTENT. 547 * 548 * @param cls header in the format "$NAME:$VALUE" 549 * without a space before "$VALUE". 550 * @param request the request object 551 * @param path the requested uri (without arguments after "?") 552 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET, 553 * #MHD_HTTP_METHOD_PUT, etc.) 554 * @param upload_size the size of the message upload content payload, 555 * #MHD_SIZE_UNKNOWN for chunked uploads (if the 556 * final chunk has not been processed yet) 557 * @return action how to proceed, NULL 558 * if the request must be aborted due to a serious 559 * error while handling the request (implies closure 560 * of underling data stream, for HTTP/1.1 it means 561 * socket closure). 562 */ 563 const struct MHD_Action * 564 MHDT_server_reply_with_header ( 565 void *cls, 566 struct MHD_Request *MHD_RESTRICT request, 567 const struct MHD_String *MHD_RESTRICT path, 568 enum MHD_HTTP_Method method, 569 uint_fast64_t upload_size); 570 571 572 /** 573 * Checks that the request query arguments match the 574 * arguments given in @a cls. 575 * request. 576 * 577 * @param cls string with expected arguments separated by '&' and '='. URI encoding is NOT supported. 578 * @param request the request object 579 * @param path the requested uri (without arguments after "?") 580 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET, 581 * #MHD_HTTP_METHOD_PUT, etc.) 582 * @param upload_size the size of the message upload content payload, 583 * #MHD_SIZE_UNKNOWN for chunked uploads (if the 584 * final chunk has not been processed yet) 585 * @return action how to proceed, NULL 586 * if the request must be aborted due to a serious 587 * error while handling the request (implies closure 588 * of underling data stream, for HTTP/1.1 it means 589 * socket closure). 590 */ 591 const struct MHD_Action * 592 MHDT_server_reply_check_query ( 593 void *cls, 594 struct MHD_Request *MHD_RESTRICT request, 595 const struct MHD_String *MHD_RESTRICT path, 596 enum MHD_HTTP_Method method, 597 uint_fast64_t upload_size); 598 599 600 /** 601 * Checks that the client request includes the given 602 * custom header. If so, returns #MHD_HTTP_STATUS_NO_CONTENT. 603 * 604 * @param cls expected header with "$NAME:$VALUE" format. 605 * @param request the request object 606 * @param path the requested uri (without arguments after "?") 607 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET, 608 * #MHD_HTTP_METHOD_PUT, etc.) 609 * @param upload_size the size of the message upload content payload, 610 * #MHD_SIZE_UNKNOWN for chunked uploads (if the 611 * final chunk has not been processed yet) 612 * @return action how to proceed, NULL 613 * if the request must be aborted due to a serious 614 * error while handling the request (implies closure 615 * of underling data stream, for HTTP/1.1 it means 616 * socket closure). 617 */ 618 const struct MHD_Action * 619 MHDT_server_reply_check_header ( 620 void *cls, 621 struct MHD_Request *MHD_RESTRICT request, 622 const struct MHD_String *MHD_RESTRICT path, 623 enum MHD_HTTP_Method method, 624 uint_fast64_t upload_size); 625 626 627 /** 628 * Checks that the client request includes the given 629 * upload. If so, returns #MHD_HTTP_STATUS_NO_CONTENT. 630 * 631 * @param cls expected upload data as a 0-terminated string. 632 * @param request the request object 633 * @param path the requested uri (without arguments after "?") 634 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET, 635 * #MHD_HTTP_METHOD_PUT, etc.) 636 * @param upload_size the size of the message upload content payload, 637 * #MHD_SIZE_UNKNOWN for chunked uploads (if the 638 * final chunk has not been processed yet) 639 * @return action how to proceed, NULL 640 * if the request must be aborted due to a serious 641 * error while handling the request (implies closure 642 * of underling data stream, for HTTP/1.1 it means 643 * socket closure). 644 */ 645 const struct MHD_Action * 646 MHDT_server_reply_check_upload ( 647 void *cls, 648 struct MHD_Request *MHD_RESTRICT request, 649 const struct MHD_String *MHD_RESTRICT path, 650 enum MHD_HTTP_Method method, 651 uint_fast64_t upload_size); 652 653 654 /** 655 * Checks that the client request against the expected 656 * POST data. If so, returns #MHD_HTTP_STATUS_NO_CONTENT. 657 * 658 * Note that @a cls cannot be used by multiple commands 659 * simultaneously, so do not use this in concurrent 660 * tests aliasing @a cls. 661 * 662 * @param cls a `struct MHD_PostInstructions` 663 * @param request the request object 664 * @param path the requested uri (without arguments after "?") 665 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET, 666 * #MHD_HTTP_METHOD_PUT, etc.) 667 * @param upload_size the size of the message upload content payload, 668 * #MHD_SIZE_UNKNOWN for chunked uploads (if the 669 * final chunk has not been processed yet) 670 * @return action how to proceed, NULL 671 * if the request must be aborted due to a serious 672 * error while handling the request (implies closure 673 * of underling data stream, for HTTP/1.1 it means 674 * socket closure). 675 */ 676 const struct MHD_Action * 677 MHDT_server_reply_check_post ( 678 void *cls, 679 struct MHD_Request *MHD_RESTRICT request, 680 const struct MHD_String *MHD_RESTRICT path, 681 enum MHD_HTTP_Method method, 682 uint_fast64_t upload_size); 683 684 685 /** 686 * Checks that the client request includes the given 687 * username and password in HTTP basic authetnication. 688 * If so, returns #MHD_HTTP_STATUS_NO_CONTENT, otherwise 689 * an #MHD_HTTP_STATUS_UNAUTHORIZED. 690 * 691 * @param cls expected upload data as a 0-terminated string. 692 * @param request the request object 693 * @param path the requested uri (without arguments after "?") 694 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET, 695 * #MHD_HTTP_METHOD_PUT, etc.) 696 * @param upload_size the size of the message upload content payload, 697 * #MHD_SIZE_UNKNOWN for chunked uploads (if the 698 * final chunk has not been processed yet) 699 * @return action how to proceed, NULL 700 * if the request must be aborted due to a serious 701 * error while handling the request (implies closure 702 * of underling data stream, for HTTP/1.1 it means 703 * socket closure). 704 */ 705 const struct MHD_Action * 706 MHDT_server_reply_check_basic_auth ( 707 void *cls, 708 struct MHD_Request *MHD_RESTRICT request, 709 const struct MHD_String *MHD_RESTRICT path, 710 enum MHD_HTTP_Method method, 711 uint_fast64_t upload_size); 712 713 714 /** 715 * Checks that the client request includes the given 716 * username and password in HTTP digest authetnication. 717 * If so, returns #MHD_HTTP_STATUS_NO_CONTENT, otherwise 718 * an #MHD_HTTP_STATUS_UNAUTHORIZED. 719 * 720 * @param cls expected upload data as a 0-terminated string. 721 * @param request the request object 722 * @param path the requested uri (without arguments after "?") 723 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET, 724 * #MHD_HTTP_METHOD_PUT, etc.) 725 * @param upload_size the size of the message upload content payload, 726 * #MHD_SIZE_UNKNOWN for chunked uploads (if the 727 * final chunk has not been processed yet) 728 * @return action how to proceed, NULL 729 * if the request must be aborted due to a serious 730 * error while handling the request (implies closure 731 * of underling data stream, for HTTP/1.1 it means 732 * socket closure). 733 */ 734 const struct MHD_Action * 735 MHDT_server_reply_check_digest_auth ( 736 void *cls, 737 struct MHD_Request *MHD_RESTRICT request, 738 const struct MHD_String *MHD_RESTRICT path, 739 enum MHD_HTTP_Method method, 740 uint_fast64_t upload_size); 741 742 743 /** 744 * Initialize options for an MHD daemon for a test. 745 * 746 * @param cls closure 747 * @param[in,out] d daemon to initialize 748 * @return error message, NULL on success 749 */ 750 typedef const char * 751 (*MHDT_ServerSetup)(const void *cls, 752 struct MHD_Daemon *d); 753 754 755 /** 756 * Initialize MHD daemon without any special 757 * options, binding to any free port. 758 * 759 * @param cls closure 760 * @param[in,out] d daemon to initialize 761 * @return error message, NULL on success 762 */ 763 const char * 764 MHDT_server_setup_minimal (const void *cls, 765 struct MHD_Daemon *d); 766 767 768 /** 769 * Initialize MHD daemon for an external event loop. 770 * Must be used together with #MHDT_server_run_external(). 771 * 772 * @param cls closure (use NULL) 773 * @param[in,out] d daemon to initialize 774 * @return error message, NULL on success 775 */ 776 const char * 777 MHDT_server_setup_external (const void *cls, 778 struct MHD_Daemon *d); 779 780 781 /** 782 * Initialize MHD daemon with TLS support, binding to any free port. 783 * 784 * @param cls closure 785 * @param[in,out] d daemon to initialize 786 * @return error message, NULL on success 787 */ 788 const char * 789 MHDT_server_setup_tls (const void *cls, 790 struct MHD_Daemon *d); 791 792 793 /** 794 * Initialize MHD daemon with TLS support using GnuTLS, binding to any free 795 * port. 796 * 797 * @param cls closure 798 * @param[in,out] d daemon to initialize 799 * @return error message, NULL on success 800 */ 801 const char * 802 MHDT_server_setup_gnutls (const void *cls, 803 struct MHD_Daemon *d); 804 805 806 /** 807 * Initialize MHD daemon with TLS support using OpenSSL, binding to any free 808 * port. 809 * 810 * @param cls closure 811 * @param[in,out] d daemon to initialize 812 * @return error message, NULL on success 813 */ 814 const char * 815 MHDT_server_setup_openssl (const void *cls, 816 struct MHD_Daemon *d); 817 818 819 /** 820 * Function that runs an MHD daemon until 821 * a read() against @a finsig succeeds. 822 * 823 * @param cls closure 824 * @param finsig fd to read from to detect termination request 825 * @param[in,out] d daemon to run 826 */ 827 typedef void 828 (*MHDT_ServerRunner)(void *cls, 829 int finsig, 830 struct MHD_Daemon *d); 831 832 833 /** 834 * Function that starts an MHD daemon with the 835 * simple #MHD_daemon_start() method until 836 * a read() against @a finsig succeeds. 837 * 838 * @param cls closure, pass a NULL-terminated (!) 839 * array of `struct MHD_DaemonOptionAndValue` with the 840 * the threading mode to use 841 * @param finsig fd to read from to detect termination request 842 * @param[in,out] d daemon to run 843 */ 844 void 845 MHDT_server_run_minimal (void *cls, 846 int finsig, 847 struct MHD_Daemon *d); 848 849 850 /** 851 * Function that runs an MHD daemon in blocking mode until 852 * a read() against @a finsig succeeds. 853 * 854 * @param cls closure 855 * @param finsig fd to read from to detect termination request 856 * @param[in,out] d daemon to run 857 */ 858 void 859 MHDT_server_run_blocking (void *cls, 860 int finsig, 861 struct MHD_Daemon *d); 862 863 864 /** 865 * Function that runs an MHD daemon with an external event loop until 866 * a read() against @a finsig succeeds. 867 * 868 * @param cls closure 869 * @param finsig fd to read from to detect termination request 870 * @param[in,out] d daemon to run 871 */ 872 void 873 MHDT_server_run_external (void *cls, 874 int finsig, 875 struct MHD_Daemon *d); 876 877 878 /** 879 * Run test suite with @a phases for a daemon initialized 880 * using @a ss_cb on the local machine. 881 * 882 * @param ss_cb setup logic for the daemon 883 * @param ss_cb_cls closure for @a ss_cb 884 * @param run_cb runs the daemon 885 * @param run_cb_cls closure for @a run_cb 886 * @param phases test phases to run in child processes 887 * @return 0 on success, 77 if test was skipped, 888 * error code otherwise 889 */ 890 int 891 MHDT_test (MHDT_ServerSetup ss_cb, 892 void *ss_cb_cls, 893 MHDT_ServerRunner run_cb, 894 void *run_cb_cls, 895 struct MHDT_Phase *phases); 896 897 #endif