MySQL  8.0.16
Source Code Documentation
client.cc File Reference
#include "my_config.h"
#include <stdarg.h>
#include <sys/types.h>
#include "m_ctype.h"
#include "m_string.h"
#include "my_sys.h"
#include "mysys_err.h"
#include <netdb.h>
#include <stdio.h>
#include <string>
#include "client_async_authentication.h"
#include "errmsg.h"
#include "lex_string.h"
#include "map_helpers.h"
#include "my_byteorder.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_default.h"
#include "my_inttypes.h"
#include "my_io.h"
#include "my_loglevel.h"
#include "my_macros.h"
#include "my_psi_config.h"
#include "my_shm_defaults.h"
#include "mysql.h"
#include "mysql/client_authentication.h"
#include "mysql/plugin_auth_common.h"
#include "mysql/psi/mysql_memory.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql_version.h"
#include "mysqld_error.h"
#include "template_utils.h"
#include "typelib.h"
#include "violite.h"
#include "my_thread.h"
#include <signal.h>
#include <sys/stat.h>
#include <time.h>
#include <errno.h>
#include <mysql/client_plugin.h>
#include <new>
#include "../libmysql/init_commands_array.h"
#include "../libmysql/mysql_trace.h"
#include "sql_common.h"
#include "sql/client_settings.h"
#include "sql/log_event.h"
#include "sql/rpl_constants.h"
#include <stdlib.h>
#include <locale.h>

Classes

struct  MY_CSET_OS_NAME
 
struct  My_hash
 

Macros

#define SOCKET_ERROR   -1
 
#define STATE_DATA(M)   (NULL != (M) ? &(MYSQL_EXTENSION_PTR(M)->state_change) : NULL)
 
#define ADD_INFO(M, element, type)
 
#define native_password_plugin_name   "mysql_native_password"
 
#define caching_sha2_password_plugin_name   "caching_sha2_password"
 
#define ALLOCATE_EXTENSIONS(OPTS)
 
#define ENSURE_EXTENSIONS_PRESENT(OPTS)
 
#define EXTENSION_SET_STRING(OPTS, X, STR)
 
#define EXTENSION_SET_SSL_STRING(OPTS, X, STR, mode)
 
#define MAX_VARIABLE_STRING_LENGTH   9
 
#define MAX_CONNECTION_ATTR_STORAGE_LENGTH   65536
 
#define GTID_ENCODED_DATA_SIZE   8
 

Typedefs

typedef enum my_cs_match_type_enum my_cs_match_type
 

Enumerations

enum  option_id {
  OPTION_ID_COL_SEP, OPTION_ID_TBL_MAP_SEP, OPTION_ID_NUM_OPTIONS, OPT_port = 1,
  OPT_socket, OPT_compress, OPT_password, OPT_pipe,
  OPT_timeout, OPT_user, OPT_init_command, OPT_host,
  OPT_database, OPT_debug, OPT_return_found_rows, OPT_ssl_key,
  OPT_ssl_cert, OPT_ssl_ca, OPT_ssl_capath, OPT_character_sets_dir,
  OPT_default_character_set, OPT_interactive_timeout, OPT_connect_timeout, OPT_local_infile,
  OPT_disable_local_infile, OPT_ssl_cipher, OPT_max_allowed_packet, OPT_protocol,
  OPT_shared_memory_base_name, OPT_multi_results, OPT_multi_statements, OPT_multi_queries,
  OPT_report_data_truncation, OPT_plugin_dir, OPT_default_auth, OPT_bind_address,
  OPT_ssl_crl, OPT_ssl_crlpath, OPT_enable_cleartext_plugin, OPT_tls_version,
  OPT_ssl_mode, OPT_optional_resultset_metadata, OPT_ssl_fips_mode, OPT_tls_ciphersuites,
  OPT_keep_this_one_last
}
 
enum  my_cs_match_type_enum { my_cs_exact, my_cs_approx, my_cs_unsupp }
 

Functions

void init_client_psi_keys (void)
 
static void mysql_prune_stmt_list (MYSQL *mysql)
 For use when the connection to the server has been lost (in which case the server has discarded all information about prepared statements associated with the connection). More...
 
static int read_com_query_metadata (MYSQL *mysql, uchar *pos, ulong field_count)
 Read resultset metadata returned by COM_QUERY command. More...
 
static int read_one_row (MYSQL *mysql, uint fields, MYSQL_ROW row, ulong *lengths)
 
static net_async_status read_one_row_nonblocking (MYSQL *mysql, uint fields, MYSQL_ROW row, ulong *lengths, int *res)
 
static int get_vio_connect_timeout (MYSQL *mysql)
 Convert the connect timeout option to a timeout value for VIO functions (vio_socket_connect() and vio_io_wait()). More...
 
void set_mysql_error (MYSQL *mysql, int errcode, const char *sqlstate)
 Set the internal error message to mysql handler. More...
 
static bool my_net_is_inited (NET *net)
 Is this NET instance initialized? my_net_init() and net_end() More...
 
void net_clear_error (NET *net)
 Clear possible error state of struct NET. More...
 
void set_mysql_extended_error (MYSQL *mysql, int errcode, const char *sqlstate, const char *format,...)
 Set an error message on the client. More...
 
static void free_state_change_info (MYSQL_EXTENSION *ext)
 
void read_ok_ex (MYSQL *mysql, ulong length)
 Read Ok packet along with the server state change information. More...
 
static ulong cli_safe_read_with_ok_complete (MYSQL *mysql, bool parse_ok, bool *is_data_packet, ulong len)
 
net_async_status cli_safe_read_with_ok_nonblocking (MYSQL *mysql, bool parse_ok, bool *is_data_packet, ulong *res)
 Read a packet from server in asynchronous way. More...
 
net_async_status cli_safe_read_nonblocking (MYSQL *mysql, bool *is_data_packet, ulong *res)
 Its a non blocking version of cli_safe_read. More...
 
ulong cli_safe_read_with_ok (MYSQL *mysql, bool parse_ok, bool *is_data_packet)
 Read a packet from server. More...
 
ulong cli_safe_read (MYSQL *mysql, bool *is_data_packet)
 Read a packet from server. More...
 
void free_rows (MYSQL_DATA *cur)
 
bool cli_advanced_command (MYSQL *mysql, enum enum_server_command command, const uchar *header, size_t header_length, const uchar *arg, size_t arg_length, bool skip_check, MYSQL_STMT *stmt)
 
net_async_status cli_advanced_command_nonblocking (MYSQL *mysql, enum enum_server_command command, const uchar *header, ulong header_length, const uchar *arg, ulong arg_length, bool skip_check, MYSQL_STMT *stmt, bool *ret)
 
void free_old_query (MYSQL *mysql)
 
static net_async_status flush_one_result_nonblocking (MYSQL *mysql, bool *res)
 Finish reading of a partial result set from the server in asynchronous way. More...
 
static bool flush_one_result (MYSQL *mysql)
 Finish reading of a partial result set from the server. More...
 
static bool opt_flush_ok_packet (MYSQL *mysql, bool *is_ok_packet)
 Read a packet from network. More...
 
static net_async_status cli_flush_use_result_nonblocking (MYSQL *mysql, bool flush_all_results)
 
static void cli_flush_use_result (MYSQL *mysql, bool flush_all_results)
 
void end_server (MYSQL *mysql)
 
net_async_status STDCALL mysql_free_result_nonblocking (MYSQL_RES *result)
 Frees the memory allocated for a result, set by APIs which would have returned rows. More...
 
void STDCALL mysql_free_result (MYSQL_RES *result)
 
static int add_init_command (struct st_mysql_options *options, const char *cmd)
 
static char * set_ssl_option_unpack_path (const char *arg)
 
void mysql_read_default_options (struct st_mysql_options *options, const char *filename, const char *group)
 
static void cli_fetch_lengths (ulong *to, MYSQL_ROW column, unsigned int field_count)
 
static int unpack_field (MYSQL *mysql, MEM_ROOT *alloc, bool default_value, uint server_capabilities, MYSQL_ROWS *row, MYSQL_FIELD *field)
 Read field metadata from field descriptor and store it in MYSQL_FIELD structure. More...
 
MYSQL_FIELDunpack_fields (MYSQL *mysql, MYSQL_ROWS *data, MEM_ROOT *alloc, uint fields, bool default_value, uint server_capabilities)
 
net_async_status cli_read_metadata_ex_nonblocking (MYSQL *mysql, MEM_ROOT *alloc, ulong field_count, unsigned int field, MYSQL_FIELD **ret)
 Read metadata resultset from server in asynchronous way. More...
 
MYSQL_FIELDcli_read_metadata_ex (MYSQL *mysql, MEM_ROOT *alloc, ulong field_count, unsigned int field)
 Read metadata resultset from server Memory allocated in a given allocator root. More...
 
