jw项目windows环境软件安装
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1333 lines
42 KiB

1 year ago
  1. /* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License, version 2.0,
  4. as published by the Free Software Foundation.
  5. This program is also distributed with certain software (including
  6. but not limited to OpenSSL) that is licensed under separate terms,
  7. as designated in a particular file or component or in included license
  8. documentation. The authors of MySQL hereby grant you an additional
  9. permission to link the program and your derivative works with the
  10. separately licensed software that they have included with MySQL.
  11. Without limiting anything contained in the foregoing, this file,
  12. which is part of C Driver for MySQL (Connector/C), is also subject to the
  13. Universal FOSS Exception, version 1.0, a copy of which can be found at
  14. http://oss.oracle.com/licenses/universal-foss-exception.
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License, version 2.0, for more details.
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  22. /**
  23. @file include/mysql_com.h
  24. Common definition between mysql server & client.
  25. */
  26. #ifndef _mysql_com_h
  27. #define _mysql_com_h
  28. #ifndef MYSQL_ABI_CHECK
  29. #include <stdbool.h>
  30. #include <stdint.h>
  31. #endif
  32. #include "my_command.h"
  33. #include "my_compress.h"
  34. /*
  35. We need a definition for my_socket. On the client, <mysql.h> already provides
  36. it, but on the server side, we need to get it from a header.
  37. */
  38. #ifndef my_socket_defined
  39. #include "my_io.h"
  40. #include "mysql/components/services/bits/my_io_bits.h"
  41. #endif
  42. #ifndef MYSQL_ABI_CHECK
  43. #include <stdbool.h>
  44. #endif
  45. #define SYSTEM_CHARSET_MBMAXLEN 3
  46. #define FILENAME_CHARSET_MBMAXLEN 5
  47. #define NAME_CHAR_LEN 64 /**< Field/table name length */
  48. #define PARTITION_EXPR_CHAR_LEN \
  49. 2048 /**< Maximum expression length in chars \
  50. */
  51. #define USERNAME_CHAR_LENGTH 32
  52. #define USERNAME_CHAR_LENGTH_STR "32"
  53. #ifndef NAME_LEN
  54. #define NAME_LEN (NAME_CHAR_LEN * SYSTEM_CHARSET_MBMAXLEN)
  55. #endif
  56. #define USERNAME_LENGTH (USERNAME_CHAR_LENGTH * SYSTEM_CHARSET_MBMAXLEN)
  57. #define CONNECT_STRING_MAXLEN 1024
  58. #define MYSQL_AUTODETECT_CHARSET_NAME "auto"
  59. #define SERVER_VERSION_LENGTH 60
  60. #define SQLSTATE_LENGTH 5
  61. /*
  62. In FIDO terminology, relying party is the server where required services are
  63. running. Relying party ID is unique name given to server.
  64. */
  65. #define RELYING_PARTY_ID_LENGTH 255
  66. /* Length of random salt sent during fido registration */
  67. #define CHALLENGE_LENGTH 32
  68. /* Maximum authentication factors server supports */
  69. #define MAX_AUTH_FACTORS 3
  70. /**
  71. Maximum length of comments
  72. pre 5.6: 60 characters
  73. */
  74. #define TABLE_COMMENT_INLINE_MAXLEN 180
  75. #define TABLE_COMMENT_MAXLEN 2048
  76. #define COLUMN_COMMENT_MAXLEN 1024
  77. #define INDEX_COMMENT_MAXLEN 1024
  78. #define TABLE_PARTITION_COMMENT_MAXLEN 1024
  79. #define TABLESPACE_COMMENT_MAXLEN 2048
  80. /**
  81. Maximum length of protocol packet.
  82. @ref page_protocol_basic_ok_packet length limit also restricted to this value
  83. as any length greater than this value will have first byte of
  84. @ref page_protocol_basic_ok_packet to be 254 thus does not
  85. provide a means to identify if this is @ref page_protocol_basic_ok_packet or
  86. @ref page_protocol_basic_eof_packet.
  87. */
  88. #define MAX_PACKET_LENGTH (256L * 256L * 256L - 1)
  89. #define LOCAL_HOST "localhost"
  90. #define LOCAL_HOST_NAMEDPIPE "."
  91. #if defined(_WIN32)
  92. #define MYSQL_NAMEDPIPE "MySQL"
  93. #define MYSQL_SERVICENAME "MySQL"
  94. #endif /* _WIN32 */
  95. /** The length of the header part for each generated column in the .frm file.*/
  96. #define FRM_GCOL_HEADER_SIZE 4
  97. /**
  98. Maximum length of the expression statement defined for generated columns.
  99. */
  100. #define GENERATED_COLUMN_EXPRESSION_MAXLEN 65535 - FRM_GCOL_HEADER_SIZE
  101. /**
  102. Length of random string sent by server on handshake; this is also length of
  103. obfuscated password, received from client
  104. */
  105. #define SCRAMBLE_LENGTH 20
  106. #define AUTH_PLUGIN_DATA_PART_1_LENGTH 8
  107. /** length of password stored in the db: new passwords are preceded with '*'*/
  108. #define SCRAMBLED_PASSWORD_CHAR_LENGTH (SCRAMBLE_LENGTH * 2 + 1)
  109. /**
  110. @defgroup group_cs_column_definition_flags Column Definition Flags
  111. @ingroup group_cs
  112. @brief Values for the flags bitmask used by ::Send_field:flags
  113. Currently need to fit into 32 bits.
  114. Each bit represents an optional feature of the protocol.
  115. Both the client and the server are sending these.
  116. The intersection of the two determines what optional parts of the
  117. protocol will be used.
  118. */
  119. /**
  120. @addtogroup group_cs_column_definition_flags
  121. @{
  122. */
  123. #define NOT_NULL_FLAG 1 /**< Field can't be NULL */
  124. #define PRI_KEY_FLAG 2 /**< Field is part of a primary key */
  125. #define UNIQUE_KEY_FLAG 4 /**< Field is part of a unique key */
  126. #define MULTIPLE_KEY_FLAG 8 /**< Field is part of a key */
  127. #define BLOB_FLAG 16 /**< Field is a blob */
  128. #define UNSIGNED_FLAG 32 /**< Field is unsigned */
  129. #define ZEROFILL_FLAG 64 /**< Field is zerofill */
  130. #define BINARY_FLAG 128 /**< Field is binary */
  131. /* The following are only sent to new clients */
  132. #define ENUM_FLAG 256 /**< field is an enum */
  133. #define AUTO_INCREMENT_FLAG 512 /**< field is a autoincrement field */
  134. #define TIMESTAMP_FLAG 1024 /**< Field is a timestamp */
  135. #define SET_FLAG 2048 /**< field is a set */
  136. #define NO_DEFAULT_VALUE_FLAG 4096 /**< Field doesn't have default value */
  137. #define ON_UPDATE_NOW_FLAG 8192 /**< Field is set to NOW on UPDATE */
  138. #define NUM_FLAG 32768 /**< Field is num (for clients) */
  139. #define PART_KEY_FLAG 16384 /**< Intern; Part of some key */
  140. #define GROUP_FLAG 32768 /**< Intern: Group field */
  141. #define UNIQUE_FLAG 65536 /**< Intern: Used by sql_yacc */
  142. #define BINCMP_FLAG 131072 /**< Intern: Used by sql_yacc */
  143. #define GET_FIXED_FIELDS_FLAG \
  144. (1 << 18) /**< Used to get fields in item tree \
  145. */
  146. #define FIELD_IN_PART_FUNC_FLAG (1 << 19) /**< Field part of partition func */
  147. /**
  148. Intern: Field in TABLE object for new version of altered table,
  149. which participates in a newly added index.
  150. */
  151. #define FIELD_IN_ADD_INDEX (1 << 20)
  152. #define FIELD_IS_RENAMED (1 << 21) /**< Intern: Field is being renamed */
  153. #define FIELD_FLAGS_STORAGE_MEDIA 22 /**< Field storage media, bit 22-23 */
  154. #define FIELD_FLAGS_STORAGE_MEDIA_MASK (3 << FIELD_FLAGS_STORAGE_MEDIA)
  155. #define FIELD_FLAGS_COLUMN_FORMAT 24 /**< Field column format, bit 24-25 */
  156. #define FIELD_FLAGS_COLUMN_FORMAT_MASK (3 << FIELD_FLAGS_COLUMN_FORMAT)
  157. #define FIELD_IS_DROPPED (1 << 26) /**< Intern: Field is being dropped */
  158. #define EXPLICIT_NULL_FLAG \
  159. (1 << 27) /**< Field is explicitly specified as \
  160. NULL by the user */
  161. /* 1 << 28 is unused. */
  162. /** Field will not be loaded in secondary engine. */
  163. #define NOT_SECONDARY_FLAG (1 << 29)
  164. /** Field is explicitly marked as invisible by the user. */
  165. #define FIELD_IS_INVISIBLE (1 << 30)
  166. /** @}*/
  167. /**
  168. @defgroup group_cs_com_refresh_flags COM_REFRESH Flags
  169. @ingroup group_cs
  170. @brief Values for the `sub_command` in ::COM_REFRESH
  171. Currently the protocol carries only 8 bits of these flags.
  172. The rest (8-end) are used only internally in the server.
  173. */
  174. /**
  175. @addtogroup group_cs_com_refresh_flags
  176. @{
  177. */
  178. #define REFRESH_GRANT 1 /**< Refresh grant tables, FLUSH PRIVILEGES */
  179. #define REFRESH_LOG 2 /**< Start on new log file, FLUSH LOGS */
  180. #define REFRESH_TABLES 4 /**< close all tables, FLUSH TABLES */
  181. #define REFRESH_HOSTS 8 /**< Flush host cache, FLUSH HOSTS */
  182. #define REFRESH_STATUS 16 /**< Flush status variables, FLUSH STATUS */
  183. #define REFRESH_THREADS 32 /**< Flush thread cache */
  184. #define REFRESH_REPLICA \
  185. 64 /**< Reset master info and restart replica \
  186. thread, RESET REPLICA */
  187. #define REFRESH_SLAVE \
  188. REFRESH_REPLICA /**< Reset master info and restart replica \
  189. thread, RESET REPLICA. This is deprecated, \
  190. use REFRESH_REPLICA instead. */
  191. #define REFRESH_MASTER \
  192. 128 /**< Remove all bin logs in the index \
  193. and truncate the index, RESET MASTER */
  194. #define REFRESH_ERROR_LOG 256 /**< Rotate only the error log */
  195. #define REFRESH_ENGINE_LOG 512 /**< Flush all storage engine logs */
  196. #define REFRESH_BINARY_LOG 1024 /**< Flush the binary log */
  197. #define REFRESH_RELAY_LOG 2048 /**< Flush the relay log */
  198. #define REFRESH_GENERAL_LOG 4096 /**< Flush the general log */
  199. #define REFRESH_SLOW_LOG 8192 /**< Flush the slow query log */
  200. #define REFRESH_READ_LOCK 16384 /**< Lock tables for read. */
  201. /**
  202. Wait for an impending flush before closing the tables.
  203. @sa REFRESH_READ_LOCK, handle_reload_request, close_cached_tables
  204. */
  205. #define REFRESH_FAST 32768
  206. #define REFRESH_USER_RESOURCES \
  207. 0x80000L /** FLUSH RESOURCES. @sa ::reset_mqh \
  208. */
  209. #define REFRESH_FOR_EXPORT 0x100000L /** FLUSH TABLES ... FOR EXPORT */
  210. #define REFRESH_OPTIMIZER_COSTS 0x200000L /** FLUSH OPTIMIZER_COSTS */
  211. #define REFRESH_PERSIST 0x400000L /** RESET PERSIST */
  212. /** @}*/
  213. /**
  214. @defgroup group_cs_capabilities_flags Capabilities Flags
  215. @ingroup group_cs
  216. @brief Values for the capabilities flag bitmask used by the MySQL protocol
  217. Currently need to fit into 32 bits.
  218. Each bit represents an optional feature of the protocol.
  219. Both the client and the server are sending these.
  220. The intersection of the two determines whast optional parts of the
  221. protocol will be used.
  222. */
  223. /**
  224. @addtogroup group_cs_capabilities_flags
  225. @{
  226. */
  227. /**
  228. Use the improved version of Old Password Authentication.
  229. Not used.
  230. @note Assumed to be set since 4.1.1.
  231. */
  232. #define CLIENT_LONG_PASSWORD 1
  233. /**
  234. Send found rows instead of affected rows in @ref
  235. page_protocol_basic_eof_packet
  236. */
  237. #define CLIENT_FOUND_ROWS 2
  238. /**
  239. @brief Get all column flags
  240. Longer flags in Protocol::ColumnDefinition320.
  241. @todo Reference Protocol::ColumnDefinition320
  242. Server
  243. ------
  244. Supports longer flags.
  245. Client
  246. ------
  247. Expects longer flags.
  248. */
  249. #define CLIENT_LONG_FLAG 4
  250. /**
  251. Database (schema) name can be specified on connect in Handshake Response
  252. Packet.
  253. @todo Reference Handshake Response Packet.
  254. Server
  255. ------
  256. Supports schema-name in Handshake Response Packet.
  257. Client
  258. ------
  259. Handshake Response Packet contains a schema-name.
  260. @sa send_client_reply_packet()
  261. */
  262. #define CLIENT_CONNECT_WITH_DB 8
  263. #define CLIENT_NO_SCHEMA \
  264. 16 /**< DEPRECATED: Don't allow database.table.column */
  265. /**
  266. Compression protocol supported.
  267. @todo Reference Compression
  268. Server
  269. ------
  270. Supports compression.
  271. Client
  272. ------
  273. Switches to Compression compressed protocol after successful authentication.
  274. */
  275. #define CLIENT_COMPRESS 32
  276. /**
  277. Special handling of ODBC behavior.
  278. @note No special behavior since 3.22.
  279. */
  280. #define CLIENT_ODBC 64
  281. /**
  282. Can use LOAD DATA LOCAL.
  283. Server
  284. ------
  285. Enables the LOCAL INFILE request of LOAD DATA|XML.
  286. Client
  287. ------
  288. Will handle LOCAL INFILE request.
  289. */
  290. #define CLIENT_LOCAL_FILES 128
  291. /**
  292. Ignore spaces before '('
  293. Server
  294. ------
  295. Parser can ignore spaces before '('.
  296. Client
  297. ------
  298. Let the parser ignore spaces before '('.
  299. */
  300. #define CLIENT_IGNORE_SPACE 256
  301. /**
  302. New 4.1 protocol
  303. @todo Reference the new 4.1 protocol
  304. Server
  305. ------
  306. Supports the 4.1 protocol.
  307. Client
  308. ------
  309. Uses the 4.1 protocol.
  310. @note this value was CLIENT_CHANGE_USER in 3.22, unused in 4.0
  311. */
  312. #define CLIENT_PROTOCOL_41 512
  313. /**
  314. This is an interactive client
  315. Use @ref System_variables::net_wait_timeout
  316. versus @ref System_variables::net_interactive_timeout.
  317. Server
  318. ------
  319. Supports interactive and noninteractive clients.
  320. Client
  321. ------
  322. Client is interactive.
  323. @sa mysql_real_connect()
  324. */
  325. #define CLIENT_INTERACTIVE 1024
  326. /**
  327. Use SSL encryption for the session
  328. @todo Reference SSL
  329. Server
  330. ------
  331. Supports SSL
  332. Client
  333. ------
  334. Switch to SSL after sending the capability-flags.
  335. */
  336. #define CLIENT_SSL 2048
  337. /**
  338. Client only flag. Not used.
  339. Client
  340. ------
  341. Do not issue SIGPIPE if network failures occur (libmysqlclient only).
  342. @sa mysql_real_connect()
  343. */
  344. #define CLIENT_IGNORE_SIGPIPE 4096
  345. /**
  346. Client knows about transactions
  347. Server
  348. ------
  349. Can send status flags in @ref page_protocol_basic_ok_packet /
  350. @ref page_protocol_basic_eof_packet.
  351. Client
  352. ------
  353. Expects status flags in @ref page_protocol_basic_ok_packet /
  354. @ref page_protocol_basic_eof_packet.
  355. @note This flag is optional in 3.23, but always set by the server since 4.0.
  356. @sa send_server_handshake_packet(), parse_client_handshake_packet(),
  357. net_send_ok(), net_send_eof()
  358. */
  359. #define CLIENT_TRANSACTIONS 8192
  360. #define CLIENT_RESERVED 16384 /**< DEPRECATED: Old flag for 4.1 protocol */
  361. #define CLIENT_RESERVED2 \
  362. 32768 /**< DEPRECATED: Old flag for 4.1 authentication \
  363. CLIENT_SECURE_CONNECTION */
  364. /**
  365. Enable/disable multi-stmt support
  366. Also sets @ref CLIENT_MULTI_RESULTS. Currently not checked anywhere.
  367. Server
  368. ------
  369. Can handle multiple statements per COM_QUERY and COM_STMT_PREPARE.
  370. Client
  371. -------
  372. May send multiple statements per COM_QUERY and COM_STMT_PREPARE.
  373. @note Was named ::CLIENT_MULTI_QUERIES in 4.1.0, renamed later.
  374. Requires
  375. --------
  376. ::CLIENT_PROTOCOL_41
  377. @todo Reference COM_QUERY and COM_STMT_PREPARE
  378. */
  379. #define CLIENT_MULTI_STATEMENTS (1UL << 16)
  380. /**
  381. Enable/disable multi-results
  382. Server
  383. ------
  384. Can send multiple resultsets for COM_QUERY.
  385. Error if the server needs to send them and client
  386. does not support them.
  387. Client
  388. -------
  389. Can handle multiple resultsets for COM_QUERY.
  390. Requires
  391. --------
  392. ::CLIENT_PROTOCOL_41
  393. @sa mysql_execute_command(), sp_head::MULTI_RESULTS
  394. */
  395. #define CLIENT_MULTI_RESULTS (1UL << 17)
  396. /**
  397. Multi-results and OUT parameters in PS-protocol.
  398. Server
  399. ------
  400. Can send multiple resultsets for COM_STMT_EXECUTE.
  401. Client
  402. ------
  403. Can handle multiple resultsets for COM_STMT_EXECUTE.
  404. Requires
  405. --------
  406. ::CLIENT_PROTOCOL_41
  407. @todo Reference COM_STMT_EXECUTE and PS-protocol
  408. @sa Protocol_binary::send_out_parameters
  409. */
  410. #define CLIENT_PS_MULTI_RESULTS (1UL << 18)
  411. /**
  412. Client supports plugin authentication
  413. Server
  414. ------
  415. Sends extra data in Initial Handshake Packet and supports the pluggable
  416. authentication protocol.
  417. Client
  418. ------
  419. Supports authentication plugins.
  420. Requires
  421. --------
  422. ::CLIENT_PROTOCOL_41
  423. @todo Reference plugin authentication, Initial Handshake Packet,
  424. Authentication plugins
  425. @sa send_change_user_packet(), send_client_reply_packet(), run_plugin_auth(),
  426. parse_com_change_user_packet(), parse_client_handshake_packet()
  427. */
  428. #define CLIENT_PLUGIN_AUTH (1UL << 19)
  429. /**
  430. Client supports connection attributes
  431. Server
  432. ------
  433. Permits connection attributes in Protocol::HandshakeResponse41.
  434. Client
  435. ------
  436. Sends connection attributes in Protocol::HandshakeResponse41.
  437. @todo Reference Protocol::HandshakeResponse41
  438. @sa send_client_connect_attrs(), read_client_connect_attrs()
  439. */
  440. #define CLIENT_CONNECT_ATTRS (1UL << 20)
  441. /**
  442. Enable authentication response packet to be larger than 255 bytes.
  443. When the ability to change default plugin require that the initial password
  444. field in the Protocol::HandshakeResponse41 paclet can be of arbitrary size.
  445. However, the 4.1 client-server protocol limits the length of the
  446. auth-data-field sent from client to server to 255 bytes.
  447. The solution is to change the type of the field to a true length encoded
  448. string and indicate the protocol change
  449. with this client capability flag.
  450. Server
  451. ------
  452. Understands length-encoded integer for auth response data in
  453. Protocol::HandshakeResponse41.
  454. Client
  455. ------
  456. Length of auth response data in Protocol::HandshakeResponse41
  457. is a length-encoded integer.
  458. @todo Reference Protocol::HandshakeResponse41
  459. @note The flag was introduced in 5.6.6, but had the wrong value.
  460. @sa send_client_reply_packet(), parse_client_handshake_packet(),
  461. get_56_lenc_string(), get_41_lenc_string()
  462. */
  463. #define CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA (1UL << 21)
  464. /**
  465. Don't close the connection for a user account with expired password.
  466. Server
  467. ------
  468. Announces support for expired password extension.
  469. Client
  470. ------
  471. Can handle expired passwords.
  472. @todo Reference expired password
  473. @sa MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, disconnect_on_expired_password
  474. ACL_USER::password_expired, check_password_lifetime(), acl_authenticate()
  475. */
  476. #define CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS (1UL << 22)
  477. /**
  478. Capable of handling server state change information. Its a hint to the
  479. server to include the state change information in
  480. @ref page_protocol_basic_ok_packet.
  481. Server
  482. ------
  483. Can set ::SERVER_SESSION_STATE_CHANGED in the ::SERVER_STATUS_flags_enum
  484. and send @ref sect_protocol_basic_ok_packet_sessinfo in a
  485. @ref page_protocol_basic_ok_packet.
  486. Client
  487. ------
  488. Expects the server to send @ref sect_protocol_basic_ok_packet_sessinfo in
  489. a @ref page_protocol_basic_ok_packet.
  490. @sa enum_session_state_type, read_ok_ex(), net_send_ok(), Session_tracker,
  491. State_tracker
  492. */
  493. #define CLIENT_SESSION_TRACK (1UL << 23)
  494. /**
  495. Client no longer needs @ref page_protocol_basic_eof_packet and will
  496. use @ref page_protocol_basic_ok_packet instead.
  497. @sa net_send_ok()
  498. Server
  499. ------
  500. Can send OK after a Text Resultset.
  501. Client
  502. ------
  503. Expects an @ref page_protocol_basic_ok_packet (instead of
  504. @ref page_protocol_basic_eof_packet) after the resultset rows of a
  505. Text Resultset.
  506. Background
  507. ----------
  508. To support ::CLIENT_SESSION_TRACK, additional information must be sent after
  509. all successful commands. Although the @ref page_protocol_basic_ok_packet is
  510. extensible, the @ref page_protocol_basic_eof_packet is not due to the overlap
  511. of its bytes with the content of the Text Resultset Row.
  512. Therefore, the @ref page_protocol_basic_eof_packet in the
  513. Text Resultset is replaced with an @ref page_protocol_basic_ok_packet.
  514. @ref page_protocol_basic_eof_packet is deprecated as of MySQL 5.7.5.
  515. @todo Reference Text Resultset
  516. @sa cli_safe_read_with_ok(), read_ok_ex(), net_send_ok(), net_send_eof()
  517. */
  518. #define CLIENT_DEPRECATE_EOF (1UL << 24)
  519. /**
  520. The client can handle optional metadata information in the resultset.
  521. */
  522. #define CLIENT_OPTIONAL_RESULTSET_METADATA (1UL << 25)
  523. /**
  524. Compression protocol extended to support zstd compression method
  525. This capability flag is used to send zstd compression level between
  526. client and server provided both client and server are enabled with
  527. this flag.
  528. Server
  529. ------
  530. Server sets this flag when global variable protocol-compression-algorithms
  531. has zstd in its list of supported values.
  532. Client
  533. ------
  534. Client sets this flag when it is configured to use zstd compression method.
  535. */
  536. #define CLIENT_ZSTD_COMPRESSION_ALGORITHM (1UL << 26)
  537. /**
  538. Support optional extension for query parameters into the @ref
  539. page_protocol_com_query and @ref page_protocol_com_stmt_execute packets.
  540. Server
  541. ------
  542. Expects an optional part containing the query parameter set(s). Executes the
  543. query for each set of parameters or returns an error if more than 1 set of
  544. parameters is sent and the server can't execute it.
  545. Client
  546. ------
  547. Can send the optional part containing the query parameter set(s).
  548. */
  549. #define CLIENT_QUERY_ATTRIBUTES (1UL << 27)
  550. /**
  551. Support Multi factor authentication.
  552. Server
  553. ------
  554. Server sends AuthNextFactor packet after every nth factor authentication
  555. method succeeds, except the last factor authentication.
  556. Client
  557. ------
  558. Client reads AuthNextFactor packet sent by server and initiates next factor
  559. authentication method.
  560. */
  561. #define MULTI_FACTOR_AUTHENTICATION (1UL << 28)
  562. /**
  563. This flag will be reserved to extend the 32bit capabilities structure to
  564. 64bits.
  565. */
  566. #define CLIENT_CAPABILITY_EXTENSION (1UL << 29)
  567. /**
  568. Verify server certificate.
  569. Client only flag.
  570. @deprecated in favor of --ssl-mode.
  571. */
  572. #define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30)
  573. /**
  574. Don't reset the options after an unsuccessful connect
  575. Client only flag.
  576. Typically passed via ::mysql_real_connect() 's client_flag parameter.
  577. @sa mysql_real_connect()
  578. */
  579. #define CLIENT_REMEMBER_OPTIONS (1UL << 31)
  580. /** @}*/
  581. /** a compatibility alias for CLIENT_COMPRESS */
  582. #define CAN_CLIENT_COMPRESS CLIENT_COMPRESS
  583. /** Gather all possible capabilities (flags) supported by the server */
  584. #define CLIENT_ALL_FLAGS \
  585. (CLIENT_LONG_PASSWORD | CLIENT_FOUND_ROWS | CLIENT_LONG_FLAG | \
  586. CLIENT_CONNECT_WITH_DB | CLIENT_NO_SCHEMA | CLIENT_COMPRESS | CLIENT_ODBC | \
  587. CLIENT_LOCAL_FILES | CLIENT_IGNORE_SPACE | CLIENT_PROTOCOL_41 | \
  588. CLIENT_INTERACTIVE | CLIENT_SSL | CLIENT_IGNORE_SIGPIPE | \
  589. CLIENT_TRANSACTIONS | CLIENT_RESERVED | CLIENT_RESERVED2 | \
  590. CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS | CLIENT_PS_MULTI_RESULTS | \
  591. CLIENT_SSL_VERIFY_SERVER_CERT | CLIENT_REMEMBER_OPTIONS | \
  592. CLIENT_PLUGIN_AUTH | CLIENT_CONNECT_ATTRS | \
  593. CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA | \
  594. CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS | CLIENT_SESSION_TRACK | \
  595. CLIENT_DEPRECATE_EOF | CLIENT_OPTIONAL_RESULTSET_METADATA | \
  596. CLIENT_ZSTD_COMPRESSION_ALGORITHM | CLIENT_QUERY_ATTRIBUTES | \
  597. MULTI_FACTOR_AUTHENTICATION)
  598. /**
  599. Switch off from ::CLIENT_ALL_FLAGS the flags that are optional and
  600. depending on build flags.
  601. If any of the optional flags is supported by the build it will be switched
  602. on before sending to the client during the connection handshake.
  603. */
  604. #define CLIENT_BASIC_FLAGS \
  605. (CLIENT_ALL_FLAGS & \
  606. ~(CLIENT_SSL | CLIENT_COMPRESS | CLIENT_SSL_VERIFY_SERVER_CERT | \
  607. CLIENT_ZSTD_COMPRESSION_ALGORITHM))
  608. /** The status flags are a bit-field */
  609. enum SERVER_STATUS_flags_enum {
  610. /**
  611. Is raised when a multi-statement transaction
  612. has been started, either explicitly, by means
  613. of BEGIN or COMMIT AND CHAIN, or
  614. implicitly, by the first transactional
  615. statement, when autocommit=off.
  616. */
  617. SERVER_STATUS_IN_TRANS = 1,
  618. SERVER_STATUS_AUTOCOMMIT = 2, /**< Server in auto_commit mode */
  619. SERVER_MORE_RESULTS_EXISTS = 8, /**< Multi query - next query exists */
  620. SERVER_QUERY_NO_GOOD_INDEX_USED = 16,
  621. SERVER_QUERY_NO_INDEX_USED = 32,
  622. /**
  623. The server was able to fulfill the clients request and opened a
  624. read-only non-scrollable cursor for a query. This flag comes
  625. in reply to COM_STMT_EXECUTE and COM_STMT_FETCH commands.
  626. Used by Binary Protocol Resultset to signal that COM_STMT_FETCH
  627. must be used to fetch the row-data.
  628. @todo Refify "Binary Protocol Resultset" and "COM_STMT_FETCH".
  629. */
  630. SERVER_STATUS_CURSOR_EXISTS = 64,
  631. /**
  632. This flag is sent when a read-only cursor is exhausted, in reply to
  633. COM_STMT_FETCH command.
  634. */
  635. SERVER_STATUS_LAST_ROW_SENT = 128,
  636. SERVER_STATUS_DB_DROPPED = 256, /**< A database was dropped */
  637. SERVER_STATUS_NO_BACKSLASH_ESCAPES = 512,
  638. /**
  639. Sent to the client if after a prepared statement reprepare
  640. we discovered that the new statement returns a different
  641. number of result set columns.
  642. */
  643. SERVER_STATUS_METADATA_CHANGED = 1024,
  644. SERVER_QUERY_WAS_SLOW = 2048,
  645. /**
  646. To mark ResultSet containing output parameter values.
  647. */
  648. SERVER_PS_OUT_PARAMS = 4096,
  649. /**
  650. Set at the same time as SERVER_STATUS_IN_TRANS if the started
  651. multi-statement transaction is a read-only transaction. Cleared
  652. when the transaction commits or aborts. Since this flag is sent
  653. to clients in OK and EOF packets, the flag indicates the
  654. transaction status at the end of command execution.
  655. */
  656. SERVER_STATUS_IN_TRANS_READONLY = 8192,
  657. /**
  658. This status flag, when on, implies that one of the state information has
  659. changed on the server because of the execution of the last statement.
  660. */
  661. SERVER_SESSION_STATE_CHANGED = (1UL << 14)
  662. };
  663. /**
  664. Server status flags that must be cleared when starting
  665. execution of a new SQL statement.
  666. Flags from this set are only added to the
  667. current server status by the execution engine, but
  668. never removed -- the execution engine expects them
  669. to disappear automagically by the next command.
  670. */
  671. #define SERVER_STATUS_CLEAR_SET \
  672. (SERVER_QUERY_NO_GOOD_INDEX_USED | SERVER_QUERY_NO_INDEX_USED | \
  673. SERVER_MORE_RESULTS_EXISTS | SERVER_STATUS_METADATA_CHANGED | \
  674. SERVER_QUERY_WAS_SLOW | SERVER_STATUS_DB_DROPPED | \
  675. SERVER_STATUS_CURSOR_EXISTS | SERVER_STATUS_LAST_ROW_SENT | \
  676. SERVER_SESSION_STATE_CHANGED)
  677. /** Max length of a error message. Should be kept in sync with ::ERRMSGSIZE. */
  678. #define MYSQL_ERRMSG_SIZE 512
  679. #define NET_READ_TIMEOUT 30 /**< Timeout on read */
  680. #define NET_WRITE_TIMEOUT 60 /**< Timeout on write */
  681. #define NET_WAIT_TIMEOUT 8 * 60 * 60 /**< Wait for new query */
  682. /**
  683. Flag used by the parser. Kill only the query and not the connection.
  684. @sa SQLCOM_KILL, sql_kill(), LEX::type
  685. */
  686. #define ONLY_KILL_QUERY 1
  687. #ifndef MYSQL_VIO
  688. struct Vio;
  689. #define MYSQL_VIO struct Vio *
  690. #endif
  691. #define MAX_TINYINT_WIDTH 3 /**< Max width for a TINY w.o. sign */
  692. #define MAX_SMALLINT_WIDTH 5 /**< Max width for a SHORT w.o. sign */
  693. #define MAX_MEDIUMINT_WIDTH 8 /**< Max width for a INT24 w.o. sign */
  694. #define MAX_INT_WIDTH 10 /**< Max width for a LONG w.o. sign */
  695. #define MAX_BIGINT_WIDTH 20 /**< Max width for a LONGLONG */
  696. /// Max width for a CHAR column, in number of characters
  697. #define MAX_CHAR_WIDTH 255
  698. /// Default width for blob in bytes @todo - align this with sizes from field.h
  699. #define MAX_BLOB_WIDTH 16777216
  700. #define NET_ERROR_UNSET 0 /**< No error has occurred yet */
  701. #define NET_ERROR_SOCKET_RECOVERABLE 1 /**< Socket still usable */
  702. #define NET_ERROR_SOCKET_UNUSABLE 2 /**< Do not use the socket */
  703. #define NET_ERROR_SOCKET_NOT_READABLE 3 /**< Try write and close socket */
  704. #define NET_ERROR_SOCKET_NOT_WRITABLE 4 /**< Try read and close socket */
  705. typedef struct NET {
  706. MYSQL_VIO vio;
  707. unsigned char *buff, *buff_end, *write_pos, *read_pos;
  708. my_socket fd; /* For Perl DBI/dbd */
  709. /**
  710. Set if we are doing several queries in one
  711. command ( as in LOAD TABLE ... FROM MASTER ),
  712. and do not want to confuse the client with OK at the wrong time
  713. */
  714. unsigned long remain_in_buf, length, buf_length, where_b;
  715. unsigned long max_packet, max_packet_size;
  716. unsigned int pkt_nr, compress_pkt_nr;
  717. unsigned int write_timeout, read_timeout, retry_count;
  718. int fcntl;
  719. unsigned int *return_status;
  720. unsigned char reading_or_writing;
  721. unsigned char save_char;
  722. bool compress;
  723. unsigned int last_errno;
  724. unsigned char error;
  725. /** Client library error message buffer. Actually belongs to struct MYSQL. */
  726. char last_error[MYSQL_ERRMSG_SIZE];
  727. /** Client library sqlstate buffer. Set along with the error message. */
  728. char sqlstate[SQLSTATE_LENGTH + 1];
  729. /**
  730. Extension pointer, for the caller private use.
  731. Any program linking with the networking library can use this pointer,
  732. which is handy when private connection specific data needs to be
  733. maintained.
  734. The mysqld server process uses this pointer internally,
  735. to maintain the server internal instrumentation for the connection.
  736. */
  737. void *extension;
  738. } NET;
  739. #define packet_error (~(unsigned long)0)
  740. /**
  741. @addtogroup group_cs_backward_compatibility Backward compatibility
  742. @ingroup group_cs
  743. @{
  744. */
  745. #define CLIENT_MULTI_QUERIES CLIENT_MULTI_STATEMENTS
  746. #define FIELD_TYPE_DECIMAL MYSQL_TYPE_DECIMAL
  747. #define FIELD_TYPE_NEWDECIMAL MYSQL_TYPE_NEWDECIMAL
  748. #define FIELD_TYPE_TINY MYSQL_TYPE_TINY
  749. #define FIELD_TYPE_SHORT MYSQL_TYPE_SHORT
  750. #define FIELD_TYPE_LONG MYSQL_TYPE_LONG
  751. #define FIELD_TYPE_FLOAT MYSQL_TYPE_FLOAT
  752. #define FIELD_TYPE_DOUBLE MYSQL_TYPE_DOUBLE
  753. #define FIELD_TYPE_NULL MYSQL_TYPE_NULL
  754. #define FIELD_TYPE_TIMESTAMP MYSQL_TYPE_TIMESTAMP
  755. #define FIELD_TYPE_LONGLONG MYSQL_TYPE_LONGLONG
  756. #define FIELD_TYPE_INT24 MYSQL_TYPE_INT24
  757. #define FIELD_TYPE_DATE MYSQL_TYPE_DATE
  758. #define FIELD_TYPE_TIME MYSQL_TYPE_TIME
  759. #define FIELD_TYPE_DATETIME MYSQL_TYPE_DATETIME
  760. #define FIELD_TYPE_YEAR MYSQL_TYPE_YEAR
  761. #define FIELD_TYPE_NEWDATE MYSQL_TYPE_NEWDATE
  762. #define FIELD_TYPE_ENUM MYSQL_TYPE_ENUM
  763. #define FIELD_TYPE_SET MYSQL_TYPE_SET
  764. #define FIELD_TYPE_TINY_BLOB MYSQL_TYPE_TINY_BLOB
  765. #define FIELD_TYPE_MEDIUM_BLOB MYSQL_TYPE_MEDIUM_BLOB
  766. #define FIELD_TYPE_LONG_BLOB MYSQL_TYPE_LONG_BLOB
  767. #define FIELD_TYPE_BLOB MYSQL_TYPE_BLOB
  768. #define FIELD_TYPE_VAR_STRING MYSQL_TYPE_VAR_STRING
  769. #define FIELD_TYPE_STRING MYSQL_TYPE_STRING
  770. #define FIELD_TYPE_CHAR MYSQL_TYPE_TINY
  771. #define FIELD_TYPE_INTERVAL MYSQL_TYPE_ENUM
  772. #define FIELD_TYPE_GEOMETRY MYSQL_TYPE_GEOMETRY
  773. #define FIELD_TYPE_BIT MYSQL_TYPE_BIT
  774. /** @}*/
  775. /**
  776. @addtogroup group_cs_shutdown_kill_constants Shutdown/kill enums and constants
  777. @ingroup group_cs
  778. @sa THD::is_killable
  779. @{
  780. */
  781. #define MYSQL_SHUTDOWN_KILLABLE_CONNECT (unsigned char)(1 << 0)
  782. #define MYSQL_SHUTDOWN_KILLABLE_TRANS (unsigned char)(1 << 1)
  783. #define MYSQL_SHUTDOWN_KILLABLE_LOCK_TABLE (unsigned char)(1 << 2)
  784. #define MYSQL_SHUTDOWN_KILLABLE_UPDATE (unsigned char)(1 << 3)
  785. /**
  786. We want levels to be in growing order of hardness (because we use number
  787. comparisons).
  788. @note ::SHUTDOWN_DEFAULT does not respect the growing property, but it's ok.
  789. */
  790. enum mysql_enum_shutdown_level {
  791. SHUTDOWN_DEFAULT = 0,
  792. /** Wait for existing connections to finish */
  793. SHUTDOWN_WAIT_CONNECTIONS = MYSQL_SHUTDOWN_KILLABLE_CONNECT,
  794. /** Wait for existing transactons to finish */
  795. SHUTDOWN_WAIT_TRANSACTIONS = MYSQL_SHUTDOWN_KILLABLE_TRANS,
  796. /** Wait for existing updates to finish (=> no partial MyISAM update) */
  797. SHUTDOWN_WAIT_UPDATES = MYSQL_SHUTDOWN_KILLABLE_UPDATE,
  798. /** Flush InnoDB buffers and other storage engines' buffers*/
  799. SHUTDOWN_WAIT_ALL_BUFFERS = (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1),
  800. /** Don't flush InnoDB buffers, flush other storage engines' buffers*/
  801. SHUTDOWN_WAIT_CRITICAL_BUFFERS = (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1) + 1,
  802. /** Query level of the KILL command */
  803. KILL_QUERY = 254,
  804. /** Connection level of the KILL command */
  805. KILL_CONNECTION = 255
  806. };
  807. /** @}*/
  808. enum enum_resultset_metadata {
  809. /** No metadata will be sent. */
  810. RESULTSET_METADATA_NONE = 0,
  811. /** The server will send all metadata. */
  812. RESULTSET_METADATA_FULL = 1
  813. };
  814. #if defined(__clang__)
  815. // disable -Wdocumentation to workaround
  816. // https://bugs.llvm.org/show_bug.cgi?id=38905
  817. #pragma clang diagnostic push
  818. #pragma clang diagnostic ignored "-Wdocumentation"
  819. #endif
  820. /**
  821. The flags used in COM_STMT_EXECUTE.
  822. @sa @ref Protocol_classic::parse_packet, @ref mysql_int_serialize_param_data
  823. */
  824. #if defined(__clang__)
  825. #pragma clang diagnostic pop
  826. #endif
  827. enum enum_cursor_type {
  828. CURSOR_TYPE_NO_CURSOR = 0,
  829. CURSOR_TYPE_READ_ONLY = 1,
  830. CURSOR_TYPE_FOR_UPDATE = 2,
  831. CURSOR_TYPE_SCROLLABLE = 4,
  832. /**
  833. On when the client will send the parameter count
  834. even for 0 parameters.
  835. */
  836. PARAMETER_COUNT_AVAILABLE = 8
  837. };
  838. /** options for ::mysql_options() */
  839. enum enum_mysql_set_option {
  840. MYSQL_OPTION_MULTI_STATEMENTS_ON,
  841. MYSQL_OPTION_MULTI_STATEMENTS_OFF
  842. };
  843. /**
  844. Type of state change information that the server can include in the Ok
  845. packet.
  846. @note
  847. - session_state_type shouldn't go past 255 (i.e. 1-byte boundary).
  848. - Modify the definition of ::SESSION_TRACK_END when a new member is added.
  849. */
  850. enum enum_session_state_type {
  851. SESSION_TRACK_SYSTEM_VARIABLES, /**< Session system variables */
  852. SESSION_TRACK_SCHEMA, /**< Current schema */
  853. SESSION_TRACK_STATE_CHANGE, /**< track session state changes */
  854. SESSION_TRACK_GTIDS, /**< See also: session_track_gtids */
  855. SESSION_TRACK_TRANSACTION_CHARACTERISTICS, /**< Transaction chistics */
  856. SESSION_TRACK_TRANSACTION_STATE /**< Transaction state */
  857. };
  858. /** start of ::enum_session_state_type */
  859. #define SESSION_TRACK_BEGIN SESSION_TRACK_SYSTEM_VARIABLES
  860. /** End of ::enum_session_state_type */
  861. #define SESSION_TRACK_END SESSION_TRACK_TRANSACTION_STATE
  862. /** is T a valid session state type */
  863. #define IS_SESSION_STATE_TYPE(T) \
  864. (((int)(T) >= SESSION_TRACK_BEGIN) && ((T) <= SESSION_TRACK_END))
  865. #define net_new_transaction(net) ((net)->pkt_nr = 0)
  866. bool my_net_init(struct NET *net, MYSQL_VIO vio);
  867. void my_net_local_init(struct NET *net);
  868. void net_end(struct NET *net);
  869. void net_clear(struct NET *net, bool check_buffer);
  870. void net_claim_memory_ownership(struct NET *net, bool claim);
  871. bool net_realloc(struct NET *net, size_t length);
  872. bool net_flush(struct NET *net);
  873. bool my_net_write(struct NET *net, const unsigned char *packet, size_t len);
  874. bool net_write_command(struct NET *net, unsigned char command,
  875. const unsigned char *header, size_t head_len,
  876. const unsigned char *packet, size_t len);
  877. bool net_write_packet(struct NET *net, const unsigned char *packet,
  878. size_t length);
  879. unsigned long my_net_read(struct NET *net);
  880. void my_net_set_write_timeout(struct NET *net, unsigned int timeout);
  881. void my_net_set_read_timeout(struct NET *net, unsigned int timeout);
  882. void my_net_set_retry_count(struct NET *net, unsigned int retry_count);
  883. struct rand_struct {
  884. unsigned long seed1, seed2, max_value;
  885. double max_value_dbl;
  886. };
  887. /* Include the types here so existing UDFs can keep compiling */
  888. #include "mysql/udf_registration_types.h"
  889. /**
  890. @addtogroup group_cs_compresson_constants Constants when using compression
  891. @ingroup group_cs
  892. @{
  893. */
  894. #define NET_HEADER_SIZE 4 /**< standard header size */
  895. #define COMP_HEADER_SIZE 3 /**< compression header extra size */
  896. /** @}*/
  897. /* Prototypes to password functions */
  898. /*
  899. These functions are used for authentication by client and server and
  900. implemented in sql/password.c
  901. */
  902. void randominit(struct rand_struct *, unsigned long seed1, unsigned long seed2);
  903. double my_rnd(struct rand_struct *);
  904. void create_random_string(char *to, unsigned int length,
  905. struct rand_struct *rand_st);
  906. void hash_password(unsigned long *to, const char *password,
  907. unsigned int password_len);
  908. void make_scrambled_password_323(char *to, const char *password);
  909. void scramble_323(char *to, const char *message, const char *password);
  910. bool check_scramble_323(const unsigned char *reply, const char *message,
  911. unsigned long *salt);
  912. void get_salt_from_password_323(unsigned long *res, const char *password);
  913. void make_password_from_salt_323(char *to, const unsigned long *salt);
  914. void make_scrambled_password(char *to, const char *password);
  915. void scramble(char *to, const char *message, const char *password);
  916. bool check_scramble(const unsigned char *reply, const char *message,
  917. const unsigned char *hash_stage2);
  918. void get_salt_from_password(unsigned char *res, const char *password);
  919. void make_password_from_salt(char *to, const unsigned char *hash_stage2);
  920. char *octet2hex(char *to, const char *str, unsigned int len);
  921. /* end of password.c */
  922. bool generate_sha256_scramble(unsigned char *dst, size_t dst_size,
  923. const char *src, size_t src_size, const char *rnd,
  924. size_t rnd_size);
  925. // extern "C" since it is an (undocumented) part of the libmysql ABI.
  926. #ifdef __cplusplus
  927. extern "C" {
  928. #endif
  929. char *get_tty_password(const char *opt_message);
  930. #ifdef __cplusplus
  931. }
  932. #endif
  933. const char *mysql_errno_to_sqlstate(unsigned int mysql_errno);
  934. /* Some other useful functions */
  935. // Need to be extern "C" for the time being, due to memcached.
  936. #ifdef __cplusplus
  937. extern "C" {
  938. #endif
  939. bool my_thread_init(void);
  940. void my_thread_end(void);
  941. #ifdef __cplusplus
  942. }
  943. #endif
  944. #ifdef STDCALL
  945. unsigned long STDCALL net_field_length(unsigned char **packet);
  946. unsigned long STDCALL net_field_length_checked(unsigned char **packet,
  947. unsigned long max_length);
  948. #endif
  949. uint64_t net_field_length_ll(unsigned char **packet);
  950. unsigned char *net_store_length(unsigned char *pkg, unsigned long long length);
  951. unsigned int net_length_size(unsigned long long num);
  952. unsigned int net_field_length_size(const unsigned char *pos);
  953. #define NULL_LENGTH ((unsigned long)~0) /**< For ::net_store_length() */
  954. #define MYSQL_STMT_HEADER 4
  955. #define MYSQL_LONG_DATA_HEADER 6
  956. /* clang-format off */
  957. /**
  958. Describes the current state of Asynchronous connection phase state machine
  959. @startuml
  960. [*] --> CONNECT_STAGE_INVALID
  961. [*] --> CONNECT_STAGE_NOT_STARTED
  962. CONNECT_STAGE_NOT_STARTED --> CONNECT_STAGE_NET_BEGIN_CONNECT
  963. CONNECT_STAGE_NOT_STARTED --> CONNECT_STAGE_COMPLETE
  964. CONNECT_STAGE_NET_BEGIN_CONNECT --> CONNECT_STAGE_NET_WAIT_CONNECT
  965. CONNECT_STAGE_NET_BEGIN_CONNECT --> CONNECT_STAGE_NET_COMPLETE_CONNECT
  966. CONNECT_STAGE_NET_BEGIN_CONNECT --> STATE_MACHINE_FAILED
  967. CONNECT_STAGE_NET_WAIT_CONNECT --> CONNECT_STAGE_NET_COMPLETE_CONNECT
  968. CONNECT_STAGE_NET_WAIT_CONNECT --> STATE_MACHINE_FAILED
  969. CONNECT_STAGE_NET_COMPLETE_CONNECT --> STATE_MACHINE_FAILED
  970. CONNECT_STAGE_NET_COMPLETE_CONNECT --> CONNECT_STAGE_READ_GREETING
  971. CONNECT_STAGE_READ_GREETING --> STATE_MACHINE_FAILED
  972. CONNECT_STAGE_READ_GREETING --> CONNECT_STAGE_PARSE_HANDSHAKE
  973. CONNECT_STAGE_PARSE_HANDSHAKE --> STATE_MACHINE_FAILED
  974. CONNECT_STAGE_PARSE_HANDSHAKE --> CONNECT_STAGE_ESTABLISH_SSL
  975. CONNECT_STAGE_ESTABLISH_SSL --> STATE_MACHINE_FAILED
  976. CONNECT_STAGE_ESTABLISH_SSL --> CONNECT_STAGE_AUTHENTICATE
  977. CONNECT_STAGE_AUTHENTICATE --> STATE_MACHINE_FAILED
  978. CONNECT_STAGE_AUTHENTICATE --> CONNECT_STAGE_AUTH_BEGIN
  979. CONNECT_STAGE_AUTH_BEGIN --> STATE_MACHINE_FAILED
  980. CONNECT_STAGE_AUTH_BEGIN --> CONNECT_STAGE_AUTH_RUN_FIRST_AUTHENTICATE_USER
  981. CONNECT_STAGE_AUTH_RUN_FIRST_AUTHENTICATE_USER --> CONNECT_STAGE_AUTH_HANDLE_FIRST_AUTHENTICATE_USER
  982. CONNECT_STAGE_AUTH_HANDLE_FIRST_AUTHENTICATE_USER --> STATE_MACHINE_FAILED
  983. CONNECT_STAGE_AUTH_HANDLE_FIRST_AUTHENTICATE_USER --> CONNECT_STAGE_AUTH_READ_CHANGE_USER_RESULT
  984. CONNECT_STAGE_AUTH_READ_CHANGE_USER_RESULT --> CONNECT_STAGE_AUTH_HANDLE_CHANGE_USER_REQUEST
  985. CONNECT_STAGE_AUTH_HANDLE_CHANGE_USER_REQUEST --> STATE_MACHINE_FAILED
  986. CONNECT_STAGE_AUTH_HANDLE_CHANGE_USER_REQUEST --> CONNECT_STAGE_AUTH_RUN_SECOND_AUTHENTICATE_USER
  987. CONNECT_STAGE_AUTH_HANDLE_CHANGE_USER_REQUEST --> CONNECT_STAGE_AUTH_INIT_MULTI_AUTH
  988. CONNECT_STAGE_AUTH_HANDLE_CHANGE_USER_REQUEST --> CONNECT_STAGE_AUTH_FINISH_AUTH
  989. CONNECT_STAGE_AUTH_RUN_SECOND_AUTHENTICATE_USER --> STATE_MACHINE_FAILED
  990. CONNECT_STAGE_AUTH_RUN_SECOND_AUTHENTICATE_USER --> CONNECT_STAGE_AUTH_HANDLE_SECOND_AUTHENTICATE_USER
  991. CONNECT_STAGE_AUTH_HANDLE_SECOND_AUTHENTICATE_USER --> STATE_MACHINE_FAILED
  992. CONNECT_STAGE_AUTH_HANDLE_SECOND_AUTHENTICATE_USER --> CONNECT_STAGE_AUTH_INIT_MULTI_AUTH
  993. CONNECT_STAGE_AUTH_HANDLE_SECOND_AUTHENTICATE_USER --> CONNECT_STAGE_AUTH_FINISH_AUTH
  994. CONNECT_STAGE_AUTH_INIT_MULTI_AUTH --> STATE_MACHINE_FAILED
  995. CONNECT_STAGE_AUTH_INIT_MULTI_AUTH --> CONNECT_STAGE_AUTH_DO_MULTI_PLUGIN_AUTH
  996. CONNECT_STAGE_AUTH_DO_MULTI_PLUGIN_AUTH --> STATE_MACHINE_FAILED
  997. CONNECT_STAGE_AUTH_DO_MULTI_PLUGIN_AUTH --> CONNECT_STAGE_AUTH_HANDLE_MULTI_AUTH_RESPONSE
  998. CONNECT_STAGE_AUTH_HANDLE_MULTI_AUTH_RESPONSE --> STATE_MACHINE_FAILED
  999. CONNECT_STAGE_AUTH_HANDLE_MULTI_AUTH_RESPONSE --> CONNECT_STAGE_AUTH_INIT_MULTI_AUTH
  1000. CONNECT_STAGE_AUTH_HANDLE_MULTI_AUTH_RESPONSE --> CONNECT_STAGE_AUTH_FINISH_AUTH
  1001. CONNECT_STAGE_AUTH_FINISH_AUTH --> STATE_MACHINE_FAILED
  1002. CONNECT_STAGE_AUTH_FINISH_AUTH --> CONNECT_STAGE_PREP_SELECT_DATABASE
  1003. CONNECT_STAGE_PREP_SELECT_DATABASE --> CONNECT_STAGE_COMPLETE
  1004. CONNECT_STAGE_PREP_SELECT_DATABASE --> CONNECT_STAGE_PREP_INIT_COMMANDS
  1005. CONNECT_STAGE_PREP_INIT_COMMANDS --> CONNECT_STAGE_COMPLETE
  1006. CONNECT_STAGE_PREP_INIT_COMMANDS --> CONNECT_STAGE_SEND_ONE_INIT_COMMAND
  1007. CONNECT_STAGE_SEND_ONE_INIT_COMMAND --> CONNECT_STAGE_SEND_ONE_INIT_COMMAND
  1008. CONNECT_STAGE_SEND_ONE_INIT_COMMAND --> STATE_MACHINE_FAILED
  1009. CONNECT_STAGE_SEND_ONE_INIT_COMMAND --> CONNECT_STAGE_COMPLETE
  1010. STATE_MACHINE_FAILED --> [*]
  1011. CONNECT_STAGE_COMPLETE --> [*]
  1012. CONNECT_STAGE_INVALID --> [*]
  1013. @enduml
  1014. */
  1015. /* clang-format on */
  1016. enum connect_stage {
  1017. /** MYSQL not valid or an unknown state */
  1018. CONNECT_STAGE_INVALID = 0,
  1019. /** not connected */
  1020. CONNECT_STAGE_NOT_STARTED,
  1021. /** begin connection to the server */
  1022. CONNECT_STAGE_NET_BEGIN_CONNECT,
  1023. /** wait for connection to be established */
  1024. CONNECT_STAGE_NET_WAIT_CONNECT,
  1025. /** init the local data structures post connect */
  1026. CONNECT_STAGE_NET_COMPLETE_CONNECT,
  1027. /** read the first packet */
  1028. CONNECT_STAGE_READ_GREETING,
  1029. /** parse the first packet */
  1030. CONNECT_STAGE_PARSE_HANDSHAKE,
  1031. /** tls establishment */
  1032. CONNECT_STAGE_ESTABLISH_SSL,
  1033. /** authentication phase */
  1034. CONNECT_STAGE_AUTHENTICATE,
  1035. /** determine the plugin to use */
  1036. CONNECT_STAGE_AUTH_BEGIN,
  1037. /** run first auth plugin */
  1038. CONNECT_STAGE_AUTH_RUN_FIRST_AUTHENTICATE_USER,
  1039. /** handle the result of the first auth plugin run */
  1040. CONNECT_STAGE_AUTH_HANDLE_FIRST_AUTHENTICATE_USER,
  1041. /** read the implied changed user auth, if any */
  1042. CONNECT_STAGE_AUTH_READ_CHANGE_USER_RESULT,
  1043. /** Check if server asked to use a different authentication plugin */
  1044. CONNECT_STAGE_AUTH_HANDLE_CHANGE_USER_REQUEST,
  1045. /** Start the authentication process again with the plugin which
  1046. server asked for */
  1047. CONNECT_STAGE_AUTH_RUN_SECOND_AUTHENTICATE_USER,
  1048. /** Start multi factor authentication */
  1049. CONNECT_STAGE_AUTH_INIT_MULTI_AUTH,
  1050. /** Final cleanup */
  1051. CONNECT_STAGE_AUTH_FINISH_AUTH,
  1052. /** Now read the results of the second plugin run */
  1053. CONNECT_STAGE_AUTH_HANDLE_SECOND_AUTHENTICATE_USER,
  1054. /** Invoke client plugins multi-auth authentication method */
  1055. CONNECT_STAGE_AUTH_DO_MULTI_PLUGIN_AUTH,
  1056. /** Handle response from client plugins authentication method */
  1057. CONNECT_STAGE_AUTH_HANDLE_MULTI_AUTH_RESPONSE,
  1058. /** Authenticated, set initial database if specified */
  1059. CONNECT_STAGE_PREP_SELECT_DATABASE,
  1060. /** Prepare to send a sequence of init commands. */
  1061. CONNECT_STAGE_PREP_INIT_COMMANDS,
  1062. /** Send an init command. This is called once per init command until
  1063. they've all been run (or a failure occurs) */
  1064. CONNECT_STAGE_SEND_ONE_INIT_COMMAND,
  1065. /** Connected or no async connect in progress */
  1066. CONNECT_STAGE_COMPLETE
  1067. };
  1068. #endif