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