static int alloc_field_alloc (MYSQL *mysql)
 
MYSQL_FIELDcli_read_metadata (MYSQL *mysql, ulong field_count, unsigned int field)
 Read metadata resultset from server. More...
 
static net_async_status cli_read_metadata_nonblocking (MYSQL *mysql, ulong field_count, unsigned int field, MYSQL_FIELD **ret)
 Helper method to read metadata in asynchronous way. More...
 
static net_async_status read_com_query_metadata_nonblocking (MYSQL *mysql, uchar *pos, ulong field_count, int *res)
 Read resultset metadata returned by COM_QUERY command in asynchronous way. More...
 
net_async_status cli_read_rows_nonblocking (MYSQL *mysql, MYSQL_FIELD *mysql_fields, unsigned int fields, MYSQL_DATA **result_out)
 
MYSQL_DATAcli_read_rows (MYSQL *mysql, MYSQL_FIELD *mysql_fields, unsigned int fields)
 
static int read_one_row_complete (MYSQL *mysql, ulong pkt_len, bool is_data_packet, uint fields, MYSQL_ROW row, ulong *lengths)
 
MYSQL *STDCALL mysql_init (MYSQL *mysql)
 
MYSQL_EXTENSIONmysql_extension_init (MYSQL *mysql)
 
void mysql_extension_free (MYSQL_EXTENSION *ext)
 
bool STDCALL mysql_ssl_set (MYSQL *mysql, const char *key, const char *cert, const char *ca, const char *capath, const char *cipher)
 
const char *STDCALL mysql_get_ssl_cipher (MYSQL *mysql)
 
static bool cli_read_query_result (MYSQL *mysql)
 
static net_async_status cli_read_query_result_nonblocking (MYSQL *mysql)
 
static MYSQL_REScli_use_result (MYSQL *mysql)
 
int cli_read_change_user_result (MYSQL *mysql)
 
net_async_status cli_read_change_user_result_nonblocking (MYSQL *mysql, ulong *ret)
 
const char * my_os_charset_to_mysql_charset (const char *csname)
 
static int mysql_autodetect_character_set (MYSQL *mysql)
 
static void mysql_set_character_set_with_default_collation (MYSQL *mysql)
 
int mysql_init_character_set (MYSQL *mysql)
 
static int client_mpvio_write_packet (MYSQL_PLUGIN_VIO *mpv, const uchar *pkt, int pkt_len)
 vio->write_packet() callback method for client authentication plugins More...
 
static net_async_status client_mpvio_write_packet_nonblocking (struct MYSQL_PLUGIN_VIO *mpv, const uchar *pkt, int pkt_len, int *result)
 vio->write_packet() nonblocking callback method for client authentication plugins More...
 
