1 #ifndef SQL_COMMON_INCLUDED
2 #define SQL_COMMON_INCLUDED
3 
4 /* Copyright (c) 2003, 2018, 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 #ifdef	__cplusplus
29 extern "C" {
30 #endif
31 
32 #include <mysql.h>
33 #include <hash.h>
34 
35 extern const char	*unknown_sqlstate;
36 extern const char	*cant_connect_sqlstate;
37 extern const char	*not_error_sqlstate;
38 
39 
40 /*
41   Free all memory allocated in MYSQL handle except the
42   current options.
43 */
44 void mysql_close_free(MYSQL *mysql);
45 
46 /*
47   Clear connection options stored in MYSQL handle and
48   free memory used by them.
49 */
50 void mysql_close_free_options(MYSQL *mysql);
51 
52 
53 struct st_mysql_options_extention {
54   char *plugin_dir;
55   char *default_auth;
56   char *ssl_crl;				/* PEM CRL file */
57   char *ssl_crlpath;				/* PEM directory of CRL-s? */
58   HASH connection_attributes;
59   char *server_public_key_path;
60   size_t connection_attributes_length;
61   my_bool enable_cleartext_plugin;
62   unsigned int ssl_mode;
63 };
64 
65 typedef struct st_mysql_methods
66 {
67   my_bool (*read_query_result)(MYSQL *mysql);
68   my_bool (*advanced_command)(MYSQL *mysql,
69 			      enum enum_server_command command,
70 			      const unsigned char *header,
71 			      unsigned long header_length,
72 			      const unsigned char *arg,
73 			      unsigned long arg_length,
74 			      my_bool skip_check,
75                               MYSQL_STMT *stmt);
76   MYSQL_DATA *(*read_rows)(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
77 			   unsigned int fields);
78   MYSQL_RES * (*use_result)(MYSQL *mysql);
79   void (*fetch_lengths)(unsigned long *to,
80 			MYSQL_ROW column, unsigned int field_count);
81   void (*flush_use_result)(MYSQL *mysql, my_bool flush_all_results);
82   int (*read_change_user_result)(MYSQL *mysql);
83 #if !defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY)
84   MYSQL_FIELD * (*list_fields)(MYSQL *mysql);
85   my_bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
86   int (*stmt_execute)(MYSQL_STMT *stmt);
87   int (*read_binary_rows)(MYSQL_STMT *stmt);
88   int (*unbuffered_fetch)(MYSQL *mysql, char **row);
89   void (*free_embedded_thd)(MYSQL *mysql);
90   const char *(*read_statistics)(MYSQL *mysql);
91   my_bool (*next_result)(MYSQL *mysql);
92   int (*read_rows_from_cursor)(MYSQL_STMT *stmt);
93 #endif
94 } MYSQL_METHODS;
95 
96 #define simple_command(mysql, command, arg, length, skip_check) \
97   (*(mysql)->methods->advanced_command)(mysql, command, 0,  \
98                                         0, arg, length, skip_check, NULL)
99 #define stmt_command(mysql, command, arg, length, stmt) \
100   (*(mysql)->methods->advanced_command)(mysql, command, 0,  \
101                                         0, arg, length, 1, stmt)
102 
103 extern CHARSET_INFO *default_client_charset_info;
104 MYSQL_FIELD *unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,
105                            uint fields, my_bool default_value,
106                            uint server_capabilities);
107 void free_rows(MYSQL_DATA *cur);
108 void free_old_query(MYSQL *mysql);
109 void end_server(MYSQL *mysql);
110 my_bool mysql_reconnect(MYSQL *mysql);
111 void mysql_read_default_options(struct st_mysql_options *options,
112 				const char *filename,const char *group);
113 my_bool
114 cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
115 		     const unsigned char *header, ulong header_length,
116 		     const unsigned char *arg, ulong arg_length,
117                      my_bool skip_check, MYSQL_STMT *stmt);
118 unsigned long cli_safe_read(MYSQL *mysql);
119 void net_clear_error(NET *net);
120 void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net);
121 void set_stmt_error(MYSQL_STMT *stmt, int errcode, const char *sqlstate,
122                     const char *err);
123 void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate);
124 void set_mysql_extended_error(MYSQL *mysql, int errcode, const char *sqlstate,
125                               const char *format, ...);
126 #ifdef EMBEDDED_LIBRARY
127 int embedded_ssl_check(MYSQL *mysql);
128 #endif
129 
130 /* client side of the pluggable authentication */
131 struct st_plugin_vio_info;
132 void mpvio_info(Vio *vio, struct st_plugin_vio_info *info);
133 int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
134                     const char *data_plugin, const char *db);
135 int mysql_client_plugin_init();
136 void mysql_client_plugin_deinit();
137 struct st_mysql_client_plugin;
138 extern struct st_mysql_client_plugin *mysql_client_builtins[];
139 uchar * send_client_connect_attrs(MYSQL *mysql, uchar *buf);
140 extern my_bool libmysql_cleartext_plugin_enabled;
141 int is_file_or_dir_world_writable(const char *filepath);
142 
143 #ifdef	__cplusplus
144 }
145 #endif
146 
147 #define protocol_41(A) ((A)->server_capabilities & CLIENT_PROTOCOL_41)
148 
149 #endif /* SQL_COMMON_INCLUDED */
150