common_constants.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /*
  2. * Copyright (c) 2015, 2020, Oracle and/or its affiliates.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License, version 2.0, as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is also distributed with certain software (including
  9. * but not limited to OpenSSL) that is licensed under separate terms,
  10. * as designated in a particular file or component or in included license
  11. * documentation. The authors of MySQL hereby grant you an
  12. * additional permission to link the program and your derivative works
  13. * with the separately licensed software that they have included with
  14. * MySQL.
  15. *
  16. * Without limiting anything contained in the foregoing, this file,
  17. * which is part of MySQL Connector/C++, is also subject to the
  18. * Universal FOSS Exception, version 1.0, a copy of which can be found at
  19. * http://oss.oracle.com/licenses/universal-foss-exception.
  20. *
  21. * This program is distributed in the hope that it will be useful, but
  22. * WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  24. * See the GNU General Public License, version 2.0, for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software Foundation, Inc.,
  28. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  29. */
  30. #ifndef MYSQL_COMMON_CONSTANTS_H
  31. #define MYSQL_COMMON_CONSTANTS_H
  32. #include "version_info.h"
  33. #define DEFAULT_MYSQL_PORT 3306
  34. #define DEFAULT_MYSQLX_PORT 33060
  35. // ----------------------------------------------------------------------------
  36. /*
  37. Common constants
  38. ================
  39. Warning: Values of these constants are part of the public API. Changing them
  40. is a non backward compatible API change.
  41. Note: Value of 0 is reserved for special uses and thus constant values
  42. are always > 0.
  43. Note: the empty END_LIST macro at the end of list macros helps Doxygen
  44. correctly interpret documentation for the list item.
  45. */
  46. #define OPT_STR(X,Y,N) X##_str(Y,N)
  47. #define OPT_BOOL(X,Y,N) X##_bool(Y,N)
  48. #define OPT_NUM(X,Y,N) X##_num(Y,N)
  49. #define OPT_ANY(X,Y,N) X##_any(Y,N)
  50. #undef END_LIST
  51. #define END_LIST
  52. #define CLIENT_OPTION_LIST(x) \
  53. OPT_BOOL(x,POOLING,1) /*!< disable/enable the pool. (Enabled by default)*/ \
  54. OPT_NUM(x,POOL_MAX_SIZE,2) /*!< size of the pool. (Defaults to 25)*/ \
  55. OPT_NUM(x,POOL_QUEUE_TIMEOUT,3) /*!< timeout for waiting for a connection in
  56. the pool (ms). (No timeout by default)*/ \
  57. OPT_NUM(x,POOL_MAX_IDLE_TIME,4)/*!< time for a connection to be in the pool
  58. without being used (ms).(Will not expire by default)*/ \
  59. END_LIST
  60. #define SESSION_OPTION_LIST(x) \
  61. OPT_STR(x,URI,1) /*!< connection URI or string */ \
  62. /*! DNS name of the host, IPv4 address or IPv6 address */ \
  63. OPT_STR(x,HOST,2) \
  64. OPT_NUM(x,PORT,3) /*!< X Plugin port to connect to */ \
  65. /*!
  66. Assign a priority (a number in range 1 to 100) to the last specified
  67. host; these priorities are used to determine the order in which multiple
  68. hosts are tried by the connection fail-over logic (see description
  69. of `Session` class)
  70. */ \
  71. OPT_NUM(x,PRIORITY,4) \
  72. OPT_STR(x,USER,5) /*!< user name */ \
  73. OPT_STR(x,PWD,6) /*!< password */ \
  74. OPT_STR(x,DB,7) /*!< default database */ \
  75. /*!
  76. Specify \ref SSLMode option to be used. In plain C code the value
  77. should be a `#mysqlx_ssl_mode_t` enum constant.
  78. */ \
  79. OPT_ANY(x,SSL_MODE,8) \
  80. /*! path to a PEM file specifying trusted root certificates*/ \
  81. OPT_STR(x,SSL_CA,9) \
  82. /*!
  83. Authentication method to use, see \ref AuthMethod. In plain C code the value
  84. should be a `#mysqlx_auth_method_t` enum constant.
  85. */ \
  86. OPT_ANY(x,AUTH,10) \
  87. OPT_STR(x,SOCKET,11) /*!< unix socket path */ \
  88. /*!
  89. Sets connection timeout in milliseconds. In C++ code can be also set to
  90. a `std::chrono::duration` value.
  91. */ \
  92. OPT_NUM(x,CONNECT_TIMEOUT,12) \
  93. /*!
  94. Specifies connection attributes (key-value pairs) to be sent when a session
  95. is created. The value is a JSON string (in C++ code can be also a `DbDoc`
  96. object) defining additional attributes to be sent on top of the default
  97. ones. Setting this option to `false` (in C++ code) or NULL (in plain C code)
  98. disables sending any connection attributes (including the default ones).
  99. Setting it to `true` (in C++ code) or empty string (in plain C code)
  100. requests sending only the default attributes which is also the default
  101. behavior when this option is not set.
  102. */ \
  103. OPT_STR(x,CONNECTION_ATTRIBUTES,13) \
  104. /*!
  105. List of allowed TLS protocol versions, such as "TLSv1.2". The value is a
  106. string with comma separated versions. In C++ code it can also be an
  107. iterable container with versions.
  108. */ \
  109. OPT_STR(x,TLS_VERSIONS, 14) \
  110. /*!
  111. List of allowed TLS cipher suites. The value is a string with
  112. comma separated IANA cipher suitenames (such as
  113. "TLS_RSA_WITH_3DES_EDE_CBC_SHA"). In C++ code it can also be an iterable
  114. container with names.
  115. Unknown cipher suites are silently ignored.
  116. */ \
  117. OPT_STR(x,TLS_CIPHERSUITES, 15) \
  118. /*!
  119. If enabled (true) will check hostname for DNS SRV record and use its
  120. configuration (hostname, port, priority and weight) to connect.
  121. */ \
  122. OPT_BOOL(x, DNS_SRV, 16) \
  123. OPT_ANY(x,COMPRESSION,17) /*!< enable or disable compression */ \
  124. /*!
  125. Specify compression algorithms in order of preference
  126. */ \
  127. OPT_STR(x,COMPRESSION_ALGORITHMS,18) \
  128. /*!
  129. Path to a directory containing PEM files specifying trusted root
  130. certificates.
  131. */ \
  132. OPT_STR(x,SSL_CAPATH,19) \
  133. /*! Path to a PEM file containing certificate revocation lists*/ \
  134. OPT_STR(x,SSL_CRL,20) \
  135. /*!
  136. Path to a directory containing PEM files with certificate revocation
  137. lists
  138. */ \
  139. OPT_STR(x,SSL_CRLPATH,21) \
  140. END_LIST
  141. /*
  142. Names for options supported in the query part of a connection string and
  143. how they map to session options above.
  144. Note: when adding new options to this list, also update doxygen docs
  145. for mysqlx::SessionSettings URL ctor (include\mysqlx\devapi\settings.h) and
  146. for mysqlx_get_session_from_url() (include\mysqlx\xapi.h).
  147. */
  148. #define URI_OPTION_LIST(X) \
  149. X("ssl-mode", SSL_MODE) \
  150. X("ssl-ca", SSL_CA) \
  151. X("ssl-capath", SSL_CAPATH) \
  152. X("ssl-crl", SSL_CRL) \
  153. X("ssl-crlpath", SSL_CRLPATH) \
  154. X("auth", AUTH) \
  155. X("connect-timeout", CONNECT_TIMEOUT) \
  156. X("connection-attributes",CONNECTION_ATTRIBUTES)\
  157. X("tls-version", TLS_VERSIONS) \
  158. X("tls-versions", TLS_VERSIONS) \
  159. X("tls-ciphersuites", TLS_CIPHERSUITES) \
  160. X("compression", COMPRESSION) \
  161. X("compression-algorithms", COMPRESSION_ALGORITHMS) \
  162. END_LIST
  163. #define SSL_MODE_LIST(x) \
  164. x(DISABLED,1) /*!< Establish an unencrypted connection. */ \
  165. x(REQUIRED,2) /*!< Establish a secure connection if the server supports
  166. secure connections. The connection attempt fails if a
  167. secure connection cannot be established. This is the
  168. default if `SSL_MODE` is not specified. */ \
  169. x(VERIFY_CA,3) /*!< Like `REQUIRED`, but additionally verify the server
  170. TLS certificate against the configured Certificate
  171. Authority (CA) certificates (defined by `SSL_CA`
  172. Option). The connection attempt fails if no valid
  173. matching CA certificates are found.*/ \
  174. x(VERIFY_IDENTITY,4) /*!< Like `VERIFY_CA`, but additionally verify that the
  175. server certificate matches the host to which the
  176. connection is attempted.*/\
  177. END_LIST
  178. #define AUTH_METHOD_LIST(x)\
  179. x(PLAIN,1) /*!< Plain text authentication method. The password is
  180. sent as a clear text. This method is used by
  181. default in encrypted connections. */ \
  182. x(MYSQL41,2) /*!< Authentication method supported by MySQL 4.1 and newer.
  183. The password is hashed before being sent to the server.
  184. This authentication method works over unencrypted
  185. connections */ \
  186. x(EXTERNAL,3) /*!< External authentication when the server establishes
  187. the user authenticity by other means such as SSL/x509
  188. certificates. Currently not supported by X Plugin */ \
  189. x(SHA256_MEMORY,4) /*!< Authentication using SHA256 password hashes stored in
  190. server-side cache. This authentication method works
  191. over unencrypted connections.
  192. */ \
  193. END_LIST
  194. /*
  195. Types that can be reported by MySQL server.
  196. */
  197. #define RESULT_TYPE_LIST(X) \
  198. X(BIT, 1) \
  199. X(TINYINT, 2) \
  200. X(SMALLINT, 3) \
  201. X(MEDIUMINT, 4) \
  202. X(INT, 5) \
  203. X(BIGINT, 6) \
  204. X(FLOAT, 7) \
  205. X(DECIMAL, 8) \
  206. X(DOUBLE, 9) \
  207. X(JSON, 10) \
  208. X(STRING, 11) \
  209. X(BYTES, 12) \
  210. X(TIME, 13) \
  211. X(DATE, 14) \
  212. X(DATETIME, 15) \
  213. X(TIMESTAMP, 16) \
  214. X(SET, 17) \
  215. X(ENUM, 18) \
  216. X(GEOMETRY, 19) \
  217. END_LIST
  218. /*
  219. Check options for an updatable view.
  220. @see https://dev.mysql.com/doc/refman/en/view-check-option.html
  221. */
  222. #define VIEW_CHECK_OPTION_LIST(x) \
  223. x(CASCADED,1) \
  224. x(LOCAL,2) \
  225. END_LIST
  226. /*
  227. Algorithms used to process views.
  228. @see https://dev.mysql.com/doc/refman/en/view-algorithms.html
  229. */
  230. #define VIEW_ALGORITHM_LIST(x) \
  231. x(UNDEFINED,1) \
  232. x(MERGE,2) \
  233. x(TEMPTABLE,3) \
  234. END_LIST
  235. /*
  236. View security settings.
  237. @see https://dev.mysql.com/doc/refman/en/stored-programs-security.html
  238. */
  239. #define VIEW_SECURITY_LIST(x) \
  240. x(DEFINER,1) \
  241. x(INVOKER,2) \
  242. END_LIST
  243. #define LOCK_MODE_LIST(X) \
  244. X(SHARED,1) /*!< Sets a shared mode lock on any rows that
  245. are read. Other sessions can read the rows,
  246. but cannot modify them until your transaction
  247. commits. If any of these rows were changed by
  248. another transaction that has not yet committed,
  249. your query waits until that transaction ends
  250. and then uses the latest values. */ \
  251. X(EXCLUSIVE,2) /*!< For index records the search encounters,
  252. locks the rows and any associated index entries, the same
  253. as if you issued an UPDATE statement for those rows. Other
  254. transactions are blocked from updating those rows,
  255. from doing locking in LOCK_SHARED, or from reading
  256. the data in certain transaction isolation levels. */ \
  257. END_LIST
  258. #define LOCK_CONTENTION_LIST(X) \
  259. X(DEFAULT,0) /*!< Block query until existing row locks are released. */ \
  260. X(NOWAIT,1) /*!< Return error if lock could not be obtained immediately. */ \
  261. X(SKIP_LOCKED,2) /*!< Execute query immediately, excluding items that are
  262. locked from the query results. */ \
  263. END_LIST
  264. #define COMPRESSION_MODE_LIST(x) \
  265. x(DISABLED,1) /*!< Disables the compression. */ \
  266. x(PREFERRED,2) /*!< Request compression, but not return error
  267. if compression is requested, but could not be
  268. used */ \
  269. x(REQUIRED,3) /*!< Request compression and return error if
  270. compression is not supported by the server */ \
  271. END_LIST
  272. // ----------------------------------------------------------------------------
  273. #define COLLECTION_OPTIONS_OPTION(X)\
  274. X(REUSE,1) /*!< Use existing collection. Expects a boolean value. */ \
  275. X(VALIDATION,2) /*!< Collection validation options. Expects
  276. CollectionValidation or a json string.*/ \
  277. END_LIST
  278. #define COLLECTION_VALIDATION_OPTION(X)\
  279. X(SCHEMA,1) /*!< Collection validation schema, as defined by
  280. https://dev.mysql.com/doc/refman/8.0/en/json-validation-functions.html#function_json-schema-valid
  281. */ \
  282. X(LEVEL,2) /*!< Defines level of validation on the collection, see
  283. \ref CollectionValidation_Level "CollectionValidation::Level".
  284. In plain C code the value should be
  285. \ref opt_collection_validation_level "mysqlx_collection_validation_level_t".
  286. */ \
  287. END_LIST
  288. // Schema Validation Level
  289. //Windows defines STRICT as a macro... undefine it
  290. #ifdef STRICT
  291. #undef STRICT
  292. #endif
  293. #define COLLECTION_VALIDATION_LEVEL(X)\
  294. X(OFF,1) /*!< No validation will be done on the collection. */ \
  295. X(STRICT,2) /*!< All collection documents have to comply to validation schema.
  296. */ \
  297. END_LIST
  298. #endif