static int native_password_auth_client (MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
 Client authentication plugin that does native MySQL authentication using a 20-byte (4.1+) scramble. More...
 
static net_async_status native_password_auth_client_nonblocking (MYSQL_PLUGIN_VIO *vio, MYSQL *mysql, int *result)
 Client authentication plugin that does native MySQL authentication in a nonblocking way. More...
 
static int clear_password_auth_client (MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
 The main function of the mysql_clear_password authentication plugin. More...
 
static ucharwrite_length_encoded_string3 (uchar *buf, const char *string, size_t length)
 
ucharsend_client_connect_attrs (MYSQL *mysql, uchar *buf)
 
static size_t get_length_store_length (size_t length)
 
static char * write_length_encoded_string4 (char *dest, char *dest_end, char *src, char *src_end)
 
static char * write_string (char *dest, char *dest_end, char *src, char *src_end)
 
static int send_change_user_packet (MCPVIO_EXT *mpvio, const uchar *data, int data_len)
 Sends a COM_CHANGE_USER with a caller provided payload. More...
 
static char * mysql_fill_packet_header (MYSQL *mysql, char *buff, size_t buff_size)
 Fill in the beginning of the client reply packet. More...
 
static void cli_calculate_client_flag (MYSQL *mysql, const char *db, ulong client_flag)
 Calcualtes client capabilities in effect (mysql->client_flag) More...
 
static int cli_establish_ssl (MYSQL *mysql)
 
Establishes SSL if requested and supported. More...
 
static net_async_status cli_establish_ssl_nonblocking (MYSQL *mysql, int *res)
 This function will establish asynchronous ssl connection by completing 4 different ssl connection states. More...
 
static mysql_state_machine_status authsm_begin_plugin_auth (mysql_async_auth *ctx)
 Asynchronous authentication phase is divided into several smaller chunks of subtasks like: More...
 
static mysql_state_machine_status authsm_run_first_authenticate_user (mysql_async_auth *ctx)
 Authentication can have two authenticate_user calls, depending on what the server responds with; this handles the first. More...
 
static mysql_state_machine_status authsm_handle_first_authenticate_user (mysql_async_auth *ctx)
 Handle the result of the first authenticate_user. More...
 
static mysql_state_machine_status authsm_read_change_user_result (mysql_async_auth *ctx)
 After the first authenticate_user comes a call to read the result of the implied change_user. More...
 
static mysql_state_machine_status authsm_handle_change_user_result (mysql_async_auth *ctx)
 Check if server asked to use a different authentication plugin. More...
 
static mysql_state_machine_status authsm_run_second_authenticate_user (mysql_async_auth *ctx)
 Start the authentication process again with the plugin which server asked for. More...
 
static mysql_state_machine_status authsm_handle_second_authenticate_user (mysql_async_auth *ctx)
 
static mysql_state_machine_status authsm_finish_auth (mysql_async_auth *ctx)
 
static mysql_state_machine_status csm_begin_connect (mysql_async_connect *ctx)
 Asynchronous connection phase is divided into several smaller modules where wach module does following: More...
 
static mysql_state_machine_status csm_complete_connect (mysql_async_connect *ctx)
 Complete the connection itself, setting options on the now-connected socket. More...
 
static mysql_state_machine_status csm_read_greeting (mysql_async_connect *ctx)
 Read the greeting from the server that is read the first packet. More...
 
static mysql_state_machine_status csm_parse_handshake (mysql_async_connect *ctx)
 Parse the handshake from the server. More...
 
static mysql_state_machine_status csm_establish_ssl (mysql_async_connect *ctx)
 Establish SSL if needed. More...
 
static mysql_state_machine_status csm_authenticate (mysql_async_connect *ctx)
 Invoke the authentication client plugin API to send the authentication data to the server. More...
 
static mysql_state_machine_status csm_prep_select_database (mysql_async_connect *ctx)
 Authenticated, set intial database if specified. More...
 
int mysql_get_socket_descriptor (MYSQL *mysql)
 
static bool prep_client_reply_packet (MCPVIO_EXT *mpvio, const uchar *data, int data_len, char **buff_out, int *buff_len)
 sends a client authentication packet (second packet in the 3-way handshake) More...
 
static int send_client_reply_packet (MCPVIO_EXT *mpvio, const uchar *data, int data_len)
 
static net_async_status send_client_reply_packet_nonblocking (MCPVIO_EXT *mpvio, const uchar *pkt, int pkt_len, bool *result)
 
static int client_mpvio_read_packet (MYSQL_PLUGIN_VIO *mpv, uchar **buf)
 vio->read_packet() callback method for client authentication plugins More...
 
static net_async_status client_mpvio_read_packet_nonblocking (struct MYSQL_PLUGIN_VIO *mpv, uchar **buf, int *result)
 vio->read_packet() nonblocking callback method for client authentication plugins More...
 
void mpvio_info (Vio *vio, MYSQL_PLUGIN_VIO_INFO *info)
 fills MYSQL_PLUGIN_VIO_INFO structure with the information about the connection More...
 
static void client_mpvio_info (MYSQL_PLUGIN_VIO *vio, MYSQL_PLUGIN_VIO_INFO *info)
 
static bool check_plugin_enabled (MYSQL *mysql, mysql_async_auth *ctx)
 
int run_plugin_auth (MYSQL *mysql, char *data, uint data_len, const char *data_plugin, const char *db)
 Client side of the plugin driver authentication. More...
 
mysql_state_machine_status run_plugin_auth_nonblocking (MYSQL *mysql, char *data, uint data_len, const char *data_plugin, const char *db)
 This functions drives the authentication on client side in a nonblocking way. More...
 
static int set_connect_attributes (MYSQL *mysql, char *buff, size_t buf_len)
 set some default attributes More...
 
MYSQL *STDCALL mysql_real_connect (MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, uint port, const char *unix_socket, ulong client_flag)
 
net_async_status STDCALL mysql_real_connect_nonblocking (MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, uint port, const char *unix_socket, ulong client_flag)
 This API attempts to initialize all the context needed to make an asynchronous connection followed by establishing a connection to MySQL database. More...
 
bool mysql_reconnect (MYSQL *mysql)
 
int STDCALL mysql_binlog_open (MYSQL *mysql, MYSQL_RPL *rpl)
 Open a new replication stream. More...
 
int STDCALL mysql_binlog_fetch (MYSQL *mysql, MYSQL_RPL *rpl)
 Fetch one event from the server. More...
 
void STDCALL mysql_binlog_close (MYSQL *mysql, MYSQL_RPL *rpl)
 Close replication stream. More...
 
int STDCALL mysql_select_db (MYSQL *mysql, const char *db)
 
void mysql_close_free_options (MYSQL *mysql)
 
void mysql_close_free (MYSQL *mysql)
 
void mysql_detach_stmt_list (LIST **stmt_list, const char *func_name)
 
void STDCALL mysql_close (MYSQL *mysql)
 
int STDCALL mysql_send_query (MYSQL *mysql, const char *query, ulong length)
 
net_async_status STDCALL mysql_send_query_nonblocking (MYSQL *mysql, const char *query, ulong length)
 Executes the SQL statement pointed by query. More...
 
int STDCALL mysql_real_query (MYSQL *mysql, const char *query, ulong length)
 
net_async_status STDCALL mysql_real_query_nonblocking (MYSQL *mysql, const char *query, ulong length)
 Executes the SQL statement pointed by query. More...
 
MYSQL_RES *STDCALL mysql_store_result (MYSQL *mysql)
 
enum net_async_status STDCALL mysql_store_result_nonblocking (MYSQL *mysql, MYSQL_RES **result)
 This API reads all result set sent by server in an asynchronous way. More...
 
MYSQL_ROW STDCALL mysql_fetch_row (MYSQL_RES *res)
 
net_async_status STDCALL mysql_fetch_row_nonblocking (MYSQL_RES *res, MYSQL_ROW *row)
 Reads next row of a result set in an asynchronous way. More...
 
ulong *STDCALL mysql_fetch_lengths (MYSQL_RES *res)
 
int STDCALL mysql_options (MYSQL *mysql, enum mysql_option option, const void *arg)
 
int STDCALL mysql_get_option (MYSQL *mysql, enum mysql_option option, const void *arg)
 Return the current values for the options settable through mysql_options() More...
 
int STDCALL mysql_options4 (MYSQL *mysql, enum mysql_option option, const void *arg1, const void *arg2)
 
my_ulonglong STDCALL mysql_num_rows (MYSQL_RES *res)
 
unsigned int STDCALL mysql_num_fields (MYSQL_RES *res)
 
uint STDCALL mysql_errno (MYSQL *mysql)
 
const char *STDCALL mysql_error (MYSQL *mysql)
 
static int get_data_and_length (LIST *node, const char **data, size_t *length)
 Read data and its length from a LIST node. More...
 
int STDCALL mysql_session_track_get_first (MYSQL *mysql, enum enum_session_state_type type, const char **data, size_t *length)
 Get the first state change information received from the server. More...
 
int STDCALL mysql_session_track_get_next (MYSQL *mysql, enum enum_session_state_type type, const char **data, size_t *length)
 Get the subsequent state change information received from the server. More...
 
ulong STDCALL mysql_get_server_version (MYSQL *mysql)
 
int STDCALL mysql_set_character_set (MYSQL *mysql, const char *cs_name)
 

Variables

PSI_memory_key key_memory_mysql_options
 
PSI_memory_key key_memory_MYSQL_DATA
 
PSI_memory_key key_memory_MYSQL
 
PSI_memory_key key_memory_MYSQL_RES
 
PSI_memory_key key_memory_MYSQL_ROW
 
PSI_memory_key key_memory_MYSQL_state_change_info
 
PSI_memory_key key_memory_MYSQL_HANDSHAKE
 
static PSI_memory_info all_client_memory []
 
uint mysql_port = 0
 
char * mysql_unix_port = 0
 
const char * unknown_sqlstate = "HY000"
 
const char * not_error_sqlstate = "00000"
 
const char * cant_connect_sqlstate = "08001"
 
ulong g_net_buffer_length = 8192
 
ulong g_max_allowed_packet = 1024L * 1024L * 1024L
 
CHARSET_INFOdefault_client_charset_info = &my_charset_latin1
 
unsigned int mysql_server_last_errno
 
char mysql_server_last_error [MYSQL_ERRMSG_SIZE]
 
static const char * default_options []
 
static TYPELIB option_types
 
const char * sql_protocol_names_lib []
 
TYPELIB sql_protocol_typelib
 
static MYSQL_METHODS client_methods
 
const MY_CSET_OS_NAME charsets []
 
static auth_plugin_t native_password_client_plugin
 
static auth_plugin_t clear_password_client_plugin
 
struct st_mysql_client_pluginmysql_client_builtins []
 
bool libmysql_cleartext_plugin_enabled = 0
 

Macro Definition Documentation

◆ ADD_INFO

#define ADD_INFO (   M,
  element,
  type 
)
Value:
{ \
M = STATE_DATA(mysql); \
M->info_list[type].head_node = \
list_add(M->info_list[type].head_node, element); \
}
#define M
Definition: ctype-tis620.cc:71
int type
Definition: http_common.h:411
#define STATE_DATA(M)
Definition: client.cc:136
static MYSQL mysql
Definition: mysql.cc:150

◆ ALLOCATE_EXTENSIONS

#define ALLOCATE_EXTENSIONS (   OPTS)
Value:
(OPTS)->extension = (struct st_mysql_options_extention *)my_malloc( \
#define MY_WME
Definition: my_sys.h:114
PSI_memory_key key_memory_mysql_options
Definition: client.cc:149
#define MYF(v)
Definition: my_inttypes.h:131
Definition: sql_common.h:117
#define MY_ZEROFILL
Definition: my_memory.cc:43
void * my_malloc(PSI_memory_key key, size_t size, int flags)
Below functions are used by the components.
Definition: my_memory.cc:57

◆ caching_sha2_password_plugin_name

#define caching_sha2_password_plugin_name   "caching_sha2_password"

◆ ENSURE_EXTENSIONS_PRESENT

#define ENSURE_EXTENSIONS_PRESENT (   OPTS)
Value:
do { \
if (!(OPTS)->extension) ALLOCATE_EXTENSIONS(OPTS); \
} while (0)
#define ALLOCATE_EXTENSIONS(OPTS)
Definition: client.cc:1939

◆ EXTENSION_SET_SSL_STRING

#define EXTENSION_SET_SSL_STRING (   OPTS,
  X,
  STR,
  mode 
)
Value:
do { \
; \
} while (0)

◆ EXTENSION_SET_STRING

#define EXTENSION_SET_STRING (   OPTS,
  X,
  STR 
)
Value:
do { \
if ((OPTS)->extension) \
my_free((OPTS)->extension->X); \
(OPTS)->extension->X = \
((STR) != NULL) \
: NULL; \
} while (0)
#define MY_WME
Definition: my_sys.h:114
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
char * my_strdup(PSI_memory_key key, const char *from, myf_t flags)
Definition: my_malloc.cc:292
PSI_memory_key key_memory_mysql_options
Definition: client.cc:149
#define MYF(v)
Definition: my_inttypes.h:131
#define ALLOCATE_EXTENSIONS(OPTS)
Definition: client.cc:1939

◆ GTID_ENCODED_DATA_SIZE

#define GTID_ENCODED_DATA_SIZE   8

◆ MAX_CONNECTION_ATTR_STORAGE_LENGTH

#define MAX_CONNECTION_ATTR_STORAGE_LENGTH   65536

◆ MAX_VARIABLE_STRING_LENGTH

#define MAX_VARIABLE_STRING_LENGTH   9

◆ native_password_plugin_name

#define native_password_plugin_name   "mysql_native_password"

◆ SOCKET_ERROR

#define SOCKET_ERROR   -1

◆ STATE_DATA

#define STATE_DATA (   M)    (NULL != (M) ? &(MYSQL_EXTENSION_PTR(M)->state_change) : NULL)

Typedef Documentation

◆ my_cs_match_type

Enumeration Type Documentation

◆ my_cs_match_type_enum

Enumerator
my_cs_exact 
my_cs_approx 
my_cs_unsupp 

◆ option_id

enum option_id
Enumerator
OPTION_ID_COL_SEP 

ID for character(s) separating multiple column mapping.

OPTION_ID_TBL_MAP_SEP 

ID for character(s) separating table map name and key.

OPTION_ID_NUM_OPTIONS 

number of options

