選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

150 行
5.9 KiB

  1. #pragma once
  2. #include <microhttpd.h>
  3. #include <cppcore/misc/flags.h>
  4. #include <cppcore/misc/exception.h>
  5. namespace cppmicrohttpd
  6. {
  7. /**
  8. * @brief Flags to create the daemon with.
  9. */
  10. enum class daemon_flag
  11. : unsigned int
  12. {
  13. /**
  14. * Run in debug mode. If this flag is used, the library should print error messages and warnings to stderr.
  15. * Note that for this run-time option to have any effect, MHD needs to be compiled with messages enabled.
  16. * This is done by default except you ran configure with the --disable-messages flag set.
  17. */
  18. use_debug = MHD_USE_DEBUG,
  19. /**
  20. * Run in HTTPS-mode. If you specify MHD_USE_SSL and MHD was compiled without SSL support, MHD_start_daemon
  21. * will return NULL.
  22. */
  23. use_ssl = MHD_USE_SSL,
  24. /**
  25. * Run using one thread per connection.
  26. */
  27. use_thread_per_connection = MHD_USE_THREAD_PER_CONNECTION,
  28. /**
  29. * Run using an internal thread doing SELECT.
  30. */
  31. use_select_internally = MHD_USE_SELECT_INTERNALLY,
  32. /**
  33. * Run using the IPv6 protocol (otherwise, MHD will just support IPv4). If you specify MHD_USE_IPV6 and the
  34. * local platform does not support it, MHD_start_daemon will return NULL.
  35. *
  36. * If you want MHD to support IPv4 and IPv6 using a single socket, pass MHD_USE_DUAL_STACK, otherwise,
  37. * if you only pass this option, MHD will try to bind to IPv6-only (resulting in no IPv4 support).
  38. */
  39. use_ipv6 = MHD_USE_IPv6,
  40. /**
  41. * Use a single socket for IPv4 and IPv6. Note that this will mean that IPv4 addresses are returned by MHD in
  42. * the IPv6-mapped format (the ’struct sockaddr_in6’ format will be used for IPv4 and IPv6).
  43. */
  44. use_dual_stack = MHD_USE_DUAL_STACK,
  45. /**
  46. * Be pedantic about the protocol (as opposed to as tolerant as possible). Specifically, at the moment,
  47. * this flag causes MHD to reject HTTP 1.1 connections without a Host header. This is required by the standard,
  48. * but of course in violation of the “be as liberal as possible in what you accept” norm. It is recommended to
  49. * turn this ON if you are testing clients against MHD, and OFF in production.
  50. */
  51. use_pedantic_checks = MHD_USE_PEDANTIC_CHECKS,
  52. /**
  53. * Use poll() instead of select(). This allows sockets with descriptors >= ::cppcore::fdsetSIZE. This option currently only
  54. * works in conjunction with MHD_USE_THREAD_PER_CONNECTION or MHD_USE_INTERNAL_SELECT (at this point).
  55. * If you specify MHD_USE_POLL and the local platform does not support it, MHD_start_daemon will return NULL.
  56. */
  57. use_poll = MHD_USE_POLL,
  58. /**
  59. * Suppress (automatically) adding the ’Date:’ header to HTTP responses. This option should ONLY be used on
  60. * systems that do not have a clock and that DO provide other mechanisms for cache control.
  61. * See also RFC 2616, section 14.18 (exception 3).
  62. */
  63. supress_date_no_clock = MHD_SUPPRESS_DATE_NO_CLOCK,
  64. /**
  65. * Run the HTTP server without any listen socket. This option only makes sense if MHD_add_connection is going
  66. * to be used exclusively to connect HTTP clients to the HTTP server. This option is incompatible with using
  67. * a thread pool; if it is used, MHD_OPTION_THREAD_POOL_SIZE is ignored.
  68. */
  69. use_no_listen_socket = MHD_USE_NO_LISTEN_SOCKET,
  70. /**
  71. * Force MHD to use a signal pipe to notify the event loop (of threads) of our shutdown. This is required if
  72. * an appliction uses MHD_USE_INTERNAL_SELECT or MHD_USE_THREAD_PER_CONNECTION and then performs MHD_quiesce_daemon
  73. * (which eliminates our ability to signal termination via the listen socket). In these modes, MHD_quiesce_daemon
  74. * will fail if this option was not set. Also, use of this option is automatic (as in, you do not even have to
  75. * specify it), if MHD_USE_NO_LISTEN_SOCKET is specified. In "external" select mode, this option is always simply
  76. * ignored.
  77. *
  78. * Using this option also guarantees that MHD will not call shutdown() on the listen socket, which means a parent
  79. * process can continue to use the socket.
  80. */
  81. use_pipe_for_shutdown = MHD_USE_PIPE_FOR_SHUTDOWN,
  82. /**
  83. * Enables using MHD_suspend_connection and MHD_resume_connection, as performing these calls requires some additional
  84. * pipes to be created, and code not using these calls should not pay the cost.
  85. */
  86. use_suspend_resume = MHD_USE_SUSPEND_RESUME,
  87. /**
  88. * Enable TCP_FASTOPEN on the listen socket. TCP_FASTOPEN is currently supported on Linux >= 3.6. On other systems
  89. * using this option with cause MHD_start_daemon to fail.
  90. */
  91. use_tcp_fastopen = MHD_USE_TCP_FASTOPEN,
  92. };
  93. using daemon_flags = ::cppcore::simple_flags<daemon_flag>;
  94. /**
  95. * @brief Flag to indicate which callbacks should be registerd in MHC.
  96. */
  97. enum class callback_flag
  98. {
  99. };
  100. using callback_flags = ::cppcore::shifted_flags<callback_flag>;
  101. /**
  102. * @brief Exception with the error code and error string from the MHD library.
  103. */
  104. struct exception
  105. : public ::cppcore::exception
  106. {
  107. public:
  108. using ::cppcore::exception::exception;
  109. };
  110. struct http_exception
  111. : public ::cppcore::exception
  112. {
  113. uint status; //!< HTTP status code.
  114. /**
  115. * @brief Constructor.
  116. *
  117. * @param[in] p_status HTTP status code.
  118. * @param[in] p_message Actual error message.
  119. */
  120. inline http_exception(
  121. uint p_status,
  122. const std::string& p_message);
  123. };
  124. }
  125. #include "types.inl"