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