OPT_port 
OPT_socket 
OPT_compress 
OPT_password 
OPT_pipe 
OPT_timeout 
OPT_user 
OPT_init_command 
OPT_host 
OPT_database 
OPT_debug 
OPT_return_found_rows 
OPT_ssl_key 
OPT_ssl_cert 
OPT_ssl_ca 
OPT_ssl_capath 
OPT_character_sets_dir 
OPT_default_character_set 
OPT_interactive_timeout 
OPT_connect_timeout 
OPT_local_infile 
OPT_disable_local_infile 
OPT_ssl_cipher 
OPT_max_allowed_packet 
OPT_protocol 
OPT_shared_memory_base_name 
OPT_multi_results 
OPT_multi_statements 
OPT_multi_queries 
OPT_report_data_truncation 
OPT_plugin_dir 
OPT_default_auth 
OPT_bind_address 
OPT_ssl_crl 
OPT_ssl_crlpath 
OPT_enable_cleartext_plugin 
OPT_tls_version 
OPT_ssl_mode 
OPT_optional_resultset_metadata 
OPT_ssl_fips_mode 
OPT_tls_ciphersuites 
OPT_keep_this_one_last 

Function Documentation

◆ add_init_command()

static int add_init_command ( struct st_mysql_options options,
const char *  cmd 
)
static

◆ alloc_field_alloc()

static int alloc_field_alloc ( MYSQL mysql)
static

◆ authsm_begin_plugin_auth()

static mysql_state_machine_status authsm_begin_plugin_auth ( mysql_async_auth ctx)
static

Asynchronous authentication phase is divided into several smaller chunks of subtasks like:

Determine the default/initial plugin to use.

  1. Determine the default/initial plugin to use
  2. Call authentication plugin API
  3. Handle response from authentication plugin API
  4. Check if server asked to use a different authentication plugin
  5. In case server asked to use a different authentication plugin use that plugin to start the authentication process again.
  6. Complete authentication.

All above tasks are implemented in below authsm_* functions where authsm stads for authentication state machine.

◆ authsm_finish_auth()

static mysql_state_machine_status authsm_finish_auth ( mysql_async_auth ctx)
static

◆ authsm_handle_change_user_result()

static mysql_state_machine_status authsm_handle_change_user_result ( mysql_async_auth ctx)
static

Check if server asked to use a different authentication plugin.

◆ authsm_handle_first_authenticate_user()

static mysql_state_machine_status authsm_handle_first_authenticate_user ( mysql_async_auth ctx)
static

Handle the result of the first authenticate_user.

◆ authsm_handle_second_authenticate_user()

static mysql_state_machine_status authsm_handle_second_authenticate_user ( mysql_async_auth ctx)
static

◆ authsm_read_change_user_result()

static mysql_state_machine_status authsm_read_change_user_result ( mysql_async_auth ctx)
static

After the first authenticate_user comes a call to read the result of the implied change_user.

◆ authsm_run_first_authenticate_user()

static mysql_state_machine_status authsm_run_first_authenticate_user ( mysql_async_auth ctx)
static

Authentication can have two authenticate_user calls, depending on what the server responds with; this handles the first.

◆ authsm_run_second_authenticate_user()

static mysql_state_machine_status authsm_run_second_authenticate_user ( mysql_async_auth ctx)
static

Start the authentication process again with the plugin which server asked for.

◆ check_plugin_enabled()

static bool check_plugin_enabled ( MYSQL mysql,
mysql_async_auth ctx 
)
static

◆ clear_password_auth_client()

static int clear_password_auth_client ( MYSQL_PLUGIN_VIO vio,
MYSQL mysql 
)
static

The main function of the mysql_clear_password authentication plugin.

◆ cli_advanced_command()

bool cli_advanced_command ( MYSQL mysql,
enum enum_server_command  command,
const uchar header,
size_t  header_length,
const uchar arg,
size_t  arg_length,
bool  skip_check,
MYSQL_STMT stmt 
)

◆ cli_advanced_command_nonblocking()

net_async_status cli_advanced_command_nonblocking ( MYSQL mysql,
enum enum_server_command  command,
const uchar header,
ulong  header_length,
const uchar arg,
ulong  arg_length,
bool  skip_check,
MYSQL_STMT stmt,
bool ret 
)

◆ cli_calculate_client_flag()

static void cli_calculate_client_flag ( MYSQL mysql,
const char *  db,
ulong  client_flag 
)
static

Calcualtes client capabilities in effect (mysql->client_flag)

Needs to be called immediately after receiving the server handshake packet.

Parameters
mysqlthe connection context
dbThe database specified by the client app
client_flagThe client flag as specified by the client app

◆ cli_establish_ssl()

static int cli_establish_ssl ( MYSQL mysql)
static


Establishes SSL if requested and supported.

Parameters
mysqlthe connection handle
Return values
0success
1failure

◆ cli_establish_ssl_nonblocking()

static net_async_status cli_establish_ssl_nonblocking ( MYSQL mysql,
int *  res 
)
static

This function will establish asynchronous ssl connection by completing 4 different ssl connection states.

Initial state is set to SSL_NONE during which this functions does priliminary checks like if server supports ssl or not, if CA certificate is required etc. Once preliminary checks are done state is changed to SSL_REQUEST. In this state ssl request packet is sent by client. If this network IO is complete, state is changed to SSL_CONNECT. During SSL_CONNECT sslconnect() is called which can return immediately or complete SSL handshake. If it returns immediately client will save all SSL context in struct mysql_async_auth, so that next call to this function will ensure that SSL_new() is not called twice. Once ssl connection is established state is changed to SSL_COMPLETE.

Parameters
[in]mysqlClient connection handle.
[out]resset to false incase of success and true for error.
Return values
NET_ASYNC_NOT_READYssl connection not yet established
NET_ASYNC_COMPLETEssl connection established

◆ cli_fetch_lengths()

static void cli_fetch_lengths ( ulong to,
MYSQL_ROW  column,
unsigned int  field_count 
)
static

◆ cli_flush_use_result()

static void cli_flush_use_result ( MYSQL mysql,
bool  flush_all_results 
)
static

◆ cli_flush_use_result_nonblocking()

static net_async_status cli_flush_use_result_nonblocking ( MYSQL mysql,
bool  flush_all_results 
)
static

◆ cli_read_change_user_result()

int cli_read_change_user_result ( MYSQL mysql)

◆ cli_read_change_user_result_nonblocking()

net_async_status cli_read_change_user_result_nonblocking ( MYSQL mysql,
ulong ret 
)

◆ cli_read_metadata()

MYSQL_FIELD* cli_read_metadata ( MYSQL mysql,
ulong  field_count,
unsigned int  field 
)

Read metadata resultset from server.

Parameters
[in]mysqlconnection handle
[in]field_counttotal number of fields
[in]fieldnumber of columns in single field descriptor
Return values
anarray of field rows

◆ cli_read_metadata_ex()

MYSQL_FIELD* cli_read_metadata_ex ( MYSQL mysql,
MEM_ROOT alloc,
ulong  field_count,
unsigned int  field 
)

Read metadata resultset from server Memory allocated in a given allocator root.

Parameters
[in]mysqlconnection handle
[in]allocmemory allocator root
[in]field_counttotal number of fields
[in]fieldnumber of columns in single field descriptor
Return values
anarray of field rows

◆ cli_read_metadata_ex_nonblocking()

net_async_status cli_read_metadata_ex_nonblocking ( MYSQL mysql,
MEM_ROOT alloc,
ulong  field_count,
unsigned int  field,
MYSQL_FIELD **  ret 
)

Read metadata resultset from server in asynchronous way.

Parameters
[in]mysqlconnection handle
[in]allocmemory allocator root
[in]field_counttotal number of fields
[in]fieldnumber of columns in single field descriptor
[out]retan array of field rows
Return values
NET_ASYNC_NOT_READYmetadata resultset not read completely
NET_ASYNC_COMPLETEfinished reading metadata resultset

◆ cli_read_metadata_nonblocking()

static net_async_status cli_read_metadata_nonblocking ( MYSQL mysql,
ulong  field_count,
unsigned int  field,
MYSQL_FIELD **  ret 
)
static

Helper method to read metadata in asynchronous way.

◆ cli_read_query_result()

static bool cli_read_query_result ( MYSQL mysql)
static

◆ cli_read_query_result_nonblocking()

static net_async_status cli_read_query_result_nonblocking ( MYSQL mysql)
static

◆ cli_read_rows()

MYSQL_DATA* cli_read_rows ( MYSQL mysql,
MYSQL_FIELD mysql_fields,
unsigned int  fields 
)

◆ cli_read_rows_nonblocking()

net_async_status cli_read_rows_nonblocking ( MYSQL mysql,
MYSQL_FIELD mysql_fields,
unsigned int  fields,
MYSQL_DATA **  result_out 
)

◆ cli_safe_read()

ulong cli_safe_read ( MYSQL mysql,
bool is_data_packet 
)

Read a packet from server.

Give error message if connection was broken or ERR packet was received. Detect if the packet received was an OK, ERR or something else (a "data packet").

Parameters
[in]mysqlconnection handle
[out]is_data_packetif set to true then the packet received was a "data packet".
Return values
Thelength of the packet that was read or packet_error in case of error. In case of error its description is stored in mysql handle.

◆ cli_safe_read_nonblocking()

