MySQL  8.0.15
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 "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
 
struct  MCPVIO_EXT
 

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_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 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...
 
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)
 
void free_old_query (MYSQL *mysql)
 
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 void cli_flush_use_result (MYSQL *mysql, bool flush_all_results)
 
void end_server (MYSQL *mysql)
 
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)
 
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...
 
MYSQL_FIELDcli_read_metadata (MYSQL *mysql, ulong field_count, unsigned int field)
 Read metadata resultset from server. More...
 
MYSQL_DATAcli_read_rows (MYSQL *mysql, MYSQL_FIELD *mysql_fields, unsigned int fields)
 
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 MYSQL_REScli_use_result (MYSQL *mysql)
 
int cli_read_change_user_result (MYSQL *mysql)
 
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 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 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 int send_client_reply_packet (MCPVIO_EXT *mpvio, const uchar *data, int data_len)
 sends a client authentication packet (second packet in the 3-way handshake) More...
 
static int client_mpvio_read_packet (MYSQL_PLUGIN_VIO *mpv, uchar **buf)
 vio->read_packet() 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, auth_plugin_t *plugin)
 
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...
 
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)
 
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)
 
int STDCALL mysql_real_query (MYSQL *mysql, const char *query, ulong length)
 
MYSQL_RES *STDCALL mysql_store_result (MYSQL *mysql)
 
MYSQL_ROW STDCALL mysql_fetch_row (MYSQL_RES *res)
 
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:364
#define STATE_DATA(M)
Definition: client.cc:135
static MYSQL mysql
Definition: mysql.cc:148

◆ ALLOCATE_EXTENSIONS

#define ALLOCATE_EXTENSIONS (   OPTS)
Value:
(OPTS)->extension = (struct st_mysql_options_extention *)my_malloc( \
PSI_memory_key key_memory_mysql_options
Definition: client.cc:148
#define MYF(v)
Definition: my_inttypes.h:131
Definition: sql_common.h:112
#define MY_WME
Definition: my_sys.h:110
#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:1650

◆ 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)
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:148
#define MYF(v)
Definition: my_inttypes.h:131
#define ALLOCATE_EXTENSIONS(OPTS)
Definition: client.cc:1650
#define MY_WME
Definition: my_sys.h:110

◆ 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_keep_this_one_last 

Function Documentation

◆ add_init_command()

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

◆ check_plugin_enabled()

static bool check_plugin_enabled ( MYSQL mysql,
auth_plugin_t plugin 
)
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_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_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_read_change_user_result()

int cli_read_change_user_result ( MYSQL mysql)

◆ 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_query_result()

static bool cli_read_query_result ( MYSQL mysql)
static

◆ cli_read_rows()

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

◆ 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_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_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_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.

◆ 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.

◆ 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_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_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_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_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_query()

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

◆ 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_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)

◆ 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

◆ 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.

◆ 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_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

◆ 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

◆ 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

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
Return values
0ok
1error
See also
mysql_fill_packet_header() page_protocol_conn_packets_protocol_handshake_response

◆ 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:152
PSI_memory_key key_memory_MYSQL_DATA
Definition: client.cc:149
PSI_memory_key key_memory_MYSQL
Definition: client.cc:150
PSI_memory_key key_memory_MYSQL_RES
Definition: client.cc:151
PSI_memory_key key_memory_mysql_options
Definition: client.cc:148
PSI_memory_key key_memory_MYSQL_HANDSHAKE
Definition: client.cc:154
#define PSI_DOCUMENT_ME
Definition: psi_base.h:46
PSI_memory_key key_memory_MYSQL_state_change_info
Definition: client.cc:153

◆ 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:6273

◆ client_methods

MYSQL_METHODS client_methods
static
Initial value:
= {
}
static void cli_flush_use_result(MYSQL *mysql, bool flush_all_results)
Definition: client.cc:1385
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:1136
MYSQL_DATA * cli_read_rows(MYSQL *mysql, MYSQL_FIELD *mysql_fields, unsigned int fields)
Definition: client.cc:2235
static void cli_fetch_lengths(ulong *to, MYSQL_ROW column, unsigned int field_count)
Definition: client.cc:1950
static bool cli_read_query_result(MYSQL *mysql)
Definition: client.cc:5230
int cli_read_change_user_result(MYSQL *mysql)
Definition: client.cc:2714
static MYSQL_RES * cli_use_result(MYSQL *mysql)
Definition: client.cc:5384

◆ 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:3019
Definition: client_plugin.h:104
static auth_plugin_t clear_password_client_plugin
Definition: client.cc:3033

◆ 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:145
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:6193

◆ 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:1537

◆ 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:1625

◆ unknown_sqlstate

const char* unknown_sqlstate = "HY000"