capabilities.hpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // Copyright (c) 2019-2024 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
  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. #ifndef BOOST_MYSQL_IMPL_INTERNAL_PROTOCOL_CAPABILITIES_HPP
  8. #define BOOST_MYSQL_IMPL_INTERNAL_PROTOCOL_CAPABILITIES_HPP
  9. #include <boost/config.hpp>
  10. #include <cstdint>
  11. namespace boost {
  12. namespace mysql {
  13. namespace detail {
  14. // Server/client capabilities
  15. // clang-format off
  16. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_LONG_PASSWORD = 1; // Use the improved version of Old Password Authentication
  17. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_FOUND_ROWS = 2; // Send found rows instead of affected rows in EOF_Packet
  18. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_LONG_FLAG = 4; // Get all column flags
  19. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_CONNECT_WITH_DB = 8; // Database (schema) name can be specified on connect in Handshake Response Packet
  20. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_NO_SCHEMA = 16; // Don't allow database.table.column
  21. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_COMPRESS = 32; // Compression protocol supported
  22. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_ODBC = 64; // Special handling of ODBC behavior
  23. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_LOCAL_FILES = 128; // Can use LOAD DATA LOCAL
  24. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_IGNORE_SPACE = 256; // Ignore spaces before '('
  25. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_PROTOCOL_41 = 512; // New 4.1 protocol
  26. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_INTERACTIVE = 1024; // This is an interactive client
  27. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_SSL = 2048; // Use SSL encryption for the session
  28. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_IGNORE_SIGPIPE = 4096; // Client only flag
  29. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_TRANSACTIONS = 8192; // Client knows about transactions
  30. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_RESERVED = 16384; // DEPRECATED: Old flag for 4.1 protocol
  31. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_SECURE_CONNECTION = 32768; // DEPRECATED: Old flag for 4.1 authentication, required by MariaDB
  32. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_MULTI_STATEMENTS = (1UL << 16); // Enable/disable multi-stmt support
  33. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_MULTI_RESULTS = (1UL << 17); // Enable/disable multi-results
  34. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_PS_MULTI_RESULTS = (1UL << 18); // Multi-results and OUT parameters in PS-protocol
  35. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_PLUGIN_AUTH = (1UL << 19); // Client supports plugin authentication
  36. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_CONNECT_ATTRS = (1UL << 20); // Client supports connection attributes
  37. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA = (1UL << 21); // Enable authentication response packet to be larger than 255 bytes
  38. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS = (1UL << 22); // Don't close the connection for a user account with expired password
  39. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_SESSION_TRACK = (1UL << 23); // Capable of handling server state change information
  40. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_DEPRECATE_EOF = (1UL << 24); // Client no longer needs EOF_Packet and will use OK_Packet instead
  41. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_SSL_VERIFY_SERVER_CERT = (1UL << 30); // Verify server certificate
  42. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_OPTIONAL_RESULTSET_METADATA = (1UL << 25); // The client can handle optional metadata information in the resultset
  43. BOOST_INLINE_CONSTEXPR std::uint32_t CLIENT_REMEMBER_OPTIONS = (1UL << 31); // Don't reset the options after an unsuccessful connect
  44. // clang-format on
  45. class capabilities
  46. {
  47. std::uint32_t value_;
  48. public:
  49. constexpr explicit capabilities(std::uint32_t value = 0) noexcept : value_(value){};
  50. constexpr std::uint32_t get() const noexcept { return value_; }
  51. void set(std::uint32_t value) noexcept { value_ = value; }
  52. constexpr bool has(std::uint32_t cap) const noexcept { return value_ & cap; }
  53. constexpr bool has_all(capabilities other) const noexcept
  54. {
  55. return (value_ & other.get()) == other.get();
  56. }
  57. constexpr capabilities operator|(capabilities rhs) const noexcept
  58. {
  59. return capabilities(value_ | rhs.value_);
  60. }
  61. constexpr capabilities operator&(capabilities rhs) const noexcept
  62. {
  63. return capabilities(value_ & rhs.value_);
  64. }
  65. constexpr bool operator==(const capabilities& rhs) const noexcept { return value_ == rhs.value_; }
  66. constexpr bool operator!=(const capabilities& rhs) const noexcept { return value_ != rhs.value_; }
  67. };
  68. /*
  69. * CLIENT_LONG_PASSWORD: unset // Use the improved version of Old Password Authentication
  70. * CLIENT_FOUND_ROWS: unset // Send found rows instead of affected rows in EOF_Packet
  71. * CLIENT_LONG_FLAG: unset // Get all column flags
  72. * CLIENT_CONNECT_WITH_DB: optional // Database (schema) name can be specified on connect in
  73. * Handshake Response Packet CLIENT_NO_SCHEMA: unset // Don't allow database.table.column
  74. * CLIENT_COMPRESS: unset // Compression protocol supported
  75. * CLIENT_ODBC: unset // Special handling of ODBC behavior
  76. * CLIENT_LOCAL_FILES: unset // Can use LOAD DATA LOCAL
  77. * CLIENT_IGNORE_SPACE: unset // Ignore spaces before '('
  78. * CLIENT_PROTOCOL_41: mandatory // New 4.1 protocol
  79. * CLIENT_INTERACTIVE: unset // This is an interactive client
  80. * CLIENT_SSL: unset // Use SSL encryption for the session
  81. * CLIENT_IGNORE_SIGPIPE: unset // Client only flag
  82. * CLIENT_TRANSACTIONS: unset // Client knows about transactions
  83. * CLIENT_RESERVED: unset // DEPRECATED: Old flag for 4.1 protocol
  84. * CLIENT_RESERVED2: unset // DEPRECATED: Old flag for 4.1 authentication
  85. * \ CLIENT_SECURE_CONNECTION CLIENT_MULTI_STATEMENTS: unset // Enable/disable multi-stmt support
  86. * CLIENT_MULTI_RESULTS: unset // Enable/disable multi-results
  87. * CLIENT_PS_MULTI_RESULTS: unset // Multi-results and OUT parameters in PS-protocol
  88. * CLIENT_PLUGIN_AUTH: mandatory // Client supports plugin authentication
  89. * CLIENT_CONNECT_ATTRS: unset // Client supports connection attributes
  90. * CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA: mandatory // Enable authentication response packet to be
  91. * larger than 255 bytes CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS: unset // Don't close the connection
  92. * for a user account with expired password CLIENT_SESSION_TRACK: unset // Capable of handling
  93. * server state change information CLIENT_DEPRECATE_EOF: mandatory // Client no longer needs
  94. * EOF_Packet and will use OK_Packet instead CLIENT_SSL_VERIFY_SERVER_CERT: unset // Verify server
  95. * certificate CLIENT_OPTIONAL_RESULTSET_METADATA: unset // The client can handle optional metadata
  96. * information in the resultset CLIENT_REMEMBER_OPTIONS: unset // Don't reset the options after an
  97. * unsuccessful connect
  98. *
  99. * We pay attention to:
  100. * CLIENT_CONNECT_WITH_DB: optional // Database (schema) name can be specified on connect in
  101. * Handshake Response Packet CLIENT_PROTOCOL_41: mandatory // New 4.1 protocol CLIENT_PLUGIN_AUTH:
  102. * mandatory // Client supports plugin authentication CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA:
  103. * mandatory // Enable authentication response packet to be larger than 255 bytes
  104. * CLIENT_DEPRECATE_EOF: mandatory // Client no longer needs EOF_Packet and will use OK_Packet
  105. * instead
  106. */
  107. // clang-format off
  108. BOOST_INLINE_CONSTEXPR capabilities mandatory_capabilities{
  109. CLIENT_PROTOCOL_41 |
  110. CLIENT_PLUGIN_AUTH |
  111. CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA |
  112. CLIENT_DEPRECATE_EOF |
  113. CLIENT_SECURE_CONNECTION
  114. };
  115. // clang-format on
  116. BOOST_INLINE_CONSTEXPR capabilities optional_capabilities{CLIENT_MULTI_RESULTS | CLIENT_PS_MULTI_RESULTS};
  117. } // namespace detail
  118. } // namespace mysql
  119. } // namespace boost
  120. #endif