net_async_status cli_safe_read_nonblocking ( MYSQL mysql,
bool is_data_packet,
ulong res 
)

Its a non blocking version of cli_safe_read.

◆ cli_safe_read_with_ok()

ulong cli_safe_read_with_ok ( MYSQL mysql,
bool  parse_ok,
bool is_data_packet 
)

Read a packet from server.

Give error message if socket was down or packet is an error message

Parameters
[in]mysqlconnection handle
[in]parse_okif set to true then parse OK packet if it is received
[out]is_data_packetif set to true then packet received is a "data packet", that is not OK or ERR packet or EOF in case of old servers
Returns
The length of the packet that was read or packet_error in case of error. In case of error its description is stored in mysql handle.

◆ cli_safe_read_with_ok_complete()

ulong cli_safe_read_with_ok_complete ( MYSQL mysql,
bool  parse_ok,
bool is_data_packet,
ulong  len 
)
static

◆ cli_safe_read_with_ok_nonblocking()

net_async_status cli_safe_read_with_ok_nonblocking ( MYSQL mysql,
bool  parse_ok,
bool is_data_packet,
ulong res 
)

Read a packet from server in asynchronous way.

This function can return without completly reading the packet, in such a case call this function again until complete packet is read.

Parameters
[in]mysqlconnection handle
[in]parse_okif set to true then parse OK packet if it was sent by server
[out]is_data_packetif set to true then the packet received was a "data packet".
[out]resThe length of the packet that was read or packet_error in case of error.
Return values
NET_ASYNC_NOT_READYpacket was not completely read
NET_ASYNC_COMPLETEfinished reading packet

◆ cli_use_result()

static MYSQL_RES * cli_use_result ( MYSQL mysql)
static

◆ client_mpvio_info()

static void client_mpvio_info ( MYSQL_PLUGIN_VIO vio,
MYSQL_PLUGIN_VIO_INFO info 
)
static

◆ client_mpvio_read_packet()

static int client_mpvio_read_packet ( MYSQL_PLUGIN_VIO mpv,
uchar **  buf 
)
static

vio->read_packet() callback method for client authentication plugins

This function is called by a client authentication plugin, when it wants to read data from the server.

◆ client_mpvio_read_packet_nonblocking()

static net_async_status client_mpvio_read_packet_nonblocking ( struct MYSQL_PLUGIN_VIO mpv,
uchar **  buf,
int *  result 
)
static

vio->read_packet() nonblocking callback method for client authentication plugins

◆ client_mpvio_write_packet()

static int client_mpvio_write_packet ( MYSQL_PLUGIN_VIO mpv,
const uchar pkt,
int  pkt_len 
)
static

vio->write_packet() callback method for client authentication plugins

This function is called by a client authentication plugin, when it wants to send data to the server.

It transparently wraps the data into a change user or authentication handshake packet, if neccessary.

◆ client_mpvio_write_packet_nonblocking()

static net_async_status client_mpvio_write_packet_nonblocking ( struct MYSQL_PLUGIN_VIO mpv,
const uchar pkt,
int  pkt_len,
int *  result 
)
static

vio->write_packet() nonblocking callback method for client authentication plugins

◆ csm_authenticate()

static mysql_state_machine_status csm_authenticate ( mysql_async_connect ctx)
static

Invoke the authentication client plugin API to send the authentication data to the server.

◆ csm_begin_connect()

static mysql_state_machine_status csm_begin_connect ( mysql_async_connect ctx)
static

Asynchronous connection phase is divided into several smaller modules where wach module does following:

Begin the connection to the server, including any DNS resolution necessary, socket configuration, etc.

  1. Begin the connection to the server, including any DNS resolution necessary, socket configuration, etc
  2. Complete the connection itself
  3. Connection established, read the first packet
  4. Parse the handshake from the server
  5. Establish SSL connection if needed
  6. Invoke the plugin to send the authentication data to the server
  7. Authenticated, set intial database if specified
  8. Send COM_INIT_DB.
  9. Prepare to send a sequence of init commands. 10.Send an init command.

Below are the modules which does all above tasks.

◆ csm_complete_connect()

static mysql_state_machine_status csm_complete_connect ( mysql_async_connect ctx)
static

Complete the connection itself, setting options on the now-connected socket.

◆ csm_establish_ssl()

static mysql_state_machine_status csm_establish_ssl ( mysql_async_connect ctx)
static

Establish SSL if needed.

◆ csm_parse_handshake()

static mysql_state_machine_status csm_parse_handshake ( mysql_async_connect ctx)
static

Parse the handshake from the server.

◆ csm_prep_select_database()

static mysql_state_machine_status csm_prep_select_database ( mysql_async_connect ctx)
static

Authenticated, set intial database if specified.

◆ csm_read_greeting()

static mysql_state_machine_status csm_read_greeting ( mysql_async_connect ctx)
static

Read the greeting from the server that is read the first packet.

◆ end_server()

void end_server ( MYSQL mysql)

◆ flush_one_result()

static bool flush_one_result ( MYSQL mysql)
static

Finish reading of a partial result set from the server.

Get the EOF packet, and update mysql->status and mysql->warning_count.

Returns
true if a communication or protocol error, an error is set in this case, false otherwise.

◆ flush_one_result_nonblocking()

static net_async_status flush_one_result_nonblocking ( MYSQL mysql,
bool res 
)
static

Finish reading of a partial result set from the server in asynchronous way.

This function can return without completly flushing the result set, in such a case call this function again until result set in flushed. Read OK packet incase result set is not a data packet.

Parameters
[in]mysqlconnection handle
[out]restrue in case of protocol error, false otherwise
Return values
NET_ASYNC_NOT_READYresult set not flushed yet
NET_ASYNC_COMPLETEfinished flushing result set

◆ free_old_query()

void free_old_query ( MYSQL mysql)

◆ free_rows()

void free_rows ( MYSQL_DATA cur)

◆ free_state_change_info()

static void free_state_change_info ( MYSQL_EXTENSION ext)
static

◆ get_data_and_length()

static int get_data_and_length ( LIST node,
const char **  data,
size_t *  length 
)
static

Read data and its length from a LIST node.

Assumes LIST which stores data blobs in LEX_STRING structures, where LEX_STRING::str is pointer to the data and LEX_STRING::length is the length of this data.

If node is NULL then data and length are set to NULL and 0, respectively, and function returns 0, otherwise, if data has been read from the node, function returns 1.

◆ get_length_store_length()

static size_t get_length_store_length ( size_t  length)
static

◆ get_vio_connect_timeout()

static int get_vio_connect_timeout ( MYSQL mysql)
static

Convert the connect timeout option to a timeout value for VIO functions (vio_socket_connect() and vio_io_wait()).

Parameters
mysqlConnection handle (client side).
Returns
The timeout value in milliseconds, or -1 if no timeout.

◆ init_client_psi_keys()

void init_client_psi_keys ( void  )

◆ mpvio_info()

void mpvio_info ( Vio vio,
MYSQL_PLUGIN_VIO_INFO info 
)

fills MYSQL_PLUGIN_VIO_INFO structure with the information about the connection

◆ my_net_is_inited()

static bool my_net_is_inited ( NET net)
static

Is this NET instance initialized? my_net_init() and net_end()

◆ my_os_charset_to_mysql_charset()

const char* my_os_charset_to_mysql_charset ( const char *  csname)

◆ mysql_autodetect_character_set()

static int mysql_autodetect_character_set ( MYSQL mysql)
static

◆ mysql_binlog_close()

void STDCALL mysql_binlog_close ( MYSQL mysql,
MYSQL_RPL rpl 
)

Close replication stream.

Parameters
mysqlConnection handle.
rplReplication stream information.

◆ mysql_binlog_fetch()

int STDCALL mysql_binlog_fetch ( MYSQL mysql,
MYSQL_RPL rpl 
)

Fetch one event from the server.

Read one packet and check its validity, set rpl->buffer and rpl->size accordingly.

Parameters
mysqlConnection handle.
rplReplication stream information.
Return values
-1Got error packet.
0Success.

◆ mysql_binlog_open()

int STDCALL mysql_binlog_open ( MYSQL mysql,
MYSQL_RPL rpl 
)

Open a new replication stream.

Compose and send COM_BINLOG_DUMP[_GTID] command using information in the MYSQL_RPL structure.

Caller must set the following MYSQL_RPL's slots: file_name_length, file_name, start_positions, server_id, flags and in case of MYSQL_RPL_GTID: gtid_set_size, gtid_set or fix_gtid_set/fix_gtid_set_arg which is used to compose command packet.

Note: we treat NULL rpl->file_name as an empty string. If rpl->file_name_length is 0, strlen(rpl->file_name) will be called to set it. If rpl->fix_gtid_set is not NULL it will be called to fill packet gtid set data (rpl->gtid_set is ignored).

