MySQL  8.0.17
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 
43 struct MEM_ROOT;
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 extern const char *unknown_sqlstate;
50 extern const char *cant_connect_sqlstate;
51 extern const char *not_error_sqlstate;
52 
53 /*
54  Free all memory allocated in MYSQL handle except the
55  current options.
56 */
58 
59 /*
60  Clear connection options stored in MYSQL handle and
61  free memory used by them.
62 */
64 
65 /**
66  The structure is used to hold the state change information
67  received from the server. LIST functions are used for manipulation
68  of the members of the structure.
69 */
71  /** head_node->data is a LEX_STRING which contains the variable name. */
74 };
75 
76 /**
77  Store the change info received from the server in an array of linked lists
78  with STATE_INFO_NODE elements (one per state type).
79 */
80 struct STATE_INFO {
81  /** Array of STATE_NODE_INFO elements (one per state type). */
83 };
84 
85 /*
86  Access to MYSQL::extension member.
87 
88  Note: functions mysql_extension_{init,free}() are defined
89  in client.c.
90 */
91 
92 struct st_mysql_trace_info;
93 
95  struct st_mysql_trace_info *trace_data;
97  /* Struct to track the state of asynchronous operations */
99 };
100 
101 /* "Constructor/destructor" for MYSQL extension structure. */
104 
105 /*
106  Note: Allocated extension structure is freed in mysql_close_free()
107  called by mysql_close().
108 */
109 #define MYSQL_EXTENSION_PTR(H) \
110  ((MYSQL_EXTENSION *)((H)->extension \
111  ? (H)->extension \
112  : ((H)->extension = mysql_extension_init(H))))
113 
114 #define ASYNC_DATA(M) \
115  (NULL != (M) ? (MYSQL_EXTENSION_PTR(M)->mysql_async_context) : NULL)
116 
118  char *plugin_dir;
120  char *ssl_crl; /* PEM CRL file */
121  char *ssl_crlpath; /* PEM directory of CRL-s? */
126  bool get_server_public_key; /* Former ssl_enforce */
127  char *tls_version; /* TLS version option */
128  long ssl_ctx_flags; /* SSL ctx options flag */
129  unsigned int ssl_mode;
130  unsigned int retry_count;
131  unsigned int ssl_fips_mode; /* SSL fips mode for enforced encryption.*/
133 };
134 
138  const unsigned char *header, size_t header_length,
139  const unsigned char *arg, size_t arg_length,
140  bool skip_check, MYSQL_STMT *stmt);
141  MYSQL_DATA *(*read_rows)(MYSQL *mysql, MYSQL_FIELD *mysql_fields,
142  unsigned int fields);
143  MYSQL_RES *(*use_result)(MYSQL *mysql);
144  void (*fetch_lengths)(unsigned long *to, MYSQL_ROW column,
145  unsigned int field_count);
146  void (*flush_use_result)(MYSQL *mysql, bool flush_all_results);
148 #if !defined(MYSQL_SERVER)
149  MYSQL_FIELD *(*list_fields)(MYSQL *mysql);
150  bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
151  int (*stmt_execute)(MYSQL_STMT *stmt);
152  int (*read_binary_rows)(MYSQL_STMT *stmt);
153  int (*unbuffered_fetch)(MYSQL *mysql, char **row);
154  const char *(*read_statistics)(MYSQL *mysql);
155  bool (*next_result)(MYSQL *mysql);
156  int (*read_rows_from_cursor)(MYSQL_STMT *stmt);
157  void (*free_rows)(MYSQL_DATA *cur);
158 #endif
162  const unsigned char *header, unsigned long header_length,
163  const unsigned char *arg, unsigned long arg_length, bool skip_check,
164  MYSQL_STMT *stmt, bool *error);
166  MYSQL_FIELD *mysql_fields,
167  unsigned int fields,
168  MYSQL_DATA **result);
170  bool flush_all_results);
173  ulong *res);
174 };
175 
176 #define simple_command(mysql, command, arg, length, skip_check) \
177  ((mysql)->methods \
178  ? (*(mysql)->methods->advanced_command)(mysql, command, 0, 0, arg, \
179  length, skip_check, NULL) \
180  : (set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate), \
181  1))
182 #define simple_command_nonblocking(mysql, command, arg, length, skip_check, \
183  error) \
184  (*(mysql)->methods->advanced_command_nonblocking)( \
185  mysql, command, 0, 0, arg, length, skip_check, NULL, error)
186 
187 #define stmt_command(mysql, command, arg, length, stmt) \
188  ((mysql)->methods \
189  ? (*(mysql)->methods->advanced_command)(mysql, command, 0, 0, arg, \
190  length, 1, stmt) \
191  : (set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate), \
192  1))
193 
196  uint fields, bool default_value,
197  uint server_capabilities);
199  unsigned long field_count,
200  unsigned int fields);
201 MYSQL_FIELD *cli_read_metadata(MYSQL *mysql, unsigned long field_count,
202  unsigned int fields);
203 void free_rows(MYSQL_DATA *cur);
204 void free_old_query(MYSQL *mysql);
205 void end_server(MYSQL *mysql);
208  const char *filename, const char *group);
210  const unsigned char *header, size_t header_length,
211  const unsigned char *arg, size_t arg_length,
212  bool skip_check, MYSQL_STMT *stmt);
213 unsigned long cli_safe_read(MYSQL *mysql, bool *is_data_packet);
215  bool *is_data_packet,
216  ulong *res);
217 unsigned long cli_safe_read_with_ok(MYSQL *mysql, bool parse_ok,
218  bool *is_data_packet);
219 void net_clear_error(NET *net);
220 void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net);
221 void set_stmt_error(MYSQL_STMT *stmt, int errcode, const char *sqlstate,
222  const char *err);
223 void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate);
224 void set_mysql_extended_error(MYSQL *mysql, int errcode, const char *sqlstate,
225  const char *format, ...)
226  MY_ATTRIBUTE((format(printf, 4, 5)));
227 
228 /* client side of the pluggable authentication */
229 struct MYSQL_PLUGIN_VIO_INFO;
230 
232 int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
233  const char *data_plugin, const char *db);
236 
238 
242 int is_file_or_dir_world_writable(const char *filepath);
243 void read_ok_ex(MYSQL *mysql, unsigned long len);
244 
245 #ifdef __cplusplus
246 }
247 #endif
248 
249 #define protocol_41(A) ((A)->server_capabilities & CLIENT_PROTOCOL_41)
250 
251 #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:1280
STATE_INFO state_change
Definition: sql_common.h:96
bool get_server_public_key
Definition: sql_common.h:126
unsigned char uchar
Definition: my_inttypes.h:51
enum net_async_status(* read_query_result_nonblocking)(MYSQL *mysql)
Definition: sql_common.h:159
const char * cant_connect_sqlstate
Definition: client.cc:198
struct MYSQL_ASYNC * mysql_async_context
Definition: sql_common.h:98
bool enable_cleartext_plugin
Definition: sql_common.h:125
Definition: sql_common.h:94
Definition: mysql.h:121
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:1228
Definition: client.cc:3879
void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate)
Set the internal error message to mysql handler.
Definition: client.cc:296
void free_rows(MYSQL_DATA *cur)
Definition: client.cc:1272
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:72
unsigned long cli_safe_read_with_ok(MYSQL *mysql, bool parse_ok, bool *is_data_packet)
Read a packet from server.
Definition: client.cc:1138
void end_server(MYSQL *mysql)
Definition: client.cc:1799
void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net)
Set statement error code, sqlstate, and error message from NET.
Definition: libmysql.cc:1250
struct st_mysql_client_plugin * mysql_client_builtins[]
Definition: client.cc:3852
bool libmysql_cleartext_plugin_enabled
Definition: client.cc:5138
void mysql_extension_free(MYSQL_EXTENSION *)
Definition: client.cc:3219
const char * not_error_sqlstate
Definition: client.cc:197
enum net_async_status(* read_change_user_result_nonblocking)(MYSQL *mysql, ulong *res)
Definition: sql_common.h:172
void mysql_read_default_options(struct st_mysql_options *options, const char *filename, const char *group)
Definition: client.cc:2058
printf("== done ==\)
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:137
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:6690
Definition: mysql.h:334
net_async_status
Definition: plugin_auth_common.h:130
bool(* read_query_result)(MYSQL *mysql)
Definition: sql_common.h:136
long ssl_ctx_flags
Definition: sql_common.h:128
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:5176
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:82
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:1116
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:129
static const char * filepath
Definition: myisamlog.cc:91
Definition: mysql.h:153
void net_clear_error(NET *net)
Clear possible error state of struct NET.
Definition: client.cc:328
enum net_async_status(* next_result_nonblocking)(MYSQL *mysql)
Definition: sql_common.h:171
struct My_hash * connection_attributes
Definition: sql_common.h:122
void(* fetch_lengths)(unsigned long *to, MYSQL_ROW column, unsigned int field_count)
Definition: sql_common.h:144
size_t connection_attributes_length
Definition: sql_common.h:124
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:165
Definition: mysql.h:220
void mpvio_info(MYSQL_VIO vio, MYSQL_PLUGIN_VIO_INFO *info)
unsigned int len
Definition: dbug_analyze.cc:216
unsigned int uint
Definition: uca-dump.cc:29
char * default_auth
Definition: sql_common.h:119
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:1268
LIST * current_node
Definition: sql_common.h:73
Definition: m_ctype.h:359
Definition: mysql_async.h:165
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:2660
Definition: sql_common.h:117
void read_ok_ex(MYSQL *mysql, unsigned long len)
Read Ok packet along with the server state change information.
Definition: client.cc:751
bool mysql_reconnect(MYSQL *mysql)
Definition: client.cc:6409
Definition: mysql.h:163
char * tls_version
Definition: sql_common.h:127
uchar * send_client_connect_attrs(MYSQL *mysql, uchar *buf)
Definition: client.cc:3883
command
Definition: version_token.cc:278
void free_old_query(MYSQL *mysql)
Definition: client.cc:1536
CHARSET_INFO * default_client_charset_info
Definition: client.cc:210
Definition: plugin_auth_common.h:115
unsigned int retry_count
Definition: sql_common.h:130
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:160
struct st_mysql_trace_info * trace_data
Definition: sql_common.h:95
static const Query_options options
Definition: show_query_builder.cc:48
MYSQL_EXTENSION * mysql_extension_init(MYSQL *)
Definition: client.cc:3204
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:818
char * ssl_crl
Definition: sql_common.h:120
Store the change info received from the server in an array of linked lists with STATE_INFO_NODE eleme...
Definition: sql_common.h:80
char * ssl_crlpath
Definition: sql_common.h:121
char ** MYSQL_ROW
Definition: mysql.h:145
static MYSQL mysql
Definition: mysql.cc:150
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:2584
void(* flush_use_result)(MYSQL *mysql, bool flush_all_results)
Definition: sql_common.h:146
enum net_async_status(* flush_use_result_nonblocking)(MYSQL *mysql, bool flush_all_results)
Definition: sql_common.h:169
MYSQL_FIELD * unpack_fields(MYSQL *mysql, MYSQL_ROWS *data, MEM_ROOT *alloc, uint fields, bool default_value, uint server_capabilities)
Definition: client.cc:2445
Log info(cout, "NOTE")
const char * unknown_sqlstate
Definition: client.cc:196
Definition: mysql.h:294
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:70
char * tls_ciphersuites
Definition: sql_common.h:132
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:345
unsigned int ssl_fips_mode
Definition: sql_common.h:131
void mysql_close_free(MYSQL *mysql)
Definition: client.cc:6733
Definition: mysql.h:665
char * server_public_key_path
Definition: sql_common.h:123
unsigned long ulong
Definition: my_inttypes.h:48
int(* read_change_user_result)(MYSQL *mysql)
Definition: sql_common.h:147
Definition: mysql_com.h:829
char * plugin_dir
Definition: sql_common.h:118
void mysql_client_plugin_deinit()
Deinitializes the client plugin layer.
Definition: client_plugin.cc:356
Definition: sql_common.h:135
#define SESSION_TRACK_END
End of enum_session_state_type.
Definition: mysql_com.h:980
Log error(cerr, "ERROR")