00001 /* Copyright (C) 2000 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 /* 00018 ** Common definition between mysql server & client 00019 */ 00020 00021 #ifndef _mysql_com_h 00022 #define _mysql_com_h 00023 00024 #define NAME_LEN 64 /* Field/table name length */ 00025 #define HOSTNAME_LENGTH 60 00026 #define USERNAME_LENGTH 16 00027 #define SERVER_VERSION_LENGTH 60 00028 #define SQLSTATE_LENGTH 5 00029 00030 /* 00031 USER_HOST_BUFF_SIZE -- length of string buffer, that is enough to contain 00032 username and hostname parts of the user identifier with trailing zero in 00033 MySQL standard format: 00034 user_name_part@host_name_part\0 00035 */ 00036 #define USER_HOST_BUFF_SIZE HOSTNAME_LENGTH + USERNAME_LENGTH + 2 00037 00038 #define LOCAL_HOST "localhost" 00039 #define LOCAL_HOST_NAMEDPIPE "." 00040 00041 00042 #if defined(__WIN__) && !defined( _CUSTOMCONFIG_) 00043 #define MYSQL_NAMEDPIPE "MySQL" 00044 #define MYSQL_SERVICENAME "MySQL" 00045 #endif /* __WIN__ */ 00046 00047 /* 00048 You should add new commands to the end of this list, otherwise old 00049 servers won't be able to handle them as 'unsupported'. 00050 */ 00051 00052 enum enum_server_command 00053 { 00054 COM_SLEEP, COM_QUIT, COM_INIT_DB, COM_QUERY, COM_FIELD_LIST, 00055 COM_CREATE_DB, COM_DROP_DB, COM_REFRESH, COM_SHUTDOWN, COM_STATISTICS, 00056 COM_PROCESS_INFO, COM_CONNECT, COM_PROCESS_KILL, COM_DEBUG, COM_PING, 00057 COM_TIME, COM_DELAYED_INSERT, COM_CHANGE_USER, COM_BINLOG_DUMP, 00058 COM_TABLE_DUMP, COM_CONNECT_OUT, COM_REGISTER_SLAVE, 00059 COM_STMT_PREPARE, COM_STMT_EXECUTE, COM_STMT_SEND_LONG_DATA, COM_STMT_CLOSE, 00060 COM_STMT_RESET, COM_SET_OPTION, COM_STMT_FETCH, COM_DAEMON, 00061 /* don't forget to update const char *command_name[] in sql_parse.cc */ 00062 00063 /* Must be last */ 00064 COM_END 00065 }; 00066 00067 00068 /* 00069 Length of random string sent by server on handshake; this is also length of 00070 obfuscated password, recieved from client 00071 */ 00072 #define SCRAMBLE_LENGTH 20 00073 #define SCRAMBLE_LENGTH_323 8 00074 /* length of password stored in the db: new passwords are preceeded with '*' */ 00075 #define SCRAMBLED_PASSWORD_CHAR_LENGTH (SCRAMBLE_LENGTH*2+1) 00076 #define SCRAMBLED_PASSWORD_CHAR_LENGTH_323 (SCRAMBLE_LENGTH_323*2) 00077 00078 00079 #define NOT_NULL_FLAG 1 /* Field can't be NULL */ 00080 #define PRI_KEY_FLAG 2 /* Field is part of a primary key */ 00081 #define UNIQUE_KEY_FLAG 4 /* Field is part of a unique key */ 00082 #define MULTIPLE_KEY_FLAG 8 /* Field is part of a key */ 00083 #define BLOB_FLAG 16 /* Field is a blob */ 00084 #define UNSIGNED_FLAG 32 /* Field is unsigned */ 00085 #define ZEROFILL_FLAG 64 /* Field is zerofill */ 00086 #define BINARY_FLAG 128 /* Field is binary */ 00087 00088 /* The following are only sent to new clients */ 00089 #define ENUM_FLAG 256 /* field is an enum */ 00090 #define AUTO_INCREMENT_FLAG 512 /* field is a autoincrement field */ 00091 #define TIMESTAMP_FLAG 1024 /* Field is a timestamp */ 00092 #define SET_FLAG 2048 /* field is a set */ 00093 #define NO_DEFAULT_VALUE_FLAG 4096 /* Field doesn't have default value */ 00094 #define NUM_FLAG 32768 /* Field is num (for clients) */ 00095 #define PART_KEY_FLAG 16384 /* Intern; Part of some key */ 00096 #define GROUP_FLAG 32768 /* Intern: Group field */ 00097 #define UNIQUE_FLAG 65536 /* Intern: Used by sql_yacc */ 00098 #define BINCMP_FLAG 131072 /* Intern: Used by sql_yacc */ 00099 #define GET_FIXED_FIELDS_FLAG (1 << 18) /* Used to get fields in item tree */ 00100 #define FIELD_IN_PART_FUNC_FLAG (1 << 19)/* Field part of partition func */ 00101 #define FIELD_IN_ADD_INDEX (1<< 20) /* Intern: Field used in ADD INDEX */ 00102 #define FIELD_IS_RENAMED (1<< 21) /* Intern: Field is being renamed */ 00103 00104 #define REFRESH_GRANT 1 /* Refresh grant tables */ 00105 #define REFRESH_LOG 2 /* Start on new log file */ 00106 #define REFRESH_TABLES 4 /* close all tables */ 00107 #define REFRESH_HOSTS 8 /* Flush host cache */ 00108 #define REFRESH_STATUS 16 /* Flush status variables */ 00109 #define REFRESH_THREADS 32 /* Flush thread cache */ 00110 #define REFRESH_SLAVE 64 /* Reset master info and restart slave 00111 thread */ 00112 #define REFRESH_MASTER 128 /* Remove all bin logs in the index 00113 and truncate the index */ 00114 00115 /* The following can't be set with mysql_refresh() */ 00116 #define REFRESH_READ_LOCK 16384 /* Lock tables for read */ 00117 #define REFRESH_FAST 32768 /* Intern flag */ 00118 00119 /* RESET (remove all queries) from query cache */ 00120 #define REFRESH_QUERY_CACHE 65536 00121 #define REFRESH_QUERY_CACHE_FREE 0x20000L /* pack query cache */ 00122 #define REFRESH_DES_KEY_FILE 0x40000L 00123 #define REFRESH_USER_RESOURCES 0x80000L 00124 00125 #define CLIENT_LONG_PASSWORD 1 /* new more secure passwords */ 00126 #define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */ 00127 #define CLIENT_LONG_FLAG 4 /* Get all column flags */ 00128 #define CLIENT_CONNECT_WITH_DB 8 /* One can specify db on connect */ 00129 #define CLIENT_NO_SCHEMA 16 /* Don't allow database.table.column */ 00130 #define CLIENT_COMPRESS 32 /* Can use compression protocol */ 00131 #define CLIENT_ODBC 64 /* Odbc client */ 00132 #define CLIENT_LOCAL_FILES 128 /* Can use LOAD DATA LOCAL */ 00133 #define CLIENT_IGNORE_SPACE 256 /* Ignore spaces before '(' */ 00134 #define CLIENT_PROTOCOL_41 512 /* New 4.1 protocol */ 00135 #define CLIENT_INTERACTIVE 1024 /* This is an interactive client */ 00136 #define CLIENT_SSL 2048 /* Switch to SSL after handshake */ 00137 #define CLIENT_IGNORE_SIGPIPE 4096 /* IGNORE sigpipes */ 00138 #define CLIENT_TRANSACTIONS 8192 /* Client knows about transactions */ 00139 #define CLIENT_RESERVED 16384 /* Old flag for 4.1 protocol */ 00140 #define CLIENT_SECURE_CONNECTION 32768 /* New 4.1 authentication */ 00141 #define CLIENT_MULTI_STATEMENTS 65536 /* Enable/disable multi-stmt support */ 00142 #define CLIENT_MULTI_RESULTS 131072 /* Enable/disable multi-results */ 00143 #define CLIENT_REMEMBER_OPTIONS (((ulong) 1) << 31) 00144 00145 #define SERVER_STATUS_IN_TRANS 1 /* Transaction has started */ 00146 #define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */ 00147 #define SERVER_MORE_RESULTS_EXISTS 8 /* Multi query - next query exists */ 00148 #define SERVER_QUERY_NO_GOOD_INDEX_USED 16 00149 #define SERVER_QUERY_NO_INDEX_USED 32 00150 /* 00151 The server was able to fulfill the clients request and opened a 00152 read-only non-scrollable cursor for a query. This flag comes 00153 in reply to COM_STMT_EXECUTE and COM_STMT_FETCH commands. 00154 */ 00155 #define SERVER_STATUS_CURSOR_EXISTS 64 00156 /* 00157 This flag is sent when a read-only cursor is exhausted, in reply to 00158 COM_STMT_FETCH command. 00159 */ 00160 #define SERVER_STATUS_LAST_ROW_SENT 128 00161 #define SERVER_STATUS_DB_DROPPED 256 /* A database was dropped */ 00162 #define SERVER_STATUS_NO_BACKSLASH_ESCAPES 512 00163 00164 #define MYSQL_ERRMSG_SIZE 512 00165 #define NET_READ_TIMEOUT 30 /* Timeout on read */ 00166 #define NET_WRITE_TIMEOUT 60 /* Timeout on write */ 00167 #define NET_WAIT_TIMEOUT 8*60*60 /* Wait for new query */ 00168 00169 #define ONLY_KILL_QUERY 1 00170 00171 struct st_vio; /* Only C */ 00172 typedef struct st_vio Vio; 00173 00174 #define MAX_TINYINT_WIDTH 3 /* Max width for a TINY w.o. sign */ 00175 #define MAX_SMALLINT_WIDTH 5 /* Max width for a SHORT w.o. sign */ 00176 #define MAX_MEDIUMINT_WIDTH 8 /* Max width for a INT24 w.o. sign */ 00177 #define MAX_INT_WIDTH 10 /* Max width for a LONG w.o. sign */ 00178 #define MAX_BIGINT_WIDTH 20 /* Max width for a LONGLONG */ 00179 #define MAX_CHAR_WIDTH 255 /* Max length for a CHAR colum */ 00180 #define MAX_BLOB_WIDTH 8192 /* Default width for blob */ 00181 00182 typedef struct st_net { 00183 #if !defined(CHECK_EMBEDDED_DIFFERENCES) || !defined(EMBEDDED_LIBRARY) 00184 Vio* vio; 00185 unsigned char *buff,*buff_end,*write_pos,*read_pos; 00186 my_socket fd; /* For Perl DBI/dbd */ 00187 unsigned long max_packet,max_packet_size; 00188 unsigned int pkt_nr,compress_pkt_nr; 00189 unsigned int write_timeout, read_timeout, retry_count; 00190 int fcntl; 00191 my_bool compress; 00192 /* 00193 The following variable is set if we are doing several queries in one 00194 command ( as in LOAD TABLE ... FROM MASTER ), 00195 and do not want to confuse the client with OK at the wrong time 00196 */ 00197 unsigned long remain_in_buf,length, buf_length, where_b; 00198 unsigned int *return_status; 00199 unsigned char reading_or_writing; 00200 char save_char; 00201 my_bool no_send_ok; /* For SPs and other things that do multiple stmts */ 00202 my_bool no_send_eof; /* For SPs' first version read-only cursors */ 00203 /* 00204 Set if OK packet is already sent, and we do not need to send error 00205 messages 00206 */ 00207 my_bool no_send_error; 00208 /* 00209 Pointer to query object in query cache, do not equal NULL (0) for 00210 queries in cache that have not stored its results yet 00211 */ 00212 #endif 00213 char last_error[MYSQL_ERRMSG_SIZE], sqlstate[SQLSTATE_LENGTH+1]; 00214 unsigned int last_errno; 00215 unsigned char error; 00216 gptr query_cache_query; 00217 my_bool report_error; /* We should report error (we have unreported error) */ 00218 my_bool return_errno; 00219 } NET; 00220 00221 #define packet_error (~(unsigned long) 0) 00222 00223 enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY, 00224 MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG, 00225 MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE, 00226 MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP, 00227 MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24, 00228 MYSQL_TYPE_DATE, MYSQL_TYPE_TIME, 00229 MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR, 00230 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR, 00231 MYSQL_TYPE_BIT, 00232 MYSQL_TYPE_NEWDECIMAL=246, 00233 MYSQL_TYPE_ENUM=247, 00234 MYSQL_TYPE_SET=248, 00235 MYSQL_TYPE_TINY_BLOB=249, 00236 MYSQL_TYPE_MEDIUM_BLOB=250, 00237 MYSQL_TYPE_LONG_BLOB=251, 00238 MYSQL_TYPE_BLOB=252, 00239 MYSQL_TYPE_VAR_STRING=253, 00240 MYSQL_TYPE_STRING=254, 00241 MYSQL_TYPE_GEOMETRY=255 00242 00243 }; 00244 00245 /* For backward compatibility */ 00246 #define CLIENT_MULTI_QUERIES CLIENT_MULTI_STATEMENTS 00247 #define FIELD_TYPE_DECIMAL MYSQL_TYPE_DECIMAL 00248 #define FIELD_TYPE_NEWDECIMAL MYSQL_TYPE_NEWDECIMAL 00249 #define FIELD_TYPE_TINY MYSQL_TYPE_TINY 00250 #define FIELD_TYPE_SHORT MYSQL_TYPE_SHORT 00251 #define FIELD_TYPE_LONG MYSQL_TYPE_LONG 00252 #define FIELD_TYPE_FLOAT MYSQL_TYPE_FLOAT 00253 #define FIELD_TYPE_DOUBLE MYSQL_TYPE_DOUBLE 00254 #define FIELD_TYPE_NULL MYSQL_TYPE_NULL 00255 #define FIELD_TYPE_TIMESTAMP MYSQL_TYPE_TIMESTAMP 00256 #define FIELD_TYPE_LONGLONG MYSQL_TYPE_LONGLONG 00257 #define FIELD_TYPE_INT24 MYSQL_TYPE_INT24 00258 #define FIELD_TYPE_DATE MYSQL_TYPE_DATE 00259 #define FIELD_TYPE_TIME MYSQL_TYPE_TIME 00260 #define FIELD_TYPE_DATETIME MYSQL_TYPE_DATETIME 00261 #define FIELD_TYPE_YEAR MYSQL_TYPE_YEAR 00262 #define FIELD_TYPE_NEWDATE MYSQL_TYPE_NEWDATE 00263 #define FIELD_TYPE_ENUM MYSQL_TYPE_ENUM 00264 #define FIELD_TYPE_SET MYSQL_TYPE_SET 00265 #define FIELD_TYPE_TINY_BLOB MYSQL_TYPE_TINY_BLOB 00266 #define FIELD_TYPE_MEDIUM_BLOB MYSQL_TYPE_MEDIUM_BLOB 00267 #define FIELD_TYPE_LONG_BLOB MYSQL_TYPE_LONG_BLOB 00268 #define FIELD_TYPE_BLOB MYSQL_TYPE_BLOB 00269 #define FIELD_TYPE_VAR_STRING MYSQL_TYPE_VAR_STRING 00270 #define FIELD_TYPE_STRING MYSQL_TYPE_STRING 00271 #define FIELD_TYPE_CHAR MYSQL_TYPE_TINY 00272 #define FIELD_TYPE_INTERVAL MYSQL_TYPE_ENUM 00273 #define FIELD_TYPE_GEOMETRY MYSQL_TYPE_GEOMETRY 00274 #define FIELD_TYPE_BIT MYSQL_TYPE_BIT 00275 00276 00277 /* Shutdown/kill enums and constants */ 00278 00279 /* Bits for THD::killable. */ 00280 #define MYSQL_SHUTDOWN_KILLABLE_CONNECT (unsigned char)(1 << 0) 00281 #define MYSQL_SHUTDOWN_KILLABLE_TRANS (unsigned char)(1 << 1) 00282 #define MYSQL_SHUTDOWN_KILLABLE_LOCK_TABLE (unsigned char)(1 << 2) 00283 #define MYSQL_SHUTDOWN_KILLABLE_UPDATE (unsigned char)(1 << 3) 00284 00285 enum mysql_enum_shutdown_level { 00286 /* 00287 We want levels to be in growing order of hardness (because we use number 00288 comparisons). Note that DEFAULT does not respect the growing property, but 00289 it's ok. 00290 */ 00291 SHUTDOWN_DEFAULT = 0, 00292 /* wait for existing connections to finish */ 00293 SHUTDOWN_WAIT_CONNECTIONS= MYSQL_SHUTDOWN_KILLABLE_CONNECT, 00294 /* wait for existing trans to finish */ 00295 SHUTDOWN_WAIT_TRANSACTIONS= MYSQL_SHUTDOWN_KILLABLE_TRANS, 00296 /* wait for existing updates to finish (=> no partial MyISAM update) */ 00297 SHUTDOWN_WAIT_UPDATES= MYSQL_SHUTDOWN_KILLABLE_UPDATE, 00298 /* flush InnoDB buffers and other storage engines' buffers*/ 00299 SHUTDOWN_WAIT_ALL_BUFFERS= (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1), 00300 /* don't flush InnoDB buffers, flush other storage engines' buffers*/ 00301 SHUTDOWN_WAIT_CRITICAL_BUFFERS= (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1) + 1, 00302 /* Now the 2 levels of the KILL command */ 00303 #if MYSQL_VERSION_ID >= 50000 00304 KILL_QUERY= 254, 00305 #endif 00306 KILL_CONNECTION= 255 00307 }; 00308 00309 00310 enum enum_cursor_type 00311 { 00312 CURSOR_TYPE_NO_CURSOR= 0, 00313 CURSOR_TYPE_READ_ONLY= 1, 00314 CURSOR_TYPE_FOR_UPDATE= 2, 00315 CURSOR_TYPE_SCROLLABLE= 4 00316 }; 00317 00318 00319 /* options for mysql_set_option */ 00320 enum enum_mysql_set_option 00321 { 00322 MYSQL_OPTION_MULTI_STATEMENTS_ON, 00323 MYSQL_OPTION_MULTI_STATEMENTS_OFF 00324 }; 00325 00326 #define net_new_transaction(net) ((net)->pkt_nr=0) 00327 00328 #ifdef __cplusplus 00329 extern "C" { 00330 #endif 00331 00332 my_bool my_net_init(NET *net, Vio* vio); 00333 void my_net_local_init(NET *net); 00334 void net_end(NET *net); 00335 void net_clear(NET *net); 00336 my_bool net_realloc(NET *net, unsigned long length); 00337 my_bool net_flush(NET *net); 00338 my_bool my_net_write(NET *net,const char *packet,unsigned long len); 00339 my_bool net_write_command(NET *net,unsigned char command, 00340 const char *header, unsigned long head_len, 00341 const char *packet, unsigned long len); 00342 int net_real_write(NET *net,const char *packet,unsigned long len); 00343 unsigned long my_net_read(NET *net); 00344 00345 /* 00346 The following function is not meant for normal usage 00347 Currently it's used internally by manager.c 00348 */ 00349 struct sockaddr; 00350 int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen, 00351 unsigned int timeout); 00352 00353 struct rand_struct { 00354 unsigned long seed1,seed2,max_value; 00355 double max_value_dbl; 00356 }; 00357 00358 #ifdef __cplusplus 00359 } 00360 #endif 00361 00362 /* The following is for user defined functions */ 00363 00364 enum Item_result {STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT, 00365 DECIMAL_RESULT}; 00366 00367 typedef struct st_udf_args 00368 { 00369 unsigned int arg_count; /* Number of arguments */ 00370 enum Item_result *arg_type; /* Pointer to item_results */ 00371 char **args; /* Pointer to argument */ 00372 unsigned long *lengths; /* Length of string arguments */ 00373 char *maybe_null; /* Set to 1 for all maybe_null args */ 00374 char **attributes; /* Pointer to attribute name */ 00375 unsigned long *attribute_lengths; /* Length of attribute arguments */ 00376 } UDF_ARGS; 00377 00378 /* This holds information about the result */ 00379 00380 typedef struct st_udf_init 00381 { 00382 my_bool maybe_null; /* 1 if function can return NULL */ 00383 unsigned int decimals; /* for real functions */ 00384 unsigned long max_length; /* For string functions */ 00385 char *ptr; /* free pointer for function data */ 00386 my_bool const_item; /* 0 if result is independent of arguments */ 00387 } UDF_INIT; 00388 00389 /* Constants when using compression */ 00390 #define NET_HEADER_SIZE 4 /* standard header size */ 00391 #define COMP_HEADER_SIZE 3 /* compression header extra size */ 00392 00393 /* Prototypes to password functions */ 00394 00395 #ifdef __cplusplus 00396 extern "C" { 00397 #endif 00398 00399 /* 00400 These functions are used for authentication by client and server and 00401 implemented in sql/password.c 00402 */ 00403 00404 void randominit(struct rand_struct *, unsigned long seed1, 00405 unsigned long seed2); 00406 double my_rnd(struct rand_struct *); 00407 void create_random_string(char *to, unsigned int length, struct rand_struct *rand_st); 00408 00409 void hash_password(unsigned long *to, const char *password, unsigned int password_len); 00410 void make_scrambled_password_323(char *to, const char *password); 00411 void scramble_323(char *to, const char *message, const char *password); 00412 my_bool check_scramble_323(const char *, const char *message, 00413 unsigned long *salt); 00414 void get_salt_from_password_323(unsigned long *res, const char *password); 00415 void make_password_from_salt_323(char *to, const unsigned long *salt); 00416 00417 void make_scrambled_password(char *to, const char *password); 00418 void scramble(char *to, const char *message, const char *password); 00419 my_bool check_scramble(const char *reply, const char *message, 00420 const unsigned char *hash_stage2); 00421 void get_salt_from_password(unsigned char *res, const char *password); 00422 void make_password_from_salt(char *to, const unsigned char *hash_stage2); 00423 char *octet2hex(char *to, const char *str, unsigned int len); 00424 00425 /* end of password.c */ 00426 00427 char *get_tty_password(const char *opt_message); 00428 const char *mysql_errno_to_sqlstate(unsigned int mysql_errno); 00429 00430 /* Some other useful functions */ 00431 00432 my_bool my_thread_init(void); 00433 void my_thread_end(void); 00434 00435 #ifdef _global_h 00436 ulong STDCALL net_field_length(uchar **packet); 00437 my_ulonglong net_field_length_ll(uchar **packet); 00438 char *net_store_length(char *pkg, ulonglong length); 00439 #endif 00440 00441 #ifdef __cplusplus 00442 } 00443 #endif 00444 00445 #define NULL_LENGTH ((unsigned long) ~0) /* For net_store_length */ 00446 #define MYSQL_STMT_HEADER 4 00447 #define MYSQL_LONG_DATA_HEADER 6 00448 00449 #endif
1.4.7