Parameters
mysqlConnection handle.
rplReplication stream information.
Return values
-1Error.
0Success.

◆ mysql_close()

void STDCALL mysql_close ( MYSQL mysql)

◆ mysql_close_free()

void mysql_close_free ( MYSQL mysql)

◆ mysql_close_free_options()

void mysql_close_free_options ( MYSQL mysql)

◆ mysql_detach_stmt_list()

void mysql_detach_stmt_list ( LIST **  stmt_list,
const char *  func_name 
)

◆ mysql_errno()

uint STDCALL mysql_errno ( MYSQL mysql)

◆ mysql_error()

const char* STDCALL mysql_error ( MYSQL mysql)

◆ mysql_extension_free()

void mysql_extension_free ( MYSQL_EXTENSION ext)

◆ mysql_extension_init()

MYSQL_EXTENSION* mysql_extension_init ( MYSQL mysql)

◆ mysql_fetch_lengths()

ulong* STDCALL mysql_fetch_lengths ( MYSQL_RES res)

◆ mysql_fetch_row()

MYSQL_ROW STDCALL mysql_fetch_row ( MYSQL_RES res)

◆ mysql_fetch_row_nonblocking()

net_async_status STDCALL mysql_fetch_row_nonblocking ( MYSQL_RES res,
MYSQL_ROW row 
)

Reads next row of a result set in an asynchronous way.

Parameters
[in]resbuffer in which all rows are stored
[out]rowreturn pointer to one row from result set
Return values
NET_ASYNC_NOT_READYfetch operation not complete, retry again
NET_ASYNC_COMPLETEfetch operation complete

◆ mysql_fill_packet_header()

static char* mysql_fill_packet_header ( MYSQL mysql,
char *  buff,
size_t  buff_size 
)
static

Fill in the beginning of the client reply packet.

Used to fill in the beginning of the client reply packet or the ssl request packet.

Parameters
mysqlThe mysql handler to operate
[out]buffThe buffer to receive the packet
buff_sizeThe max size of the buffer. Used in debug only.
Returns
one past to where the buffer is filled
See also
page_protocol_conn_packets_protocol_ssl_request send_client_reply_packet()

◆ mysql_free_result()

void STDCALL mysql_free_result ( MYSQL_RES result)

◆ mysql_free_result_nonblocking()

net_async_status STDCALL mysql_free_result_nonblocking ( MYSQL_RES result)

Frees the memory allocated for a result, set by APIs which would have returned rows.

Parameters
[in]resultbuffer which needs to be freed
Return values
NET_ASYNC_NOT_READYoperation not complete, retry again
NET_ASYNC_COMPLETEoperation complete

◆ mysql_get_option()

int STDCALL mysql_get_option ( MYSQL mysql,
enum mysql_option  option,
const void *  arg 
)

Return the current values for the options settable through mysql_options()

Returns the current values for all of the connection options. Callers should not manipulate the returned data ! Data are valid at the time of returning them until the next C API CALL arg should always be a pointer to a variable of the appropriate type. type of variable, based on the parameter:

uint MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_READ_TIMEOUT, MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_PROTOCOL, MYSQL_OPT_SSL_MODE, MYSQL_OPT_RETRY_COUNT

bool MYSQL_OPT_COMPRESS, MYSQL_OPT_LOCAL_INFILE, MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, MYSQL_ENABLE_CLEARTEXT_PLUGIN, MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, MYSQL_OPT_OPTIONAL_RESULTSET_METADATA

const char * MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP, MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_SET_CLIENT_IP, MYSQL_OPT_BIND, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH, MYSQL_OPT_SSL_KEY, MYSQL_OPT_SSL_CERT, MYSQL_OPT_SSL_CA, MYSQL_OPT_SSL_CAPATH, MYSQL_OPT_SSL_CIPHER, MYSQL_OPT_TLS_CIPHERSUITES, MYSQL_OPT_SSL_CRL, MYSQL_OPT_SSL_CRLPATH, MYSQL_OPT_TLS_VERSION, MYSQL_SERVER_PUBLIC_KEY, MYSQL_OPT_SSL_FIPS_MODE

<none, error returned> MYSQL_OPT_NAMED_PIPE, MYSQL_OPT_CONNECT_ATTR_RESET, MYSQL_OPT_CONNECT_ATTR_DELETE, MYSQL_INIT_COMMAND

Parameters
mysqlThe MYSQL connection to operate on
optionThe option to return the value for
[out]argMust be non-null. Receives the current value.
Returns
status
Return values
0SUCCESS

◆ mysql_get_server_version()

ulong STDCALL mysql_get_server_version ( MYSQL mysql)

◆ mysql_get_socket_descriptor()

int mysql_get_socket_descriptor ( MYSQL mysql)

◆ mysql_get_ssl_cipher()

const char* STDCALL mysql_get_ssl_cipher ( MYSQL mysql)

◆ mysql_init()

MYSQL* STDCALL mysql_init ( MYSQL mysql)

◆ mysql_init_character_set()

int mysql_init_character_set ( MYSQL mysql)

◆ mysql_num_fields()

unsigned int STDCALL mysql_num_fields ( MYSQL_RES res)

◆ mysql_num_rows()

my_ulonglong STDCALL mysql_num_rows ( MYSQL_RES res)

◆ mysql_options()

int STDCALL mysql_options ( MYSQL mysql,
enum mysql_option  option,
const void *  arg 
)

◆ mysql_options4()

int STDCALL mysql_options4 ( MYSQL mysql,
enum mysql_option  option,
const void *  arg1,
const void *  arg2 
)

◆ mysql_prune_stmt_list()

static void mysql_prune_stmt_list ( MYSQL mysql)
static

For use when the connection to the server has been lost (in which case the server has discarded all information about prepared statements associated with the connection).

Mark all statements in mysql->stmts by setting stmt->mysql= 0 if the statement has transitioned beyond the MYSQL_STMT_INIT_DONE state, and unlink the statement from the mysql->stmts list.

The remaining pruned list of statements (if any) is kept in mysql->stmts.

Parameters
mysqlpointer to the MYSQL object

◆ mysql_read_default_options()

void mysql_read_default_options ( struct st_mysql_options options,
const char *  filename,
const char *  group 
)

◆ mysql_real_connect()

MYSQL* STDCALL mysql_real_connect ( MYSQL mysql,
const char *  host,
const char *  user,
const char *  passwd,
const char *  db,
uint  port,
const char *  unix_socket,
ulong  client_flag 
)

◆ mysql_real_connect_nonblocking()

net_async_status STDCALL mysql_real_connect_nonblocking ( MYSQL mysql,
const char *  host,
const char *  user,
const char *  passwd,
const char *  db,
uint  port,
const char *  unix_socket,
ulong  client_flag 
)

This API attempts to initialize all the context needed to make an asynchronous connection followed by establishing a connection to MySQL database.

If this API returns NET_ASYNC_COMPLETE then connection is established else call this API from the client application until the status returned is NET_ASYNC_COMPLETE.

Parameters
[in]mysqlconnection handle
[in]hosthost name or IP address
[in]userlogin ID used to connect to host
[in]passwdpassword for this login ID
[in]dbdefault database to be set after connection
[in]portport number to use for connection
[in]unix_socketsocket file to use for connection
[in]client_flagflag to indidcate what client can handle
Return values
NET_ASYNC_COMPLETESuccess.
NET_ASYNC_ERRORError.

◆ mysql_real_query()

int STDCALL mysql_real_query ( MYSQL mysql,
const char *  query,
ulong  length 
)

◆ mysql_real_query_nonblocking()

net_async_status STDCALL mysql_real_query_nonblocking ( MYSQL mysql,
const char *  query,
ulong  length 
)

Executes the SQL statement pointed by query.

This sql statement length is set in length parameter. query string can contain multiple sql statements separated by semicolons. This function can return immediately with status set to NET_ASYNC_NOT_READY, in this case client application is expected to call this API until it returns NET_ASYNC_COMPLETE.

Parameters
[in]mysqlconnection handle
[in]queryquery string to be executed
[in]lengthlength of query
Return values
NET_ASYNC_ERRORquery execution failed
NET_ASYNC_NOT_READYquery not yet completed, call this API again
NET_ASYNC_COMPLETEquery execution finished

◆ mysql_reconnect()

bool mysql_reconnect ( MYSQL mysql)

◆ mysql_select_db()

int STDCALL mysql_select_db ( MYSQL mysql,
const char *  db 
)

◆ mysql_send_query()

int STDCALL mysql_send_query ( MYSQL mysql,
const char *  query,
ulong  length 
)

◆ mysql_send_query_nonblocking()

net_async_status STDCALL mysql_send_query_nonblocking ( MYSQL mysql,
const char *  query,
ulong  length 
)

Executes the SQL statement pointed by query.

This API is called by mysql_real_query_nonblocking to send query to server in asynchronous way.

