MySQL  8.0.18
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, 2019, 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.*/
147 };
148 
152  const unsigned char *header, size_t header_length,
153  const unsigned char *arg, size_t arg_length,
154  bool skip_check, MYSQL_STMT *stmt);
155  MYSQL_DATA *(*read_rows)(MYSQL *mysql, MYSQL_FIELD *mysql_fields,
156  unsigned int fields);
157  MYSQL_RES *(*use_result)(MYSQL *mysql);
158  void (*fetch_lengths)(unsigned long *to, MYSQL_ROW column,
159  unsigned int field_count);
160  void (*flush_use_result)(MYSQL *mysql, bool flush_all_results);
162 #if !defined(MYSQL_SERVER)
163  MYSQL_FIELD *(*list_fields)(MYSQL *mysql);
164  bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
165  int (*stmt_execute)(MYSQL_STMT *stmt);
166  int (*read_binary_rows)(MYSQL_STMT *stmt);
167  int (*unbuffered_fetch)(MYSQL *mysql, char **row);
168  const char *(*read_statistics)(MYSQL *mysql);
169  bool (*next_result)(MYSQL *mysql);
170  int (*read_rows_from_cursor)(MYSQL_STMT *stmt);
171  void (*free_rows)(MYSQL_DATA *cur);
172 #endif
176  const unsigned char *header, unsigned long header_length,
177  const unsigned char *arg, unsigned long arg_length, bool skip_check,
178  MYSQL_STMT *stmt, bool *error);
180  MYSQL_FIELD *mysql_fields,
181  unsigned int fields,
182  MYSQL_DATA **result);
184  bool flush_all_results);
187  ulong *res);
188 };
189 
190 #define simple_command(mysql, command, arg, length, skip_check) \
191  ((mysql)->methods \
192  ? (*(mysql)->methods->advanced_command)(mysql, command, 0, 0, arg, \
193  length, skip_check, NULL) \
194  : (set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate), \
195  1))
196 #define simple_command_nonblocking(mysql, command, arg, length, skip_check, \
197  error) \
198  (*(mysql)->methods->advanced_command_nonblocking)( \
199  mysql, command, 0, 0, arg, length, skip_check, NULL, error)
200 
201 #define stmt_command(mysql, command, arg, length, stmt) \
202  ((mysql)->methods \
203  ? (*(mysql)->methods->advanced_command)(mysql, command, 0, 0, arg, \
204  length, 1, stmt) \
205  : (set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate), \
206  1))
207 
210  uint fields, bool default_value,
211  uint server_capabilities);
213  unsigned long field_count,
214  unsigned int fields);
215 MYSQL_FIELD *cli_read_metadata(MYSQL *mysql, unsigned long field_count,
216  unsigned int fields);
217 void free_rows(MYSQL_DATA *cur);
218 void free_old_query(MYSQL *mysql);
219 void end_server(MYSQL *mysql);
222  const char *filename, const char *group);
224  const unsigned char *header, size_t header_length,
225  const unsigned char *arg, size_t arg_length,
226  bool skip_check, MYSQL_STMT *stmt);
227 unsigned long cli_safe_read(MYSQL *mysql, bool *is_data_packet);
229  bool *is_data_packet,
230  ulong *res);
231 unsigned long cli_safe_read_with_ok(MYSQL *mysql, bool parse_ok,
232  bool *is_data_packet);
233 void net_clear_error(NET *net);
234 void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net);
235 void set_stmt_error(MYSQL_STMT *stmt, int errcode, const char *sqlstate,
236  const char *err);
237 void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate);
238 void set_mysql_extended_error(MYSQL *mysql, int errcode, const char *sqlstate,
239  const char *format, ...)
240  MY_ATTRIBUTE((format(printf, 4, 5)));
241 
242 /* client side of the pluggable authentication */
243 struct MYSQL_PLUGIN_VIO_INFO;
244 
246 int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
247  const char *data_plugin, const char *db);
250 
252 
256 int is_file_or_dir_world_writable(const char *filepath);
257 void read_ok_ex(MYSQL *mysql, unsigned long len);
258 
259 #ifdef __cplusplus
260 }
261 #endif
262 
263 #define protocol_41(A) ((A)->server_capabilities & CLIENT_PROTOCOL_41)
264 
265 #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:1281
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
enum net_async_status(* read_query_result_nonblocking)(MYSQL *mysql)
Definition: sql_common.h:173
const char * cant_connect_sqlstate
Definition: client.cc:200
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:1227
struct result result
Definition: result.h:37
Definition: client.cc:3896
void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate)
Set the internal error message to mysql handler.
Definition: client.cc:298
void free_rows(MYSQL_DATA *cur)
Definition: client.cc:1273
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:1137
void end_server(MYSQL *mysql)
Definition: client.cc:1798
void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net)
Set statement error code, sqlstate, and error message from NET.
Definition: libmysql.cc:1247
struct st_mysql_client_plugin * mysql_client_builtins[]
Definition: client.cc:3869
bool libmysql_cleartext_plugin_enabled
Definition: client.cc:5216
void mysql_extension_free(MYSQL_EXTENSION *)
Definition: client.cc:3240
const char * not_error_sqlstate
Definition: client.cc:199
enum net_async_status(* read_change_user_result_nonblocking)(MYSQL *mysql, ulong *res)
Definition: sql_common.h:186
void mysql_read_default_options(struct st_mysql_options *options, const char *filename, const char *group)
Definition: client.cc:2057
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:151
int mysql_client_plugin_init()
Initializes the client plugin layer.
Definition: client_plugin.cc:316
void mysql_close_free_options(MYSQL *mysql)
Definition: client.cc:6795
Definition: mysql.h:335
net_async_status
Definition: plugin_auth_common.h:130
bool(* read_query_result)(MYSQL *mysql)
Definition: sql_common.h:150
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:5254
Definition: mysql_com_server.h:58
Definition: client_plugin.h:104
STATE_INFO_NODE info_list[SESSION_TRACK_END+1]
Array of STATE_NODE_INFO elements (one per state type).
Definition: sql_common.h:84
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:1115
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:91
Definition: mysql.h:152
void net_clear_error(NET *net)
Clear possible error state of struct NET.
Definition: client.cc:329
enum net_async_status(* next_result_nonblocking)(MYSQL *mysql)
Definition: sql_common.h:185
struct My_hash * connection_attributes
Definition: sql_common.h:132
char * compression_algorithm
Definition: sql_common.h:143
void(* fetch_lengths)(unsigned long *to, MYSQL_ROW column, unsigned int field_count)
Definition: sql_common.h:158
size_t connection_attributes_length
Definition: sql_common.h:134
Header for compiler-dependent features.
enum net_async_status(* read_rows_nonblocking)(MYSQL *mysql, MYSQL_FIELD *mysql_fields, unsigned int fields, MYSQL_DATA **result)
Definition: sql_common.h:179
Definition: mysql.h:221
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:1269
LIST * current_node
Definition: sql_common.h:75
Definition: m_ctype.h:359
Definition: mysql_async.h:166
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)
Read metadata resultset from server.
Definition: client.cc:2677
Definition: sql_common.h:127
void read_ok_ex(MYSQL *mysql, unsigned long len)
Read Ok packet along with the server state change information.
Definition: client.cc:750
bool mysql_reconnect(MYSQL *mysql)
Definition: client.cc:6512
Definition: mysql.h:162
char * tls_version
Definition: sql_common.h:137
uchar * send_client_connect_attrs(MYSQL *mysql, uchar *buf)
Definition: client.cc:3900
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:1537
CHARSET_INFO * default_client_charset_info
Definition: client.cc:212
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
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:174
struct st_mysql_trace_info * trace_data
Definition: sql_common.h:97
NET_SERVER * server_extn
Definition: sql_common.h:103
static const Query_options options
Definition: show_query_builder.cc:48
MYSQL_EXTENSION * mysql_extension_init(MYSQL *)
Definition: client.cc:3223
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:41
#define MYSQL_VIO
Definition: mysql_com.h:847
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)
Read metadata resultset from server Memory allocated in a given allocator root.
Definition: client.cc:2594
void(* flush_use_result)(MYSQL *mysql, bool flush_all_results)
Definition: sql_common.h:160
enum net_async_status(* flush_use_result_nonblocking)(MYSQL *mysql, bool flush_all_results)
Definition: sql_common.h:183
MYSQL_FIELD * unpack_fields(MYSQL *mysql, MYSQL_ROWS *data, MEM_ROOT *alloc, uint fields, bool default_value, uint server_capabilities)
Definition: client.cc:2455
Log info(cout, "NOTE")
const char * unknown_sqlstate
Definition: client.cc:198
Definition: mysql.h:295
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:346
unsigned int ssl_fips_mode
Definition: sql_common.h:141
void mysql_close_free(MYSQL *mysql)
Definition: client.cc:6839
Definition: mysql.h:666
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 long ulong
Definition: my_inttypes.h:48
unsigned int zstd_compression_level
Definition: sql_common.h:145
int(* read_change_user_result)(MYSQL *mysql)
Definition: sql_common.h:161
Definition: mysql_com.h:858
char * plugin_dir
Definition: sql_common.h:128
void mysql_client_plugin_deinit()
Deinitializes the client plugin layer.
Definition: client_plugin.cc:356
Definition: sql_common.h:149
#define SESSION_TRACK_END
End of enum_session_state_type.
Definition: mysql_com.h:1009