1/************************************************************************************
2 Copyright (C) 2000, 2012 MySQL AB & MySQL Finland AB & TCX DataKonsult AB,
3 Monty Program AB
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not see <http://www.gnu.org/licenses>
17 or write to the Free Software Foundation, Inc.,
18 51 Franklin St., Fifth Floor, Boston, MA 02110, USA
19
20 Part of this code includes code from the PHP project which
21 is freely available from http://www.php.net
22*************************************************************************************/
23
24/*
25** Common definition between mysql server & client
26*/
27
28#ifndef _mysql_com_h
29#define _mysql_com_h
30
31
32#define NAME_CHAR_LEN 64
33#define NAME_LEN 256 /* Field/table name length */
34#define HOSTNAME_LENGTH 255
35#define SYSTEM_MB_MAX_CHAR_LENGTH 4
36#define USERNAME_CHAR_LENGTH 128
37#define USERNAME_LENGTH (USERNAME_CHAR_LENGTH * SYSTEM_MB_MAX_CHAR_LENGTH)
38#define SERVER_VERSION_LENGTH 60
39#define SQLSTATE_LENGTH 5
40#define SCRAMBLE_LENGTH 20
41#define SCRAMBLE_LENGTH_323 8
42
43#define LOCAL_HOST "localhost"
44#define LOCAL_HOST_NAMEDPIPE "."
45
46#if defined(_WIN32) && !defined( _CUSTOMCONFIG_)
47#define MARIADB_NAMEDPIPE "MySQL"
48#define MYSQL_SERVICENAME "MySql"
49#endif /* _WIN32 */
50
51/* for use in mysql client tools only */
52#define MYSQL_AUTODETECT_CHARSET_NAME "auto"
53#define BINCMP_FLAG 131072
54
55enum mysql_enum_shutdown_level
56{
57 SHUTDOWN_DEFAULT = 0,
58 KILL_QUERY= 254,
59 KILL_CONNECTION= 255
60};
61
62enum enum_server_command
63{
64 COM_SLEEP = 0,
65 COM_QUIT,
66 COM_INIT_DB,
67 COM_QUERY,
68 COM_FIELD_LIST,
69 COM_CREATE_DB,
70 COM_DROP_DB,
71 COM_REFRESH,
72 COM_SHUTDOWN,
73 COM_STATISTICS,
74 COM_PROCESS_INFO,
75 COM_CONNECT,
76 COM_PROCESS_KILL,
77 COM_DEBUG,
78 COM_PING,
79 COM_TIME = 15,
80 COM_DELAYED_INSERT,
81 COM_CHANGE_USER,
82 COM_BINLOG_DUMP,
83 COM_TABLE_DUMP,
84 COM_CONNECT_OUT = 20,
85 COM_REGISTER_SLAVE,
86 COM_STMT_PREPARE = 22,
87 COM_STMT_EXECUTE = 23,
88 COM_STMT_SEND_LONG_DATA = 24,
89 COM_STMT_CLOSE = 25,
90 COM_STMT_RESET = 26,
91 COM_SET_OPTION = 27,
92 COM_STMT_FETCH = 28,
93 COM_DAEMON= 29,
94 COM_UNSUPPORTED= 30,
95 COM_RESET_CONNECTION = 31,
96 COM_STMT_BULK_EXECUTE = 250,
97 COM_RESERVED_1 = 254, /* former COM_MULTI, now removed */
98 COM_END
99};
100
101
102#define NOT_NULL_FLAG 1 /* Field can't be NULL */
103#define PRI_KEY_FLAG 2 /* Field is part of a primary key */
104#define UNIQUE_KEY_FLAG 4 /* Field is part of a unique key */
105#define MULTIPLE_KEY_FLAG 8 /* Field is part of a key */
106#define BLOB_FLAG 16 /* Field is a blob */
107#define UNSIGNED_FLAG 32 /* Field is unsigned */
108#define ZEROFILL_FLAG 64 /* Field is zerofill */
109#define BINARY_FLAG 128
110/* The following are only sent to new clients */
111#define ENUM_FLAG 256 /* field is an enum */
112#define AUTO_INCREMENT_FLAG 512 /* field is a autoincrement field */
113#define TIMESTAMP_FLAG 1024 /* Field is a timestamp */
114#define SET_FLAG 2048 /* field is a set */
115/* new since 3.23.58 */
116#define NO_DEFAULT_VALUE_FLAG 4096 /* Field doesn't have default value */
117#define ON_UPDATE_NOW_FLAG 8192 /* Field is set to NOW on UPDATE */
118/* end new */
119#define NUM_FLAG 32768 /* Field is num (for clients) */
120#define PART_KEY_FLAG 16384 /* Intern; Part of some key */
121#define GROUP_FLAG 32768 /* Intern: Group field */
122#define UNIQUE_FLAG 65536 /* Intern: Used by sql_yacc */
123
124#define REFRESH_GRANT 1 /* Refresh grant tables */
125#define REFRESH_LOG 2 /* Start on new log file */
126#define REFRESH_TABLES 4 /* close all tables */
127#define REFRESH_HOSTS 8 /* Flush host cache */
128#define REFRESH_STATUS 16 /* Flush status variables */
129#define REFRESH_THREADS 32 /* Flush thread cache */
130#define REFRESH_SLAVE 64 /* Reset master info and restart slave
131 thread */
132#define REFRESH_MASTER 128 /* Remove all bin logs in the index
133 and truncate the index */
134
135/* The following can't be set with mysql_refresh() */
136#define REFRESH_READ_LOCK 16384 /* Lock tables for read */
137#define REFRESH_FAST 32768 /* Intern flag */
138
139#define CLIENT_MYSQL 1
140#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */
141#define CLIENT_LONG_FLAG 4 /* Get all column flags */
142#define CLIENT_CONNECT_WITH_DB 8 /* One can specify db on connect */
143#define CLIENT_NO_SCHEMA 16 /* Don't allow database.table.column */
144#define CLIENT_COMPRESS 32 /* Can use compression protocol */
145#define CLIENT_ODBC 64 /* Odbc client */
146#define CLIENT_LOCAL_FILES 128 /* Can use LOAD DATA LOCAL */
147#define CLIENT_IGNORE_SPACE 256 /* Ignore spaces before '(' */
148#define CLIENT_INTERACTIVE 1024 /* This is an interactive client */
149#define CLIENT_SSL 2048 /* Switch to SSL after handshake */
150#define CLIENT_IGNORE_SIGPIPE 4096 /* IGNORE sigpipes */
151#define CLIENT_TRANSACTIONS 8192 /* Client knows about transactions */
152/* added in 4.x */
153#define CLIENT_PROTOCOL_41 512
154#define CLIENT_RESERVED 16384
155#define CLIENT_SECURE_CONNECTION 32768
156#define CLIENT_MULTI_STATEMENTS (1UL << 16)
157#define CLIENT_MULTI_RESULTS (1UL << 17)
158#define CLIENT_PS_MULTI_RESULTS (1UL << 18)
159#define CLIENT_PLUGIN_AUTH (1UL << 19)
160#define CLIENT_CONNECT_ATTRS (1UL << 20)
161#define CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA (1UL << 21)
162#define CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS (1UL << 22)
163#define CLIENT_SESSION_TRACKING (1UL << 23)
164#define CLIENT_ZSTD_COMPRESSION (1UL << 26)
165#define CLIENT_PROGRESS (1UL << 29) /* client supports progress indicator */
166#define CLIENT_PROGRESS_OBSOLETE CLIENT_PROGRESS
167#define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30)
168#define CLIENT_SSL_VERIFY_SERVER_CERT_OBSOLETE CLIENT_SSL_VERIFY_SERVER_CERT
169#define CLIENT_REMEMBER_OPTIONS (1UL << 31)
170
171/* MariaDB specific capabilities */
172#define MARIADB_CLIENT_FLAGS 0xFFFFFFFF00000000ULL
173#define MARIADB_CLIENT_PROGRESS (1ULL << 32)
174#define MARIADB_CLIENT_RESERVED_1 (1ULL << 33) /* Former COM_MULTI, don't use */
175#define MARIADB_CLIENT_STMT_BULK_OPERATIONS (1ULL << 34)
176/* support of extended data type/format information, since 10.5.0 */
177#define MARIADB_CLIENT_EXTENDED_METADATA (1ULL << 35)
178/* Do not resend metadata for prepared statements, since 10.6*/
179#define MARIADB_CLIENT_CACHE_METADATA (1ULL << 36)
180/* permit sending unit result-set for BULK commands */
181#define MARIADB_CLIENT_BULK_UNIT_RESULTS (1ULL << 37)
182
183#define IS_MARIADB_EXTENDED_SERVER(mysql)\
184 (!(mysql->server_capabilities & CLIENT_MYSQL))
185
186#define MARIADB_CLIENT_SUPPORTED_FLAGS (MARIADB_CLIENT_PROGRESS |\
187 MARIADB_CLIENT_STMT_BULK_OPERATIONS|\
188 MARIADB_CLIENT_EXTENDED_METADATA|\
189 MARIADB_CLIENT_CACHE_METADATA|\
190 MARIADB_CLIENT_BULK_UNIT_RESULTS)
191
192#define CLIENT_SUPPORTED_FLAGS (CLIENT_MYSQL |\
193 CLIENT_FOUND_ROWS |\
194 CLIENT_LONG_FLAG |\
195 CLIENT_CONNECT_WITH_DB |\
196 CLIENT_NO_SCHEMA |\
197 CLIENT_COMPRESS |\
198 CLIENT_ODBC |\
199 CLIENT_LOCAL_FILES |\
200 CLIENT_IGNORE_SPACE |\
201 CLIENT_INTERACTIVE |\
202 CLIENT_SSL |\
203 CLIENT_IGNORE_SIGPIPE |\
204 CLIENT_TRANSACTIONS |\
205 CLIENT_PROTOCOL_41 |\
206 CLIENT_RESERVED |\
207 CLIENT_SECURE_CONNECTION |\
208 CLIENT_MULTI_STATEMENTS |\
209 CLIENT_MULTI_RESULTS |\
210 CLIENT_PROGRESS |\
211 CLIENT_SSL_VERIFY_SERVER_CERT |\
212 CLIENT_REMEMBER_OPTIONS |\
213 CLIENT_PLUGIN_AUTH |\
214 CLIENT_SESSION_TRACKING |\
215 CLIENT_CONNECT_ATTRS)
216#define CLIENT_ALLOWED_FLAGS (CLIENT_SUPPORTED_FLAGS |\
217 CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA |\
218 CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS |\
219 CLIENT_ZSTD_COMPRESSION |\
220 CLIENT_PS_MULTI_RESULTS |\
221 CLIENT_REMEMBER_OPTIONS)
222#define CLIENT_CAPABILITIES (CLIENT_MYSQL | \
223 CLIENT_LONG_FLAG |\
224 CLIENT_TRANSACTIONS |\
225 CLIENT_SECURE_CONNECTION |\
226 CLIENT_MULTI_RESULTS | \
227 CLIENT_PS_MULTI_RESULTS |\
228 CLIENT_PROTOCOL_41 |\
229 CLIENT_PLUGIN_AUTH |\
230 CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA | \
231 CLIENT_SESSION_TRACKING |\
232 CLIENT_CONNECT_ATTRS)
233
234#define CLIENT_DEFAULT_FLAGS ((CLIENT_SUPPORTED_FLAGS & ~CLIENT_COMPRESS)\
235 & ~CLIENT_SSL)
236
237#define CLIENT_DEFAULT_EXTENDED_FLAGS (MARIADB_CLIENT_SUPPORTED_FLAGS &\
238 ~MARIADB_CLIENT_BULK_UNIT_RESULTS)
239
240#define SERVER_STATUS_IN_TRANS 1 /* Transaction has started */
241#define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */
242#define SERVER_MORE_RESULTS_EXIST 8
243#define SERVER_QUERY_NO_GOOD_INDEX_USED 16
244#define SERVER_QUERY_NO_INDEX_USED 32
245#define SERVER_STATUS_CURSOR_EXISTS 64
246#define SERVER_STATUS_LAST_ROW_SENT 128
247#define SERVER_STATUS_DB_DROPPED 256
248#define SERVER_STATUS_NO_BACKSLASH_ESCAPES 512
249#define SERVER_STATUS_METADATA_CHANGED 1024
250#define SERVER_QUERY_WAS_SLOW 2048
251#define SERVER_PS_OUT_PARAMS 4096
252#define SERVER_STATUS_IN_TRANS_READONLY 8192
253#define SERVER_SESSION_STATE_CHANGED 16384
254#define SERVER_STATUS_ANSI_QUOTES 32768
255
256#define MYSQL_ERRMSG_SIZE 512
257#define NET_READ_TIMEOUT 30 /* Timeout on read */
258#define NET_WRITE_TIMEOUT 60 /* Timeout on write */
259#define NET_WAIT_TIMEOUT (8*60*60) /* Wait for new query */
260
261/* for server integration (mysqlbinlog) */
262#define LIST_PROCESS_HOST_LEN 64
263#define MYSQL50_TABLE_NAME_PREFIX "#mysql50#"
264#define MYSQL50_TABLE_NAME_PREFIX_LENGTH (sizeof(MYSQL50_TABLE_NAME_PREFIX)-1)
265#define SAFE_NAME_LEN (NAME_LEN + MYSQL50_TABLE_NAME_PREFIX_LENGTH)
266
267struct st_ma_pvio;
268typedef struct st_ma_pvio MARIADB_PVIO;
269
270#define MAX_CHAR_WIDTH 255 /* Max length for a CHAR column */
271#define MAX_BLOB_WIDTH 8192 /* Default width for blob */
272
273/* the following defines were added for PHP's mysqli and pdo extensions:
274 see: CONC-56
275*/
276#define MAX_TINYINT_WIDTH 3
277#define MAX_SMALLINT_WIDTH 5
278#define MAX_MEDIUMINT_WIDTH 8
279#define MAX_INT_WIDTH 10
280#define MAX_BIGINT_WIDTH 20
281
282struct st_ma_connection_plugin;
283
284
285typedef struct st_net {
286 MARIADB_PVIO *pvio;
287 unsigned char *buff;
288 unsigned char *buff_end,*write_pos,*read_pos;
289 my_socket fd; /* For Perl DBI/dbd */
290 unsigned long remain_in_buf,length;
291 unsigned long buf_length, where_b;
292 unsigned long max_packet, max_packet_size;
293 unsigned int pkt_nr, compress_pkt_nr;
294 unsigned int write_timeout, read_timeout, retry_count;
295 int fcntl;
296 unsigned int *return_status;
297 unsigned char reading_or_writing;
298 char save_char;
299 char unused_1;
300 my_bool unused_2;
301 my_bool compress;
302 my_bool unused_3;
303 const char *tls_self_signed_error;
304 unsigned int last_errno;
305 unsigned char error;
306 my_bool unused_5;
307 my_bool unused_6;
308 char last_error[MYSQL_ERRMSG_SIZE];
309 char sqlstate[SQLSTATE_LENGTH+1];
310 struct st_mariadb_net_extension *extension;
311} NET;
312
313#define packet_error ((unsigned int) -1)
314
315/* used by mysql_set_server_option */
316enum enum_mysql_set_option
317{
318 MYSQL_OPTION_MULTI_STATEMENTS_ON,
319 MYSQL_OPTION_MULTI_STATEMENTS_OFF
320};
321
322/* for status callback function */
323enum enum_mariadb_status_info
324{
325 STATUS_TYPE= 0,
326 SESSION_TRACK_TYPE
327};
328
329enum enum_session_state_type
330{
331 SESSION_TRACK_SYSTEM_VARIABLES= 0,
332 SESSION_TRACK_SCHEMA,
333 SESSION_TRACK_STATE_CHANGE,
334 /* currently not supported by MariaDB Server */
335 SESSION_TRACK_GTIDS,
336 SESSION_TRACK_TRANSACTION_CHARACTERISTICS,
337 SESSION_TRACK_TRANSACTION_STATE /* make sure that SESSION_TRACK_END always points
338 to last element of enum !! */
339};
340
341#define SESSION_TRACK_BEGIN 0
342#define SESSION_TRACK_END SESSION_TRACK_TRANSACTION_STATE
343#define SESSION_TRACK_TYPES (SESSION_TRACK_END + 1)
344
345/* SESSION_TRACK_TRANSACTION_TYPE was renamed to SESSION_TRACK_TRANSACTION_STATE
346 in 3e699a1738cdfb0a2c5b8eabfa8301b8d11cf711.
347 This is a workaround to prevent breaking of travis and buildbot tests.
348 TODO: Remove this after server fixes */
349#define SESSION_TRACK_TRANSACTION_TYPE SESSION_TRACK_TRANSACTION_STATE
350
351enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,
352 MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
353 MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
354 MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP,
355 MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24,
356 MYSQL_TYPE_DATE, MYSQL_TYPE_TIME,
357 MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
358 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
359 MYSQL_TYPE_BIT,
360 /*
361 the following types are not used by client,
362 only for mysqlbinlog!!
363 */
364 MYSQL_TYPE_TIMESTAMP2,
365 MYSQL_TYPE_DATETIME2,
366 MYSQL_TYPE_TIME2,
367 /* --------------------------------------------- */
368 MYSQL_TYPE_JSON=245,
369 MYSQL_TYPE_NEWDECIMAL=246,
370 MYSQL_TYPE_ENUM=247,
371 MYSQL_TYPE_SET=248,
372 MYSQL_TYPE_TINY_BLOB=249,
373 MYSQL_TYPE_MEDIUM_BLOB=250,
374 MYSQL_TYPE_LONG_BLOB=251,
375 MYSQL_TYPE_BLOB=252,
376 MYSQL_TYPE_VAR_STRING=253,
377 MYSQL_TYPE_STRING=254,
378 MYSQL_TYPE_GEOMETRY=255,
379 MAX_NO_FIELD_TYPES };
380
381#define FIELD_TYPE_CHAR FIELD_TYPE_TINY /* For compatibility */
382#define FIELD_TYPE_INTERVAL FIELD_TYPE_ENUM /* For compatibility */
383#define FIELD_TYPE_DECIMAL MYSQL_TYPE_DECIMAL
384#define FIELD_TYPE_NEWDECIMAL MYSQL_TYPE_NEWDECIMAL
385#define FIELD_TYPE_TINY MYSQL_TYPE_TINY
386#define FIELD_TYPE_SHORT MYSQL_TYPE_SHORT
387#define FIELD_TYPE_LONG MYSQL_TYPE_LONG
388#define FIELD_TYPE_FLOAT MYSQL_TYPE_FLOAT
389#define FIELD_TYPE_DOUBLE MYSQL_TYPE_DOUBLE
390#define FIELD_TYPE_NULL MYSQL_TYPE_NULL
391#define FIELD_TYPE_TIMESTAMP MYSQL_TYPE_TIMESTAMP
392#define FIELD_TYPE_LONGLONG MYSQL_TYPE_LONGLONG
393#define FIELD_TYPE_INT24 MYSQL_TYPE_INT24
394#define FIELD_TYPE_DATE MYSQL_TYPE_DATE
395#define FIELD_TYPE_TIME MYSQL_TYPE_TIME
396#define FIELD_TYPE_DATETIME MYSQL_TYPE_DATETIME
397#define FIELD_TYPE_YEAR MYSQL_TYPE_YEAR
398#define FIELD_TYPE_NEWDATE MYSQL_TYPE_NEWDATE
399#define FIELD_TYPE_ENUM MYSQL_TYPE_ENUM
400#define FIELD_TYPE_SET MYSQL_TYPE_SET
401#define FIELD_TYPE_TINY_BLOB MYSQL_TYPE_TINY_BLOB
402#define FIELD_TYPE_MEDIUM_BLOB MYSQL_TYPE_MEDIUM_BLOB
403#define FIELD_TYPE_LONG_BLOB MYSQL_TYPE_LONG_BLOB
404#define FIELD_TYPE_BLOB MYSQL_TYPE_BLOB
405#define FIELD_TYPE_VAR_STRING MYSQL_TYPE_VAR_STRING
406#define FIELD_TYPE_STRING MYSQL_TYPE_STRING
407#define FIELD_TYPE_GEOMETRY MYSQL_TYPE_GEOMETRY
408#define FIELD_TYPE_BIT MYSQL_TYPE_BIT
409
410extern unsigned long max_allowed_packet;
411extern unsigned long net_buffer_length;
412
413#define net_new_transaction(net) ((net)->pkt_nr=0)
414
415int ma_net_init(NET *net, MARIADB_PVIO *pvio);
416void ma_net_end(NET *net);
417void ma_net_clear(NET *net);
418int ma_net_flush(NET *net);
419int ma_net_write(NET *net,const unsigned char *packet, size_t len);
420int ma_net_write_command(NET *net,unsigned char command,const char *packet,
421 size_t len, my_bool disable_flush);
422int ma_net_real_write(NET *net,const char *packet, size_t len);
423extern unsigned long ma_net_read(NET *net);
424
425struct rand_struct {
426 unsigned long seed1,seed2,max_value;
427 double max_value_dbl;
428};
429
430 /* The following is for user defined functions */
431
432enum Item_result {STRING_RESULT,REAL_RESULT,INT_RESULT,ROW_RESULT,DECIMAL_RESULT};
433
434typedef struct st_udf_args
435{
436 unsigned int arg_count; /* Number of arguments */
437 enum Item_result *arg_type; /* Pointer to item_results */
438 char **args; /* Pointer to argument */
439 unsigned long *lengths; /* Length of string arguments */
440 char *maybe_null; /* Set to 1 for all maybe_null args */
441} UDF_ARGS;
442
443 /* This holds information about the result */
444
445typedef struct st_udf_init
446{
447 my_bool maybe_null; /* 1 if function can return NULL */
448 unsigned int decimals; /* for real functions */
449 unsigned int max_length; /* For string functions */
450 char *ptr; /* free pointer for function data */
451 my_bool const_item; /* 0 if result is independent of arguments */
452} UDF_INIT;
453
454/* Connection types */
455#define MARIADB_CONNECTION_UNIXSOCKET 0
456#define MARIADB_CONNECTION_TCP 1
457#define MARIADB_CONNECTION_NAMEDPIPE 2
458#define MARIADB_CONNECTION_SHAREDMEM 3
459
460 /* Constants when using compression */
461#define NET_HEADER_SIZE 4 /* standard header size */
462#define COMP_HEADER_SIZE 3 /* compression header extra size */
463
464 /* Prototypes to password functions */
465#define native_password_plugin_name "mysql_native_password"
466#define old_password_plugin_name "mysql_old_password"
467
468#ifdef __cplusplus
469extern "C" {
470#endif
471
472char *ma_scramble_323(char *to,const char *message,const char *password);
473void ma_scramble_41(const unsigned char *buffer, const char *scramble, const char *password);
474void ma_hash_password(unsigned long *result, const char *password, size_t len);
475void ma_make_scrambled_password(char *to,const char *password);
476
477/* Some other useful functions */
478
479void mariadb_load_defaults(const char *conf_file, const char **groups,
480 int *argc, char ***argv);
481my_bool ma_thread_init(void);
482void ma_thread_end(void);
483
484#ifdef __cplusplus
485}
486#endif
487
488#define NULL_LENGTH ((unsigned long) ~0) /* For net_store_length */
489
490#endif
491