capabilities.hpp 7.2 KB

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