MySQL  8.0.22
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, 2020, Oracle and/or its affiliates. All rights reserved.
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
45 struct MEM_ROOT;
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 extern const char *unknown_sqlstate;
52 extern const char *cant_connect_sqlstate;
53 extern const char *not_error_sqlstate;
54 
55 /*
56  Free all memory allocated in MYSQL handle except the
57  current options.
58 */
60 
61 /*
62  Clear connection options stored in MYSQL handle and
63  free memory used by them.
64 */
66 
67 /**
68  The structure is used to hold the state change information
69  received from the server. LIST functions are used for manipulation
70  of the members of the structure.
71 */
73  /** head_node->data is a LEX_STRING which contains the variable name. */
76 };
77 
78 /**
79  Store the change info received from the server in an array of linked lists
80  with STATE_INFO_NODE elements (one per state type).
81 */
82 struct STATE_INFO {
83  /** Array of STATE_NODE_INFO elements (one per state type). */
85 };
86 
87 /*
88  Access to MYSQL::extension member.
89 
90  Note: functions mysql_extension_{init,free}() are defined
91  in client.c.
92 */
93 
94 struct st_mysql_trace_info;
95 
97  struct st_mysql_trace_info *trace_data;
99  /* Struct to track the state of asynchronous operations */
101 #ifdef MYSQL_SERVER
102  // Used by replication to pass around compression context data.
104 #endif
105 };
106 
107 /* "Constructor/destructor" for MYSQL extension structure. */
110 /*
111  Note: Allocated extension structure is freed in mysql_close_free()
112  called by mysql_close().
113 */
114 #define MYSQL_EXTENSION_PTR(H) \
115  ((MYSQL_EXTENSION *)((H)->extension \
116  ? (H)->extension \
117  : ((H)->extension = mysql_extension_init(H))))
118 
119 #define ASYNC_DATA(M) \
120  (NULL != (M) ? (MYSQL_EXTENSION_PTR(M)->mysql_async_context) : NULL)
121 #ifdef MYSQL_SERVER
123  MYSQL_EXTENSION_PTR(mysql)->server_extn = extn;
124 }
125 #endif
126 
128  char *plugin_dir;
130  char *ssl_crl; /* PEM CRL file */
131  char *ssl_crlpath; /* PEM directory of CRL-s? */
136  bool get_server_public_key; /* Former ssl_enforce */
137  char *tls_version; /* TLS version option */
138  long ssl_ctx_flags; /* SSL ctx options flag */
139  unsigned int ssl_mode;
140  unsigned int retry_count;
141  unsigned int ssl_fips_mode; /* SSL fips mode for enforced encryption.*/
148 };
149 
151  bool (*read_query_result)(MYSQL *mysql);
152  bool (*advanced_command)(MYSQL *mysql, enum enum_server_command command,
153  const unsigned char *header, size_t header_length,
154  const unsigned char *arg, size_t arg_length,
155  bool skip_check, MYSQL_STMT *stmt);
156  MYSQL_DATA *(*read_rows)(MYSQL *mysql, MYSQL_FIELD *mysql_fields,
157  unsigned int fields);
158  MYSQL_RES *(*use_result)(MYSQL *mysql);
159  void (*fetch_lengths)(unsigned long *to, MYSQL_ROW column,
160  unsigned int field_count);
161  void (*flush_use_result)(MYSQL *mysql, bool flush_all_results);
162  int (*read_change_user_result)(MYSQL *mysql);
163 #if !defined(MYSQL_SERVER) && !defined(MYSQL_COMPONENT)
164  MYSQL_FIELD *(*list_fields)(MYSQL *mysql);
165  bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
166  int (*stmt_execute)(MYSQL_STMT *stmt);
167  int (*read_binary_rows)(MYSQL_STMT *stmt);
168  int (*unbuffered_fetch)(MYSQL *mysql, char **row);
169  const char *(*read_statistics)(MYSQL *mysql);
170  bool (*next_result)(MYSQL *mysql);
171  int (*read_rows_from_cursor)(MYSQL_STMT *stmt);
172  void (*free_rows)(MYSQL_DATA *cur);
173 #endif
174  enum net_async_status (*read_query_result_nonblocking)(MYSQL *mysql);
175  enum net_async_status (*advanced_command_nonblocking)(
177  const unsigned char *header, unsigned long header_length,
178  const unsigned char *arg, unsigned long arg_length, bool skip_check,
179  MYSQL_STMT *stmt, bool *error);
180  enum net_async_status (*read_rows_nonblocking)(MYSQL *mysql,
181  MYSQL_FIELD *mysql_fields,
182  unsigned int fields,
183  MYSQL_DATA **result);
184  enum net_async_status (*flush_use_result_nonblocking)(MYSQL *mysql,
185  bool flush_all_results);
186  enum net_async_status (*next_result_nonblocking)(MYSQL *mysql);
187  enum net_async_status (*read_change_user_result_nonblocking)(MYSQL *mysql,
188  ulong *res);
189 };
190 
191 #define simple_command(mysql, command, arg, length, skip_check) \
192  ((mysql)->methods \
193  ? (*(mysql)->methods->advanced_command)(mysql, command, 0, 0, arg, \
194  length, skip_check, NULL) \
195  : (set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate), \
196  1))
197 #define simple_command_nonblocking(mysql, command, arg, length, skip_check, \
198  error) \
199  (*(mysql)->methods->advanced_command_nonblocking)( \
200  mysql, command, 0, 0, arg, length, skip_check, NULL, error)
201 
202 #define stmt_command(mysql, command, arg, length, stmt) \
203  ((mysql)->methods \
204  ? (*(mysql)->methods->advanced_command)(mysql, command, 0, 0, arg, \
205  length, 1, stmt) \
206  : (set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate), \
207  1))
208 
211  uint fields, bool default_value,
212  uint server_capabilities);
214  unsigned long field_count,
215  unsigned int fields);
216 MYSQL_FIELD *cli_read_metadata(MYSQL *mysql, unsigned long field_count,
217  unsigned int fields);
218 void free_rows(MYSQL_DATA *cur);
219 void free_old_query(MYSQL *mysql);
220 void end_server(MYSQL *mysql);
223  const char *filename, const char *group);
225  const unsigned char *header, size_t header_length,
226  const unsigned char *arg, size_t arg_length,
227  bool skip_check, MYSQL_STMT *stmt);
228 unsigned long cli_safe_read(MYSQL *mysql, bool *is_data_packet);
230  bool *is_data_packet,
231  ulong *res);
232 unsigned long cli_safe_read_with_ok(MYSQL *mysql, bool parse_ok,
233  bool *is_data_packet);
234 void net_clear_error(NET *net);
235 void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net);
236 void set_stmt_error(MYSQL_STMT *stmt, int errcode, const char *sqlstate,
237  const char *err);
238 void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate);
239 void set_mysql_extended_error(MYSQL *mysql, int errcode, const char *sqlstate,
240  const char *format, ...)
241  MY_ATTRIBUTE((format(printf, 4, 5)));
242 
243 /* client side of the pluggable authentication */
244 struct MYSQL_PLUGIN_VIO_INFO;
245 
246 void mpvio_info(MYSQL_VIO vio, MYSQL_PLUGIN_VIO_INFO *info);
247 int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
248  const char *data_plugin, const char *db);
251 
253 
254 extern struct st_mysql_client_plugin *mysql_client_builtins[];
257 int is_file_or_dir_world_writable(const char *filepath);
258 void read_ok_ex(MYSQL *mysql, unsigned long len);
259 
260 #ifdef __cplusplus
261 }
262 #endif
263 
264 #define protocol_41(A) ((A)->server_capabilities & CLIENT_PROTOCOL_41)
265 
266 #endif /* SQL_COMMON_INCLUDED */
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:1270
void mysql_extension_set_server_extn(MYSQL *mysql, NET_SERVER *extn)
Definition: sql_common.h:122
STATE_INFO state_change
Definition: sql_common.h:98
bool get_server_public_key
Definition: sql_common.h:136
unsigned char uchar
Definition: my_inttypes.h:51
const char * cant_connect_sqlstate
Definition: client.cc:201
struct MYSQL_ASYNC * mysql_async_context
Definition: sql_common.h:100
bool enable_cleartext_plugin
Definition: sql_common.h:135
Definition: sql_common.h:96
Definition: mysql.h:120
#define MYSQL_EXTENSION_PTR(H)
Definition: sql_common.h:114
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:1283
struct result result
Definition: result.h:33
Definition: client.cc:3813
void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate)
Set the internal error message to mysql handler.
Definition: client.cc:299
void free_rows(MYSQL_DATA *cur)
Definition: client.cc:1262
Some integer typedefs for easier portability.
#define bool
Definition: config_static.h:42
LIST * head_node
head_node->data is a LEX_STRING which contains the variable name.
Definition: sql_common.h:74
unsigned long cli_safe_read_with_ok(MYSQL *mysql, bool parse_ok, bool *is_data_packet)
Read a packet from server.
Definition: client.cc:1126
void end_server(MYSQL *mysql)
Definition: client.cc:1796
void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net)
Set statement error code, sqlstate, and error message from NET.
Definition: libmysql.cc:1303
struct st_mysql_client_plugin * mysql_client_builtins[]
Definition: client.cc:3788
bool libmysql_cleartext_plugin_enabled
Definition: client.cc:5146
void mysql_extension_free(MYSQL_EXTENSION *)
Definition: client.cc:3189
const char * not_error_sqlstate
Definition: client.cc:200
void mysql_read_default_options(struct st_mysql_options *options, const char *filename, const char *group)
Definition: client.cc:2013
int mysql_client_plugin_init()
Initializes the client plugin layer.
Definition: client_plugin.cc:319
void mysql_close_free_options(MYSQL *mysql)
Definition: client.cc:6807
Definition: mysql.h:336
Definition: buf0block_hint.cc:29
net_async_status
Definition: plugin_auth_common.h:130
long ssl_ctx_flags
Definition: sql_common.h:138
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:5184
Definition: mysql_com_server.h:58
Definition: client_plugin.h:106
static const Query_options options
Definition: sql_show_processlist.cc:65
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:1104
Common definition between mysql server & client.
This file defines the client API to MySQL and also the ABI of the dynamically linked libmysqlclient...
unsigned int ssl_mode
Definition: sql_common.h:139
static const char * filepath
Definition: myisamlog.cc:93
Definition: mysql.h:152
void net_clear_error(NET *net)
Clear possible error state of struct NET.
Definition: client.cc:330
struct My_hash * connection_attributes
Definition: sql_common.h:132
char * compression_algorithm
Definition: sql_common.h:143
Definition: buffer.h:39
size_t connection_attributes_length
Definition: sql_common.h:134
char * load_data_dir
Definition: sql_common.h:147
Header for compiler-dependent features.
Definition: mysql.h:222
void mpvio_info(MYSQL_VIO vio, MYSQL_PLUGIN_VIO_INFO *info)
unsigned int uint
Definition: uca-dump.cc:29
char * default_auth
Definition: sql_common.h:129
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:908
unsigned long cli_safe_read(MYSQL *mysql, bool *is_data_packet)
Read a packet from server.
Definition: client.cc:1258
LIST * current_node
Definition: sql_common.h:75
Definition: m_ctype.h:359
Definition: mysql_async.h:211
enum_server_command
A list of all MySQL protocol commands.
Definition: my_command.h:47
MYSQL_FIELD * cli_read_metadata(MYSQL *mysql, unsigned long field_count, unsigned int fields)
Definition: sql_common.h:127
void read_ok_ex(MYSQL *mysql, unsigned long len)
bool mysql_reconnect(MYSQL *mysql)
Definition: client.cc:6518
Definition: mysql.h:162
char * tls_version
Definition: sql_common.h:137
uchar * send_client_connect_attrs(MYSQL *mysql, uchar *buf)
Definition: client.cc:3817
unsigned int total_configured_compression_algorithms
Definition: sql_common.h:144
command
Definition: version_token.cc:278
void free_old_query(MYSQL *mysql)
Definition: client.cc:1535
CHARSET_INFO * default_client_charset_info
Definition: client.cc:213
Definition: plugin_auth_common.h:115
unsigned int retry_count
Definition: sql_common.h:140
const char * filename
Definition: pfs_example_component_population.cc:64
struct st_mysql_trace_info * trace_data
Definition: sql_common.h:97
NET_SERVER * server_extn
Definition: sql_common.h:103
MYSQL_EXTENSION * mysql_extension_init(MYSQL *)
Definition: client.cc:3172
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
Definition: my_list.h:35
#define MYSQL_VIO
Definition: mysql_com.h:854
char * ssl_crl
Definition: sql_common.h:130
Store the change info received from the server in an array of linked lists with STATE_INFO_NODE eleme...
Definition: sql_common.h:82
char * ssl_crlpath
Definition: sql_common.h:131
char ** MYSQL_ROW
Definition: mysql.h:144
bool connection_compressed
Definition: sql_common.h:146
static MYSQL mysql
Definition: mysql.cc:152
Error messages for MySQL clients.
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:2398
Log info(cout, "NOTE")
const char * unknown_sqlstate
Definition: client.cc:199
Definition: mysql.h:296
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:77
The structure is used to hold the state change information received from the server.
Definition: sql_common.h:72
char * tls_ciphersuites
Definition: sql_common.h:142
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:347
unsigned int ssl_fips_mode
Definition: sql_common.h:141
void mysql_close_free(MYSQL *mysql)
Definition: client.cc:6849
Definition: mysql.h:667
char * server_public_key_path
Definition: sql_common.h:133
Definitions private to the server, used in the networking layer to notify specific events...
unsigned int zstd_compression_level
Definition: sql_common.h:145
Definition: mysql_com.h:867
char * plugin_dir
Definition: sql_common.h:128
void mysql_client_plugin_deinit()
Deinitializes the client plugin layer.
Definition: client_plugin.cc:359
Definition: sql_common.h:150
#define SESSION_TRACK_END
End of enum_session_state_type.
Definition: mysql_com.h:1018