MySQL 8.0.30
Source Code Documentation
sql_common.h
Go to the documentation of this file.
1#ifndef SQL_COMMON_INCLUDED
2#define SQL_COMMON_INCLUDED
3
4/* Copyright (c) 2003, 2022, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is also distributed with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have included with MySQL.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License, version 2.0, for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25
26#define SQL_COMMON_INCLUDED
27
28/**
29 @file include/sql_common.h
30*/
31
32#include <mysql.h>
33#include <stddef.h>
34#include <sys/types.h>
35
36#include "errmsg.h"
37#include "my_command.h"
38#include "my_compiler.h"
39#include "my_inttypes.h"
40#include "my_list.h"
41#include "mysql_com.h"
42#ifdef MYSQL_SERVER
43#include "mysql_com_server.h"
44#endif
45struct MEM_ROOT;
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51#ifdef IMPORT_UNKNOWN_SQLSTATE
52__declspec(dllimport)
53#endif
54 extern const char *unknown_sqlstate;
55extern const char *cant_connect_sqlstate;
56extern const char *not_error_sqlstate;
57
58/*
59 Free all memory allocated in MYSQL handle except the
60 current options.
61*/
63
64/*
65 Clear connection options stored in MYSQL handle and
66 free memory used by them.
67*/
69
70/**
71 The structure is used to hold the state change information
72 received from the server. LIST functions are used for manipulation
73 of the members of the structure.
74*/
76 /** head_node->data is a LEX_STRING which contains the variable name. */
79};
80
81/**
82 Store the change info received from the server in an array of linked lists
83 with STATE_INFO_NODE elements (one per state type).
84*/
85struct STATE_INFO {
86 /** Array of STATE_NODE_INFO elements (one per state type). */
88};
89
90/*
91 Access to MYSQL::extension member.
92
93 Note: functions mysql_extension_{init,free}() are defined
94 in client.c.
95*/
96
97struct st_mysql_trace_info;
98
100 struct st_mysql_trace_info *trace_data;
102 /* Struct to track the state of asynchronous operations */
104#ifdef MYSQL_SERVER
105 // Used by replication to pass around compression context data.
107#endif
108 struct {
110 char **names;
113};
114
115/* "Constructor/destructor" for MYSQL extension structure. */
118/* cleanup for the MYSQL extension bind structure */
120/*
121 Note: Allocated extension structure is freed in mysql_close_free()
122 called by mysql_close().
123*/
124#define MYSQL_EXTENSION_PTR(H) \
125 ((MYSQL_EXTENSION *)((H)->extension \
126 ? (H)->extension \
127 : ((H)->extension = mysql_extension_init(H))))
128
129#define ASYNC_DATA(M) \
130 (NULL != (M) ? (MYSQL_EXTENSION_PTR(M)->mysql_async_context) : NULL)
131/**
132 Sets the MYSQL_EXTENSION::server_extn attribute by the use of NET_SERVER which
133 contains information about compression context and compression attributes.
134 This attribute needs to be set each time mysql_real_connect() is called to
135 make a connection. When a connection attempt fails or when a connection is
136 closed, as part of the MYSQL handle cleanup, mysql_close_free() is called and
137 that will free MYSQL_EXTENSION::server_extn.
138
139 mysql_close_free() will free all the memory allocated in the MYSQL handle but
140 preserves MYSQL::options. These options are later free'd by
141 mysql_close_free_options() unless the client flag CLIENT_REMEMBER_OPTIONS is
142 set.
143
144 @param mysql The MYSQL handle
145 @param extn The NET_SERVER handle that contains compression context info.
146*/
147#ifdef MYSQL_SERVER
149 MYSQL_EXTENSION_PTR(mysql)->server_extn = extn;
150}
151#endif
152
153/*
154 Maximum allowed authentication plugins for a given user account.
155*/
156#define MAX_AUTHENTICATION_FACTOR 3
157/*
158 Placeholder to save plugin name and password of 1st, 2nd and 3rd
159 factor authentication methods.
160*/
163 char *password;
164};
165
169 char *ssl_crl; /* PEM CRL file */
170 char *ssl_crlpath; /* PEM directory of CRL-s? */
175 bool get_server_public_key; /* Former ssl_enforce */
176 char *tls_version; /* TLS version option */
177 long ssl_ctx_flags; /* SSL ctx options flag */
178 unsigned int ssl_mode;
179 unsigned int retry_count;
180 unsigned int ssl_fips_mode; /* SSL fips mode for enforced encryption.*/
188 void *ssl_session_data; /** the session serialization to use */
189};
190
194 const unsigned char *header, size_t header_length,
195 const unsigned char *arg, size_t arg_length,
196 bool skip_check, MYSQL_STMT *stmt);
197 MYSQL_DATA *(*read_rows)(MYSQL *mysql, MYSQL_FIELD *mysql_fields,
198 unsigned int fields);
199 MYSQL_RES *(*use_result)(MYSQL *mysql);
200 void (*fetch_lengths)(unsigned long *to, MYSQL_ROW column,
201 unsigned int field_count);
202 void (*flush_use_result)(MYSQL *mysql, bool flush_all_results);
204#if !defined(MYSQL_SERVER) && !defined(MYSQL_COMPONENT)
205 MYSQL_FIELD *(*list_fields)(MYSQL *mysql);
206 bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
207 int (*stmt_execute)(MYSQL_STMT *stmt);
208 int (*read_binary_rows)(MYSQL_STMT *stmt);
209 int (*unbuffered_fetch)(MYSQL *mysql, char **row);
210 const char *(*read_statistics)(MYSQL *mysql);
211 bool (*next_result)(MYSQL *mysql);
212 int (*read_rows_from_cursor)(MYSQL_STMT *stmt);
213 void (*free_rows)(MYSQL_DATA *cur);
214#endif
218 const unsigned char *header, unsigned long header_length,
219 const unsigned char *arg, unsigned long arg_length, bool skip_check,
220 MYSQL_STMT *stmt, bool *error);
222 MYSQL_FIELD *mysql_fields,
223 unsigned int fields,
226 bool flush_all_results);
229 ulong *res);
230};
231
232#define simple_command(mysql, command, arg, length, skip_check) \
233 ((mysql)->methods \
234 ? (*(mysql)->methods->advanced_command)(mysql, command, 0, 0, arg, \
235 length, skip_check, NULL) \
236 : (set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate), \
237 1))
238#define simple_command_nonblocking(mysql, command, arg, length, skip_check, \
239 error) \
240 (*(mysql)->methods->advanced_command_nonblocking)( \
241 mysql, command, 0, 0, arg, length, skip_check, NULL, error)
242
243#define stmt_command(mysql, command, arg, length, stmt) \
244 ((mysql)->methods \
245 ? (*(mysql)->methods->advanced_command)(mysql, command, 0, 0, arg, \
246 length, 1, stmt) \
247 : (set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate), \
248 1))
249
252 uint fields, bool default_value,
253 uint server_capabilities);
255 unsigned long field_count,
256 unsigned int fields);
257MYSQL_FIELD *cli_read_metadata(MYSQL *mysql, unsigned long field_count,
258 unsigned int fields);
259void free_rows(MYSQL_DATA *cur);
261void end_server(MYSQL *mysql);
264 const char *filename, const char *group);
266 const unsigned char *header, size_t header_length,
267 const unsigned char *arg, size_t arg_length,
268 bool skip_check, MYSQL_STMT *stmt);
269unsigned long cli_safe_read(MYSQL *mysql, bool *is_data_packet);
271 bool *is_data_packet,
272 ulong *res);
273unsigned long cli_safe_read_with_ok(MYSQL *mysql, bool parse_ok,
274 bool *is_data_packet);
275void net_clear_error(NET *net);
276void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net);
277void set_stmt_error(MYSQL_STMT *stmt, int errcode, const char *sqlstate,
278 const char *err);
279void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate);
280void set_mysql_extended_error(MYSQL *mysql, int errcode, const char *sqlstate,
281 const char *format, ...)
282 MY_ATTRIBUTE((format(printf, 4, 5)));
283
284/* client side of the pluggable authentication */
286
288int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
289 const char *data_plugin, const char *db);
292
294
299void read_ok_ex(MYSQL *mysql, unsigned long len);
300
301bool fix_param_bind(MYSQL_BIND *param, uint idx);
303 NET *net, unsigned int param_count, MYSQL_BIND *params, const char **names,
304 unsigned long n_param_sets, uchar **ret_data, ulong *ret_length,
305 uchar send_types_to_server, bool send_named_params,
306 bool send_parameter_set_count, bool send_parameter_count_when_zero);
307
308#ifdef __cplusplus
309}
310#endif
311
312#define protocol_41(A) ((A)->server_capabilities & CLIENT_PROTOCOL_41)
313
314/*
315 AuthNextFactor packet is defined to have value 2 in 1st byte.
316*/
317#define AUTH_NEXT_FACTOR_PACKETTYPE 2
318#endif /* SQL_COMMON_INCLUDED */
Error messages for MySQL clients.
enum_server_command
A list of all MySQL protocol commands.
Definition: my_command.h:47
Header for compiler-dependent features.
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:51
static const char * filepath
Definition: myisamlog.cc:93
static MYSQL mysql
Definition: mysql.cc:153
This file defines the client API to MySQL and also the ABI of the dynamically linked libmysqlclient.
char ** MYSQL_ROW
Definition: mysql.h:144
Common definition between mysql server & client.
#define MYSQL_VIO
Definition: mysql_com.h:891
#define SESSION_TRACK_END
End of enum_session_state_type.
Definition: mysql_com.h:1079
Definitions private to the server, used in the networking layer to notify specific events.
Log info(cout, "NOTE")
Definition: buf0block_hint.cc:29
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:909
Json_data_extension ext
Definition: backend.cc:50
Definition: buffer.h:42
Definition: options.cc:48
const char * filename
Definition: pfs_example_component_population.cc:66
struct result result
Definition: result.h:33
net_async_status
Definition: plugin_auth_common.h:135
void mysql_extension_bind_free(MYSQL_EXTENSION *ext)
Definition: client.cc:3300
const char * unknown_sqlstate
Definition: client.cc:208
void mysql_close_free(MYSQL *mysql)
Definition: client.cc:7383
void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net)
Set statement error code, sqlstate, and error message from NET.
Definition: libmysql.cc:1246
void end_server(MYSQL *mysql)
Definition: client.cc:1878
void set_mysql_extended_error(MYSQL *mysql, int errcode, const char *sqlstate, const char *format,...)
Set an error message on the client.
Definition: client.cc:379
bool libmysql_cleartext_plugin_enabled
Definition: client.cc:5452
bool fix_param_bind(MYSQL_BIND *param, uint idx)
Definition: bind_params.cc:407
bool mysql_reconnect(MYSQL *mysql)
Definition: client.cc:7052
int mysql_client_plugin_init()
Initializes the client plugin layer.
Definition: client_plugin.cc:319
#define MYSQL_EXTENSION_PTR(H)
Definition: sql_common.h:124
MYSQL_FIELD * cli_read_metadata(MYSQL *mysql, unsigned long field_count, unsigned int fields)
void mpvio_info(MYSQL_VIO vio, MYSQL_PLUGIN_VIO_INFO *info)
void net_clear_error(NET *net)
Clear possible error state of struct NET.
Definition: client.cc:362
const char * cant_connect_sqlstate
Definition: client.cc:210
unsigned long cli_safe_read(MYSQL *mysql, bool *is_data_packet)
Read a packet from server.
Definition: client.cc:1302
void read_ok_ex(MYSQL *mysql, unsigned long len)
enum net_async_status cli_safe_read_nonblocking(MYSQL *mysql, bool *is_data_packet, ulong *res)
Its a non blocking version of cli_safe_read.
Definition: client.cc:1147
bool cli_advanced_command(MYSQL *mysql, enum enum_server_command command, const unsigned char *header, size_t header_length, const unsigned char *arg, size_t arg_length, bool skip_check, MYSQL_STMT *stmt)
Definition: client.cc:1314
void free_rows(MYSQL_DATA *cur)
Definition: client.cc:1306
void mysql_client_plugin_deinit()
Deinitializes the client plugin layer.
Definition: client_plugin.cc:359
unsigned long cli_safe_read_with_ok(MYSQL *mysql, bool parse_ok, bool *is_data_packet)
Read a packet from server.
Definition: client.cc:1169
bool mysql_int_serialize_param_data(NET *net, unsigned int param_count, MYSQL_BIND *params, const char **names, unsigned long n_param_sets, uchar **ret_data, ulong *ret_length, uchar send_types_to_server, bool send_named_params, bool send_parameter_set_count, bool send_parameter_count_when_zero)
Serialize the query parameters.
Definition: bind_params.cc:310
int is_file_or_dir_world_writable(const char *filepath)
Check if a file/dir is world-writable (only on non-Windows platforms)
Definition: my_path_permissions.cc:42
MYSQL_FIELD * cli_read_metadata_ex(MYSQL *mysql, MEM_ROOT *alloc, unsigned long field_count, unsigned int fields)
MYSQL_FIELD * unpack_fields(MYSQL *mysql, MYSQL_ROWS *data, MEM_ROOT *alloc, uint fields, bool default_value, uint server_capabilities)
Definition: client.cc:2480
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.
Definition: client.cc:5496
void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate)
Set the internal error message to mysql handler.
Definition: client.cc:331
#define MAX_AUTHENTICATION_FACTOR
Definition: sql_common.h:156
void set_stmt_error(MYSQL_STMT *stmt, int errcode, const char *sqlstate, const char *err)
Set statement error code, sqlstate, and error message from given errcode and sqlstate.
Definition: libmysql.cc:1226
CHARSET_INFO * default_client_charset_info
Definition: client.cc:220
void free_old_query(MYSQL *mysql)
Definition: client.cc:1603
uchar * send_client_connect_attrs(MYSQL *mysql, uchar *buf)
Definition: client.cc:4092
const char * not_error_sqlstate
Definition: client.cc:209
MYSQL_EXTENSION * mysql_extension_init(MYSQL *)
Definition: client.cc:3280
void mysql_close_free_options(MYSQL *mysql)
Definition: client.cc:7342
void mysql_extension_set_server_extn(MYSQL *mysql, NET_SERVER *extn)
Sets the MYSQL_EXTENSION::server_extn attribute by the use of NET_SERVER which contains information a...
Definition: sql_common.h:148
void mysql_extension_free(MYSQL_EXTENSION *)
Definition: client.cc:3311
struct st_mysql_client_plugin * mysql_client_builtins[]
Definition: client.cc:4063
void mysql_read_default_options(struct st_mysql_options *options, const char *filename, const char *group)
Definition: client.cc:2095
Definition: m_ctype.h:354
Definition: my_list.h:35
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
Definition: mysql_async.h:211
Definition: mysql.h:652
Definition: mysql.h:162
Definition: sql_common.h:99
char ** names
Definition: sql_common.h:110
uint n_params
Definition: sql_common.h:109
struct MYSQL_ASYNC * mysql_async_context
Definition: sql_common.h:103
NET_SERVER * server_extn
Definition: sql_common.h:106
struct st_mysql_trace_info * trace_data
Definition: sql_common.h:100
STATE_INFO state_change
Definition: sql_common.h:101
MYSQL_BIND * bind
Definition: sql_common.h:111
struct MYSQL_EXTENSION::@8 bind_info
Definition: mysql.h:120
Definition: sql_common.h:191
enum net_async_status(* advanced_command_nonblocking)(MYSQL *mysql, enum enum_server_command command, const unsigned char *header, unsigned long header_length, const unsigned char *arg, unsigned long arg_length, bool skip_check, MYSQL_STMT *stmt, bool *error)
Definition: sql_common.h:216
enum net_async_status(* read_change_user_result_nonblocking)(MYSQL *mysql, ulong *res)
Definition: sql_common.h:228
bool(* read_query_result)(MYSQL *mysql)
Definition: sql_common.h:192
void(* fetch_lengths)(unsigned long *to, MYSQL_ROW column, unsigned int field_count)
Definition: sql_common.h:200
bool(* advanced_command)(MYSQL *mysql, enum enum_server_command command, const unsigned char *header, size_t header_length, const unsigned char *arg, size_t arg_length, bool skip_check, MYSQL_STMT *stmt)
Definition: sql_common.h:193
enum net_async_status(* read_rows_nonblocking)(MYSQL *mysql, MYSQL_FIELD *mysql_fields, unsigned int fields, MYSQL_DATA **result)
Definition: sql_common.h:221
void(* flush_use_result)(MYSQL *mysql, bool flush_all_results)
Definition: sql_common.h:202
enum net_async_status(* read_query_result_nonblocking)(MYSQL *mysql)
Definition: sql_common.h:215
enum net_async_status(* next_result_nonblocking)(MYSQL *mysql)
Definition: sql_common.h:227
int(* read_change_user_result)(MYSQL *mysql)
Definition: sql_common.h:203
enum net_async_status(* flush_use_result_nonblocking)(MYSQL *mysql, bool flush_all_results)
Definition: sql_common.h:225
Definition: plugin_auth_common.h:120
Definition: mysql.h:338
Definition: mysql.h:152
Definition: mysql.h:679
Definition: mysql.h:298
Definition: client.cc:4088
Definition: mysql_com_server.h:58
Definition: mysql_com.h:910
The structure is used to hold the state change information received from the server.
Definition: sql_common.h:75
LIST * head_node
head_node->data is a LEX_STRING which contains the variable name.
Definition: sql_common.h:77
LIST * current_node
Definition: sql_common.h:78
Store the change info received from the server in an array of linked lists with STATE_INFO_NODE eleme...
Definition: sql_common.h:85
STATE_INFO_NODE info_list[SESSION_TRACK_END+1]
Array of STATE_NODE_INFO elements (one per state type).
Definition: sql_common.h:87
Definition: sql_common.h:161
char * plugin_name
Definition: sql_common.h:162
char * password
Definition: sql_common.h:163
Definition: client_plugin.h:113
Definition: sql_common.h:166
unsigned int ssl_fips_mode
Definition: sql_common.h:180
bool get_server_public_key
Definition: sql_common.h:175
char * default_auth
Definition: sql_common.h:168
char * compression_algorithm
Definition: sql_common.h:182
long ssl_ctx_flags
Definition: sql_common.h:177
char * ssl_crl
Definition: sql_common.h:169
char * tls_version
Definition: sql_common.h:176
void * ssl_session_data
Definition: sql_common.h:188
bool connection_compressed
Definition: sql_common.h:185
char * plugin_dir
Definition: sql_common.h:167
unsigned int retry_count
Definition: sql_common.h:179
bool enable_cleartext_plugin
Definition: sql_common.h:174
char * tls_ciphersuites
Definition: sql_common.h:181
struct client_authentication_info client_auth_info[MAX_AUTHENTICATION_FACTOR]
Definition: sql_common.h:187
unsigned int total_configured_compression_algorithms
Definition: sql_common.h:183
char * server_public_key_path
Definition: sql_common.h:172
size_t connection_attributes_length
Definition: sql_common.h:173
struct My_hash * connection_attributes
Definition: sql_common.h:171
unsigned int ssl_mode
Definition: sql_common.h:178
char * ssl_crlpath
Definition: sql_common.h:170
char * load_data_dir
Definition: sql_common.h:186
unsigned int zstd_compression_level
Definition: sql_common.h:184
Definition: mysql.h:224
unsigned int uint
Definition: uca-dump.cc:29
command
Definition: version_token.cc:279