scheme.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // Copyright (c) 2019 Vinnie Falco ([email protected])
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/url
  8. //
  9. #ifndef BOOST_URL_SCHEME_HPP
  10. #define BOOST_URL_SCHEME_HPP
  11. #include <boost/url/detail/config.hpp>
  12. #include <boost/core/detail/string_view.hpp>
  13. #include <cinttypes>
  14. namespace boost {
  15. namespace urls {
  16. /* VFALCO NOTE The formatting of javadocs
  17. for enums is the way it is
  18. to work around an output bug in Doxygen!
  19. */
  20. /** Identifies a known URL scheme
  21. @par Specification
  22. @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.1"
  23. >3.1. Scheme (rfc3986)</a>
  24. */
  25. // Made this short so it doesn't
  26. // show up as an ascii character
  27. enum class scheme : unsigned short
  28. {
  29. /** Indicates that no scheme is present
  30. */
  31. none = 0,
  32. /** Indicates the scheme is not a well-known scheme
  33. */
  34. unknown,
  35. /**
  36. * File Transfer Protocol (FTP)
  37. FTP is a standard communication protocol
  38. used for the transfer of computer files
  39. from a server to a client on a computer
  40. network.
  41. @par Specification
  42. @li <a href="https://datatracker.ietf.org/doc/html/draft-yevstifeyev-ftp-uri-scheme">
  43. The 'ftp' URI Scheme</a>
  44. */
  45. ftp,
  46. /**
  47. * File URI Scheme
  48. The File URI Scheme is typically used
  49. to retrieve files from within one's
  50. own computer.
  51. @par Specification
  52. @li <a href="https://datatracker.ietf.org/doc/html/rfc8089">
  53. The "file" URI Scheme (rfc8089)</a>
  54. */
  55. file,
  56. /**
  57. * The Hypertext Transfer Protocol URI Scheme
  58. URLs of this type indicate a resource which
  59. is interacted with using the HTTP protocol.
  60. @par Specification
  61. @li <a href="https://datatracker.ietf.org/doc/html/rfc7230">
  62. Hypertext Transfer Protocol (HTTP/1.1) (rfc7230)</a>
  63. */
  64. http,
  65. /**
  66. * The Secure Hypertext Transfer Protocol URI Scheme
  67. URLs of this type indicate a resource which
  68. is interacted with using the Secure HTTP
  69. protocol.
  70. @par Specification
  71. @li <a href="https://datatracker.ietf.org/doc/html/rfc7230">
  72. Hypertext Transfer Protocol (HTTP/1.1) (rfc7230)</a>
  73. */
  74. https,
  75. /**
  76. * The WebSocket URI Scheme
  77. URLs of this type indicate a resource which
  78. is interacted with using the WebSocket protocol.
  79. @par Specification
  80. @li <a href="https://datatracker.ietf.org/doc/html/rfc6455">
  81. The WebSocket Protocol (rfc6455)</a>
  82. */
  83. ws,
  84. /**
  85. * The Secure WebSocket URI Scheme
  86. URLs of this type indicate a resource which
  87. is interacted with using the Secure WebSocket
  88. protocol.
  89. @par Specification
  90. @li <a href="https://datatracker.ietf.org/doc/html/rfc6455">
  91. The WebSocket Protocol (rfc6455)</a>
  92. */
  93. wss
  94. };
  95. /** Return the known scheme for a non-normalized string, if known
  96. If the string does not identify a known
  97. scheme, the value @ref scheme::unknown is
  98. returned.
  99. @par BNF
  100. @code
  101. scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  102. @endcode
  103. @return The known scheme
  104. @param s The string holding the scheme
  105. @par Specification
  106. @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.1"
  107. >3.1. Scheme (rfc3986)</a>
  108. */
  109. BOOST_URL_DECL
  110. scheme
  111. string_to_scheme(core::string_view s) noexcept;
  112. /** Return the normalized string for a known scheme
  113. @return A string representing the known scheme
  114. @param s The known scheme constant
  115. */
  116. BOOST_URL_DECL
  117. core::string_view
  118. to_string(scheme s) noexcept;
  119. /** Return the default port for a known scheme
  120. This function returns the default port
  121. for the known schemes. If the value does
  122. not represent a known scheme or the scheme
  123. does not represent a protocol, the function
  124. returns zero.
  125. The following ports are returned by the
  126. function:
  127. @li @ref scheme::ftp = 21
  128. @li @ref scheme::http, @ref scheme::ws = 80
  129. @li @ref scheme::https, @ref scheme::wss = 443
  130. @return An integer with the default port number
  131. @param s The known scheme constant
  132. */
  133. BOOST_URL_DECL
  134. std::uint16_t
  135. default_port(scheme s) noexcept;
  136. } // urls
  137. } // boost
  138. #endif