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 60
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_MULTI = 254,
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_CAN_HANDLE_EXPIRED_PASSWORDS (1UL << 22)
162#define CLIENT_SESSION_TRACKING (1UL << 23)
163#define CLIENT_PROGRESS (1UL << 29) /* client supports progress indicator */
164#define CLIENT_PROGRESS_OBSOLETE CLIENT_PROGRESS
165#define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30)
166#define CLIENT_REMEMBER_OPTIONS (1UL << 31)
167
168/* MariaDB specific capabilities */
169#define MARIADB_CLIENT_FLAGS 0xFFFFFFFF00000000ULL
170#define MARIADB_CLIENT_PROGRESS (1ULL << 32)
171#define MARIADB_CLIENT_COM_MULTI (1ULL << 33)
172#define MARIADB_CLIENT_STMT_BULK_OPERATIONS (1ULL << 34)
173
174#define IS_MARIADB_EXTENDED_SERVER(mysql)\
175 !(mysql->server_capabilities & CLIENT_MYSQL)
176
177#define MARIADB_CLIENT_SUPPORTED_FLAGS (MARIADB_CLIENT_PROGRESS |\
178 MARIADB_CLIENT_COM_MULTI |\
179 MARIADB_CLIENT_STMT_BULK_OPERATIONS)
180
181#define CLIENT_SUPPORTED_FLAGS (CLIENT_MYSQL |\
182 CLIENT_FOUND_ROWS |\
183 CLIENT_LONG_FLAG |\
184 CLIENT_CONNECT_WITH_DB |\
185 CLIENT_NO_SCHEMA |\
186 CLIENT_COMPRESS |\
187 CLIENT_ODBC |\
188 CLIENT_LOCAL_FILES |\
189 CLIENT_IGNORE_SPACE |\
190 CLIENT_INTERACTIVE |\
191 CLIENT_SSL |\
192 CLIENT_IGNORE_SIGPIPE |\
193 CLIENT_TRANSACTIONS |\
194 CLIENT_PROTOCOL_41 |\
195 CLIENT_RESERVED |\
196 CLIENT_SECURE_CONNECTION |\
197 CLIENT_MULTI_STATEMENTS |\
198 CLIENT_MULTI_RESULTS |\
199 CLIENT_PROGRESS |\
200 CLIENT_SSL_VERIFY_SERVER_CERT |\
201 CLIENT_REMEMBER_OPTIONS |\
202 CLIENT_PLUGIN_AUTH |\
203 CLIENT_SESSION_TRACKING |\
204 CLIENT_CONNECT_ATTRS)
205
206#define CLIENT_CAPABILITIES (CLIENT_MYSQL | \
207 CLIENT_LONG_FLAG |\
208 CLIENT_TRANSACTIONS |\
209 CLIENT_SECURE_CONNECTION |\
210 CLIENT_MULTI_RESULTS | \
211 CLIENT_PS_MULTI_RESULTS |\
212 CLIENT_PROTOCOL_41 |\
213 CLIENT_PLUGIN_AUTH |\
214 CLIENT_SESSION_TRACKING |\
215 CLIENT_CONNECT_ATTRS)
216
217#define CLIENT_DEFAULT_FLAGS ((CLIENT_SUPPORTED_FLAGS & ~CLIENT_COMPRESS)\
218 & ~CLIENT_SSL)
219
220#define SERVER_STATUS_IN_TRANS 1 /* Transaction has started */
221#define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */
222#define SERVER_MORE_RESULTS_EXIST 8
223#define SERVER_QUERY_NO_GOOD_INDEX_USED 16
224#define SERVER_QUERY_NO_INDEX_USED 32
225#define SERVER_STATUS_CURSOR_EXISTS 64
226#define SERVER_STATUS_LAST_ROW_SENT 128
227#define SERVER_STATUS_DB_DROPPED 256
228#define SERVER_STATUS_NO_BACKSLASH_ESCAPES 512
229#define SERVER_STATUS_METADATA_CHANGED 1024
230#define SERVER_QUERY_WAS_SLOW 2048
231#define SERVER_PS_OUT_PARAMS 4096
232#define SERVER_STATUS_IN_TRANS_READONLY 8192
233#define SERVER_SESSION_STATE_CHANGED 16384
234#define SERVER_STATUS_ANSI_QUOTES 32768
235
236#define MYSQL_ERRMSG_SIZE 512
237#define NET_READ_TIMEOUT 30 /* Timeout on read */
238#define NET_WRITE_TIMEOUT 60 /* Timeout on write */
239#define NET_WAIT_TIMEOUT 8*60*60 /* Wait for new query */
240
241/* for server integration (mysqlbinlog) */
242#define LIST_PROCESS_HOST_LEN 64
243#define MYSQL50_TABLE_NAME_PREFIX "#mysql50#"
244#define MYSQL50_TABLE_NAME_PREFIX_LENGTH (sizeof(MYSQL50_TABLE_NAME_PREFIX)-1)
245#define SAFE_NAME_LEN (NAME_LEN + MYSQL50_TABLE_NAME_PREFIX_LENGTH)
246
247struct st_ma_pvio;
248typedef struct st_ma_pvio MARIADB_PVIO;
249
250#define MAX_CHAR_WIDTH 255 /* Max length for a CHAR column */
251#define MAX_BLOB_WIDTH 8192 /* Default width for blob */
252
253/* the following defines were added for PHP's mysqli and pdo extensions:
254 see: CONC-56
255*/
256#define MAX_TINYINT_WIDTH 3
257#define MAX_SMALLINT_WIDTH 5
258#define MAX_MEDIUMINT_WIDTH 8
259#define MAX_INT_WIDTH 10
260#define MAX_BIGINT_WIDTH 20
261
262struct st_ma_connection_plugin;
263
264
265typedef struct st_net {
266 MARIADB_PVIO *pvio;
267 unsigned char *buff;
268 unsigned char *buff_end,*write_pos,*read_pos;
269 my_socket fd; /* For Perl DBI/dbd */
270 unsigned long remain_in_buf,length;
271 unsigned long buf_length, where_b;
272 unsigned long max_packet, max_packet_size;
273 unsigned int pkt_nr, compress_pkt_nr;
274 unsigned int write_timeout, read_timeout, retry_count;
275 int fcntl;
276 unsigned int *return_status;
277 unsigned char reading_or_writing;
278 char save_char;
279 char unused_1;
280 my_bool unused_2;
281 my_bool compress;
282 my_bool unused_3;
283 void *unused_4;
284 unsigned int last_errno;
285 unsigned char error;
286 my_bool unused_5;
287 my_bool unused_6;
288 char last_error[MYSQL_ERRMSG_SIZE];
289 char sqlstate[SQLSTATE_LENGTH+1];
290 struct st_mariadb_net_extension *extension;
291} NET;
292
293#define packet_error ((unsigned int) -1)
294
295/* used by mysql_set_server_option */
296enum enum_mysql_set_option
297{
298 MYSQL_OPTION_MULTI_STATEMENTS_ON,
299 MYSQL_OPTION_MULTI_STATEMENTS_OFF
300};
301
302enum enum_session_state_type
303{
304 SESSION_TRACK_SYSTEM_VARIABLES= 0,
305 SESSION_TRACK_SCHEMA,
306 SESSION_TRACK_STATE_CHANGE,
307 /* currently not supported by MariaDB Server */
308 SESSION_TRACK_GTIDS,
309 SESSION_TRACK_TRANSACTION_CHARACTERISTICS,
310 SESSION_TRACK_TRANSACTION_TYPE /* make sure that SESSION_TRACK_END always points
311 to last element of enum !! */
312};
313
314#define SESSION_TRACK_BEGIN 0
315#define SESSION_TRACK_END SESSION_TRACK_TRANSACTION_TYPE
316#define SESSION_TRACK_TYPES SESSION_TRACK_END + 1
317
318enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,
319 MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
320 MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
321 MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP,
322 MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24,
323 MYSQL_TYPE_DATE, MYSQL_TYPE_TIME,
324 MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
325 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
326 MYSQL_TYPE_BIT,
327 /*
328 the following types are not used by client,
329 only for mysqlbinlog!!
330 */
331 MYSQL_TYPE_TIMESTAMP2,
332 MYSQL_TYPE_DATETIME2,
333 MYSQL_TYPE_TIME2,
334 /* --------------------------------------------- */
335 MYSQL_TYPE_JSON=245,
336 MYSQL_TYPE_NEWDECIMAL=246,
337 MYSQL_TYPE_ENUM=247,
338 MYSQL_TYPE_SET=248,
339 MYSQL_TYPE_TINY_BLOB=249,
340 MYSQL_TYPE_MEDIUM_BLOB=250,
341 MYSQL_TYPE_LONG_BLOB=251,
342 MYSQL_TYPE_BLOB=252,
343 MYSQL_TYPE_VAR_STRING=253,
344 MYSQL_TYPE_STRING=254,
345 MYSQL_TYPE_GEOMETRY=255,
346 MAX_NO_FIELD_TYPES };
347
348#define FIELD_TYPE_CHAR FIELD_TYPE_TINY /* For compatibility */
349#define FIELD_TYPE_INTERVAL FIELD_TYPE_ENUM /* For compatibility */
350#define FIELD_TYPE_DECIMAL MYSQL_TYPE_DECIMAL
351#define FIELD_TYPE_NEWDECIMAL MYSQL_TYPE_NEWDECIMAL
352#define FIELD_TYPE_TINY MYSQL_TYPE_TINY
353#define FIELD_TYPE_SHORT MYSQL_TYPE_SHORT
354#define FIELD_TYPE_LONG MYSQL_TYPE_LONG
355#define FIELD_TYPE_FLOAT MYSQL_TYPE_FLOAT
356#define FIELD_TYPE_DOUBLE MYSQL_TYPE_DOUBLE
357#define FIELD_TYPE_NULL MYSQL_TYPE_NULL
358#define FIELD_TYPE_TIMESTAMP MYSQL_TYPE_TIMESTAMP
359#define FIELD_TYPE_LONGLONG MYSQL_TYPE_LONGLONG
360#define FIELD_TYPE_INT24 MYSQL_TYPE_INT24
361#define FIELD_TYPE_DATE MYSQL_TYPE_DATE
362#define FIELD_TYPE_TIME MYSQL_TYPE_TIME
363#define FIELD_TYPE_DATETIME MYSQL_TYPE_DATETIME
364#define FIELD_TYPE_YEAR MYSQL_TYPE_YEAR
365#define FIELD_TYPE_NEWDATE MYSQL_TYPE_NEWDATE
366#define FIELD_TYPE_ENUM MYSQL_TYPE_ENUM
367#define FIELD_TYPE_SET MYSQL_TYPE_SET
368#define FIELD_TYPE_TINY_BLOB MYSQL_TYPE_TINY_BLOB
369#define FIELD_TYPE_MEDIUM_BLOB MYSQL_TYPE_MEDIUM_BLOB
370#define FIELD_TYPE_LONG_BLOB MYSQL_TYPE_LONG_BLOB
371#define FIELD_TYPE_BLOB MYSQL_TYPE_BLOB
372#define FIELD_TYPE_VAR_STRING MYSQL_TYPE_VAR_STRING
373#define FIELD_TYPE_STRING MYSQL_TYPE_STRING
374#define FIELD_TYPE_GEOMETRY MYSQL_TYPE_GEOMETRY
375#define FIELD_TYPE_BIT MYSQL_TYPE_BIT
376
377extern unsigned long max_allowed_packet;
378extern unsigned long net_buffer_length;
379
380#define net_new_transaction(net) ((net)->pkt_nr=0)
381
382int ma_net_init(NET *net, MARIADB_PVIO *pvio);
383void ma_net_end(NET *net);
384void ma_net_clear(NET *net);
385int ma_net_flush(NET *net);
386int ma_net_write(NET *net,const unsigned char *packet, size_t len);
387int ma_net_write_command(NET *net,unsigned char command,const char *packet,
388 size_t len, my_bool disable_flush);
389int ma_net_real_write(NET *net,const char *packet, size_t len);
390extern unsigned long ma_net_read(NET *net);
391
392struct rand_struct {
393 unsigned long seed1,seed2,max_value;
394 double max_value_dbl;
395};
396
397 /* The following is for user defined functions */
398
399enum Item_result {STRING_RESULT,REAL_RESULT,INT_RESULT,ROW_RESULT,DECIMAL_RESULT};
400
401typedef struct st_udf_args
402{
403 unsigned int arg_count; /* Number of arguments */
404 enum Item_result *arg_type; /* Pointer to item_results */
405 char **args; /* Pointer to argument */
406 unsigned long *lengths; /* Length of string arguments */
407 char *maybe_null; /* Set to 1 for all maybe_null args */
408} UDF_ARGS;
409
410 /* This holds information about the result */
411
412typedef struct st_udf_init
413{
414 my_bool maybe_null; /* 1 if function can return NULL */
415 unsigned int decimals; /* for real functions */
416 unsigned int max_length; /* For string functions */
417 char *ptr; /* free pointer for function data */
418 my_bool const_item; /* 0 if result is independent of arguments */
419} UDF_INIT;
420
421/* Connection types */
422#define MARIADB_CONNECTION_UNIXSOCKET 0
423#define MARIADB_CONNECTION_TCP 1
424#define MARIADB_CONNECTION_NAMEDPIPE 2
425#define MARIADB_CONNECTION_SHAREDMEM 3
426
427 /* Constants when using compression */
428#define NET_HEADER_SIZE 4 /* standard header size */
429#define COMP_HEADER_SIZE 3 /* compression header extra size */
430
431 /* Prototypes to password functions */
432#define native_password_plugin_name "mysql_native_password"
433#define old_password_plugin_name "mysql_old_password"
434
435#ifdef __cplusplus
436extern "C" {
437#endif
438
439char *ma_scramble_323(char *to,const char *message,const char *password);
440void ma_scramble_41(const unsigned char *buffer, const char *scramble, const char *password);
441void ma_hash_password(unsigned long *result, const char *password, size_t len);
442void ma_make_scrambled_password(char *to,const char *password);
443
444/* Some other useful functions */
445
446void mariadb_load_defaults(const char *conf_file, const char **groups,
447 int *argc, char ***argv);
448my_bool ma_thread_init(void);
449void ma_thread_end(void);
450
451#ifdef __cplusplus
452}
453#endif
454
455#define NULL_LENGTH ((unsigned long) ~0) /* For net_store_length */
456
457#endif
458