Parameters
[in]mysqlconnection handle
[in]queryquery string to be executed
[in]lengthlength of query
Return values
NET_ASYNC_ERRORquery execution failed
NET_ASYNC_NOT_READYquery not yet completed, call this API again
NET_ASYNC_COMPLETEquery execution finished

◆ mysql_session_track_get_first()

int STDCALL mysql_session_track_get_first ( MYSQL mysql,
enum enum_session_state_type  type,
const char **  data,
size_t *  length 
)

Get the first state change information received from the server.

Parameters
[in]mysqlmysql handle
[in]typestate change type
[out]databuffer to store the data
[out]lengthlength of the data
Returns
0 - Valid data stored 1 - No data

◆ mysql_session_track_get_next()

int STDCALL mysql_session_track_get_next ( MYSQL mysql,
enum enum_session_state_type  type,
const char **  data,
size_t *  length 
)

Get the subsequent state change information received from the server.

Parameters
[in]mysqlmysql handle
[in]typestate change type
[out]databuffer to store the data
[out]lengthlength of the data
Returns
0 - Valid data stored 1 - No data

◆ mysql_set_character_set()

int STDCALL mysql_set_character_set ( MYSQL mysql,
const char *  cs_name 
)

◆ mysql_set_character_set_with_default_collation()

static void mysql_set_character_set_with_default_collation ( MYSQL mysql)
static

◆ mysql_ssl_set()

bool STDCALL mysql_ssl_set ( MYSQL mysql,
const char *  key,
const char *  cert,
const char *  ca,
const char *  capath,
const char *  cipher 
)

◆ mysql_store_result()

MYSQL_RES* STDCALL mysql_store_result ( MYSQL mysql)

◆ mysql_store_result_nonblocking()

enum net_async_status STDCALL mysql_store_result_nonblocking ( MYSQL mysql,
MYSQL_RES **  result 
)

This API reads all result set sent by server in an asynchronous way.

Parameters
[in]mysqlconnection handle
[in]resultbuffer which holds all result sets.
Return values
NET_ASYNC_NOT_READYreading of result sets not complete
NET_ASYNC_COMPLETEcompleted this asynchronous operation

◆ native_password_auth_client()

static int native_password_auth_client ( MYSQL_PLUGIN_VIO vio,
MYSQL mysql 
)
static

Client authentication plugin that does native MySQL authentication using a 20-byte (4.1+) scramble.

Parameters
viothe channel to operate on
mysqlthe MYSQL structure to operate on
Return values
-1CR_OK : Success
1CR_ERROR : error reading
2012CR_SERVER_HANDSHAKE_ERR : malformed handshake data

◆ native_password_auth_client_nonblocking()

static net_async_status native_password_auth_client_nonblocking ( MYSQL_PLUGIN_VIO vio,
MYSQL mysql,
int *  result 
)
static

Client authentication plugin that does native MySQL authentication in a nonblocking way.

Parameters
[in]viothe channel to operate on
[in]mysqlthe MYSQL structure to operate on
[out]resultCR_OK : Success, CR_ERROR : error reading, CR_SERVER_HANDSHAKE_ERR : malformed handshake data
Return values
NET_ASYNC_NOT_READYauthentication not yet complete
NET_ASYNC_COMPLETEauthentication done

◆ net_clear_error()

void net_clear_error ( NET net)

Clear possible error state of struct NET.

Parameters
netclear the state of the argument

◆ opt_flush_ok_packet()

static bool opt_flush_ok_packet ( MYSQL mysql,
bool is_ok_packet 
)
static

Read a packet from network.

If it's an OK packet, flush it.

Returns
true if error, false otherwise. In case of success, is_ok_packet is set to true or false, based on what we got from network.

◆ prep_client_reply_packet()

static bool prep_client_reply_packet ( MCPVIO_EXT mpvio,
const uchar data,
int  data_len,
char **  buff_out,
int *  buff_len 
)
static

sends a client authentication packet (second packet in the 3-way handshake)

Parameters
mpvioThe connection to use
dataThe scramble to send
data_lenLength of data
buff_outBuffer holding client handshake packet
buff_lenLength of buffer holding client handshake packet
Return values
0ok
1error
See also
mysql_fill_packet_header() page_protocol_conn_packets_protocol_handshake_response

◆ read_com_query_metadata()

static int read_com_query_metadata ( MYSQL mysql,
uchar pos,
ulong  field_count 
)
static

Read resultset metadata returned by COM_QUERY command.

Parameters
[in]mysqlClient connection handle.
[in]posPosition in the packet where the metadata starts.
[in]field_countNumber of columns in the field descriptor.
Return values
0Success.
1Error.

◆ read_com_query_metadata_nonblocking()

static net_async_status read_com_query_metadata_nonblocking ( MYSQL mysql,
uchar pos,
ulong  field_count,
int *  res 
)
static

Read resultset metadata returned by COM_QUERY command in asynchronous way.

Parameters
[in]mysqlClient connection handle.
[in]posPosition in the packet where the metadata starts.
[in]field_countNumber of columns in the field descriptor.
[out]resset to false incase of success and true for error.
Return values
NET_ASYNC_NOT_READYmetadata resultset not read completely
NET_ASYNC_COMPLETEfinished reading metadata resultset

◆ read_ok_ex()

void read_ok_ex ( MYSQL mysql,
ulong  length 
)

Read Ok packet along with the server state change information.

◆ read_one_row()

static int read_one_row ( MYSQL mysql,
uint  fields,
MYSQL_ROW  row,
ulong lengths 
)
static

◆ read_one_row_complete()

static int read_one_row_complete ( MYSQL mysql,
ulong  pkt_len,
bool  is_data_packet,
uint  fields,
MYSQL_ROW  row,
ulong lengths 
)
static

◆ read_one_row_nonblocking()

static net_async_status read_one_row_nonblocking ( MYSQL mysql,
uint  fields,
MYSQL_ROW  row,
ulong lengths,
int *  res 
)
static

◆ run_plugin_auth()

int run_plugin_auth ( MYSQL mysql,
char *  data,
uint  data_len,
const char *  data_plugin,
const char *  db 
)

Client side of the plugin driver authentication.

Note
this is used by both the mysql_real_connect and mysql_change_user
Parameters
mysqlmysql
datapointer to the plugin auth data (scramble) in the handshake packet
data_lenthe length of the data
data_plugina plugin that data were prepared for or 0 if it's mysql_change_user()
dbinitial db to use, can be 0
Return values
0ok
1error

◆ run_plugin_auth_nonblocking()

mysql_state_machine_status run_plugin_auth_nonblocking ( MYSQL mysql,
char *  data,
uint  data_len,
const char *  data_plugin,
const char *  db 
)

This functions drives the authentication on client side in a nonblocking way.

This function will call differnt modules in a sequence where each module is responsible to acheive a particular part in entire authentication phase.

Note
this is used by both the mysql_real_connect_nonblocking
Parameters
mysqlmysql
datapointer to the plugin auth data (scramble) in the handshake packet
data_lenthe length of the data
data_plugina plugin that data were prepared for or 0 if it's mysql_change_user()
dbinitial db to use, can be 0
Return values
NET_ASYNC_NOT_READYauthentication not yet complete
NET_ASYNC_COMPLETEauthentication done

◆ send_change_user_packet()

static int send_change_user_packet ( MCPVIO_EXT mpvio,
const uchar data,
int  data_len 
)
static

Sends a COM_CHANGE_USER with a caller provided payload.

Return values
0ok
1error

◆ send_client_connect_attrs()

uchar* send_client_connect_attrs ( MYSQL mysql,
uchar buf 
)

◆ send_client_reply_packet()

static int send_client_reply_packet ( MCPVIO_EXT mpvio,
const uchar data,
int  data_len 
)
static

◆ send_client_reply_packet_nonblocking()

static net_async_status send_client_reply_packet_nonblocking ( MCPVIO_EXT mpvio,
const uchar pkt,
int  pkt_len,
bool result 
)
static

◆ set_connect_attributes()

static int set_connect_attributes ( MYSQL mysql,
char *  buff,
size_t  buf_len 
)
static

set some default attributes

◆ set_mysql_error()

void set_mysql_error ( MYSQL mysql,
int  errcode,
const char *  sqlstate 
)

Set the internal error message to mysql handler.

Parameters
mysqlconnection handle (client side)
errcodeCR_ error code, passed to ER macro to get error text
sqlstateSQL standard sqlstate

◆ set_mysql_extended_error()

void set_mysql_extended_error ( MYSQL mysql,
int  errcode,
const char *  sqlstate,
const char *  format,
  ... 
)

Set an error message on the client.

Parameters
mysqlconnection handle
errcodeCR_* errcode, for client errors
sqlstateSQL standard sql state, unknown_sqlstate for the majority of client errors.
formaterror message template, in sprintf format
...variable number of arguments

