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