◆ set_ssl_option_unpack_path()

static char* set_ssl_option_unpack_path ( const char *  arg)
static

◆ unpack_field()

static int unpack_field ( MYSQL mysql,
MEM_ROOT alloc,
bool  default_value,
uint  server_capabilities,
MYSQL_ROWS row,
MYSQL_FIELD field 
)
static

Read field metadata from field descriptor and store it in MYSQL_FIELD structure.

String values in MYSQL_FIELD are allocated in a given allocator root.

Parameters
mysqlconnection handle
allocmemory allocator root
default_valueflag telling if default values should be read from descriptor
server_capabilitiesprotocol capability flags which determine format of the descriptor
rowfield descriptor
fieldaddress of MYSQL_FIELD structure to store metadata in.
Returns
0 on success.

◆ unpack_fields()

MYSQL_FIELD* unpack_fields ( MYSQL mysql,
MYSQL_ROWS data,
MEM_ROOT alloc,
uint  fields,
bool  default_value,
uint  server_capabilities 
)

◆ write_length_encoded_string3()

static uchar* write_length_encoded_string3 ( uchar buf,
const char *  string,
size_t  length 
)
static

◆ write_length_encoded_string4()

static char* write_length_encoded_string4 ( char *  dest,
char *  dest_end,
char *  src,
char *  src_end 
)
static

◆ write_string()

static char* write_string ( char *  dest,
char *  dest_end,
char *  src,
char *  src_end 
)
static

Variable Documentation

◆ all_client_memory

PSI_memory_info all_client_memory[]
static
Initial value:
= {
{&key_memory_mysql_options, "mysql_options", 0, 0, PSI_DOCUMENT_ME},
{&key_memory_MYSQL_DATA, "MYSQL_DATA", 0, 0, PSI_DOCUMENT_ME},
{&key_memory_MYSQL, "MYSQL", 0, 0, PSI_DOCUMENT_ME},
{&key_memory_MYSQL_RES, "MYSQL_RES", 0, 0, PSI_DOCUMENT_ME},
{&key_memory_MYSQL_ROW, "MYSQL_ROW", 0, 0, PSI_DOCUMENT_ME},
{&key_memory_MYSQL_state_change_info, "MYSQL_STATE_CHANGE_INFO", 0, 0,
{&key_memory_MYSQL_HANDSHAKE, "MYSQL_HANDSHAKE", 0, 0, PSI_DOCUMENT_ME}}
PSI_memory_key key_memory_MYSQL_ROW
Definition: client.cc:153
PSI_memory_key key_memory_MYSQL_DATA
Definition: client.cc:150
PSI_memory_key key_memory_MYSQL
Definition: client.cc:151
PSI_memory_key key_memory_MYSQL_RES
Definition: client.cc:152
PSI_memory_key key_memory_mysql_options
Definition: client.cc:149
PSI_memory_key key_memory_MYSQL_HANDSHAKE
Definition: client.cc:155
#define PSI_DOCUMENT_ME
Definition: psi_base.h:46
PSI_memory_key key_memory_MYSQL_state_change_info
Definition: client.cc:154

◆ cant_connect_sqlstate

const char* cant_connect_sqlstate = "08001"

◆ charsets

const MY_CSET_OS_NAME charsets[]

◆ clear_password_client_plugin

auth_plugin_t clear_password_client_plugin
static
Initial value:
= {
"mysql_clear_password",
"Georgi Kodinov",
"Clear password authentication plugin",
{0, 1, 0},
"GPL",
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION
Definition: client_plugin.h:78
#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN
Definition: client_plugin.h:75
static int clear_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
The main function of the mysql_clear_password authentication plugin.
Definition: client.cc:8259

◆ client_methods

MYSQL_METHODS client_methods
static
Initial value:
= {
,
}
net_async_status cli_read_change_user_result_nonblocking(MYSQL *mysql, ulong *ret)
Definition: client.cc:3378
static void cli_flush_use_result(MYSQL *mysql, bool flush_all_results)
Definition: client.cc:1633
bool cli_advanced_command(MYSQL *mysql, enum enum_server_command command, const uchar *header, size_t header_length, const uchar *arg, size_t arg_length, bool skip_check, MYSQL_STMT *stmt)
Definition: client.cc:1217
MYSQL_DATA * cli_read_rows(MYSQL *mysql, MYSQL_FIELD *mysql_fields, unsigned int fields)
Definition: client.cc:2852
static void cli_fetch_lengths(ulong *to, MYSQL_ROW column, unsigned int field_count)
Definition: client.cc:2243
net_async_status cli_read_rows_nonblocking(MYSQL *mysql, MYSQL_FIELD *mysql_fields, unsigned int fields, MYSQL_DATA **result_out)
Definition: client.cc:2710
static bool cli_read_query_result(MYSQL *mysql)
Definition: client.cc:6771
static net_async_status cli_read_query_result_nonblocking(MYSQL *mysql)
Definition: client.cc:6827
static net_async_status cli_flush_use_result_nonblocking(MYSQL *mysql, bool flush_all_results)
Definition: client.cc:1617
int cli_read_change_user_result(MYSQL *mysql)
Definition: client.cc:3374
static MYSQL_RES * cli_use_result(MYSQL *mysql)
Definition: client.cc:7205
net_async_status cli_advanced_command_nonblocking(MYSQL *mysql, enum enum_server_command command, const uchar *header, ulong header_length, const uchar *arg, ulong arg_length, bool skip_check, MYSQL_STMT *stmt, bool *ret)
Definition: client.cc:1367

◆ default_client_charset_info

CHARSET_INFO* default_client_charset_info = &my_charset_latin1

◆ default_options

const char* default_options[]
static

◆ g_max_allowed_packet

ulong g_max_allowed_packet = 1024L * 1024L * 1024L

◆ g_net_buffer_length

ulong g_net_buffer_length = 8192

◆ key_memory_MYSQL

PSI_memory_key key_memory_MYSQL

◆ key_memory_MYSQL_DATA

PSI_memory_key key_memory_MYSQL_DATA

◆ key_memory_MYSQL_HANDSHAKE

PSI_memory_key key_memory_MYSQL_HANDSHAKE

◆ key_memory_mysql_options

PSI_memory_key key_memory_mysql_options

◆ key_memory_MYSQL_RES

PSI_memory_key key_memory_MYSQL_RES

◆ key_memory_MYSQL_ROW

PSI_memory_key key_memory_MYSQL_ROW

◆ key_memory_MYSQL_state_change_info

PSI_memory_key key_memory_MYSQL_state_change_info

◆ libmysql_cleartext_plugin_enabled

bool libmysql_cleartext_plugin_enabled = 0

◆ mysql_client_builtins

struct st_mysql_client_plugin* mysql_client_builtins[]
Initial value:
= {
0}
static auth_plugin_t native_password_client_plugin
Definition: client.cc:3696
Definition: client_plugin.h:104
static auth_plugin_t clear_password_client_plugin
Definition: client.cc:3711

◆ mysql_port

uint mysql_port = 0

◆ mysql_server_last_errno

unsigned int mysql_server_last_errno

◆ mysql_server_last_error

char mysql_server_last_error[MYSQL_ERRMSG_SIZE]

◆ mysql_unix_port

char* mysql_unix_port = 0

◆ native_password_client_plugin

auth_plugin_t native_password_client_plugin
static
Initial value:
= {
"R.J.Silk, Sergei Golubchik",
"Native MySQL authentication",
{1, 0, 0},
"GPL",
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION
Definition: client_plugin.h:78
#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN
Definition: client_plugin.h:75
#define native_password_plugin_name
Definition: client.cc:146
static int native_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
Client authentication plugin that does native MySQL authentication using a 20-byte (4...
Definition: client.cc:8090
static net_async_status native_password_auth_client_nonblocking(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql, int *result)
Client authentication plugin that does native MySQL authentication in a nonblocking way...
Definition: client.cc:8132

◆ not_error_sqlstate

const char* not_error_sqlstate = "00000"

◆ option_types

TYPELIB option_types
static
Initial value:
= {array_elements(default_options) - 1, "options",
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
constexpr size_t array_elements(T(&)[N]) noexcept
Definition: my_macros.h:77
static const char * default_options[]
Definition: client.cc:1824

◆ sql_protocol_names_lib

const char* sql_protocol_names_lib[]
Initial value:
= {"TCP", "SOCKET", "PIPE", "MEMORY",
#define NullS
Definition of the null string (a null pointer of type char *), used in some of our string handling co...
Definition: m_string.h:49

◆ sql_protocol_typelib

TYPELIB sql_protocol_typelib
Initial value:
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
constexpr size_t array_elements(T(&)[N]) noexcept
Definition: my_macros.h:77
const char * sql_protocol_names_lib[]
Definition: client.cc:1914

◆ unknown_sqlstate

const char* unknown_sqlstate = "HY000"