home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / mySQL / mysql-5.0.1-alpha-snapshot-win / data1.cab / Development / include / mysql_com.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-07-28  |  14.3 KB  |  393 lines

  1. /* Copyright (C) 2000 MySQL AB
  2.  
  3.    This program is free software; you can redistribute it and/or modify
  4.    it under the terms of the GNU General Public License as published by
  5.    the Free Software Foundation; either version 2 of the License, or
  6.    (at your option) any later version.
  7.  
  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU General Public License
  14.    along with this program; if not, write to the Free Software
  15.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  16.  
  17. /*
  18. ** Common definition between mysql server & client
  19. */
  20.  
  21. #ifndef _mysql_com_h
  22. #define _mysql_com_h
  23.  
  24. #define NAME_LEN    64        /* Field/table name length */
  25. #define HOSTNAME_LENGTH 60
  26. #define USERNAME_LENGTH 16
  27. #define SERVER_VERSION_LENGTH 60
  28. #define SQLSTATE_LENGTH 5
  29.  
  30. #define LOCAL_HOST    "localhost"
  31. #define LOCAL_HOST_NAMEDPIPE "."
  32.  
  33.  
  34. #if defined(__WIN__) && !defined( _CUSTOMCONFIG_)
  35. #define MYSQL_NAMEDPIPE "MySQL"
  36. #define MYSQL_SERVICENAME "MySQL"
  37. #endif /* __WIN__ */
  38.  
  39. enum enum_server_command
  40. {
  41.   COM_SLEEP, COM_QUIT, COM_INIT_DB, COM_QUERY, COM_FIELD_LIST,
  42.   COM_CREATE_DB, COM_DROP_DB, COM_REFRESH, COM_SHUTDOWN, COM_STATISTICS,
  43.   COM_PROCESS_INFO, COM_CONNECT, COM_PROCESS_KILL, COM_DEBUG, COM_PING,
  44.   COM_TIME, COM_DELAYED_INSERT, COM_CHANGE_USER, COM_BINLOG_DUMP,
  45.   COM_TABLE_DUMP, COM_CONNECT_OUT, COM_REGISTER_SLAVE,
  46.   COM_PREPARE, COM_EXECUTE, COM_LONG_DATA, COM_CLOSE_STMT,
  47.   COM_RESET_STMT, COM_SET_OPTION,
  48.   COM_END                /* Must be last */
  49. };
  50.  
  51.  
  52. /*
  53.   Length of random string sent by server on handshake; this is also length of
  54.   obfuscated password, recieved from client 
  55. */
  56. #define SCRAMBLE_LENGTH 20
  57. #define SCRAMBLE_LENGTH_323 8
  58. /* length of password stored in the db: new passwords are preceeded with '*' */
  59. #define SCRAMBLED_PASSWORD_CHAR_LENGTH (SCRAMBLE_LENGTH*2+1)
  60. #define SCRAMBLED_PASSWORD_CHAR_LENGTH_323 (SCRAMBLE_LENGTH_323*2)
  61.  
  62.  
  63. #define NOT_NULL_FLAG    1        /* Field can't be NULL */
  64. #define PRI_KEY_FLAG    2        /* Field is part of a primary key */
  65. #define UNIQUE_KEY_FLAG 4        /* Field is part of a unique key */
  66. #define MULTIPLE_KEY_FLAG 8        /* Field is part of a key */
  67. #define BLOB_FLAG    16        /* Field is a blob */
  68. #define UNSIGNED_FLAG    32        /* Field is unsigned */
  69. #define ZEROFILL_FLAG    64        /* Field is zerofill */
  70. #define BINARY_FLAG    128        /* Field is binary   */
  71.  
  72. /* The following are only sent to new clients */
  73. #define ENUM_FLAG    256        /* field is an enum */
  74. #define AUTO_INCREMENT_FLAG 512        /* field is a autoincrement field */
  75. #define TIMESTAMP_FLAG    1024        /* Field is a timestamp */
  76. #define SET_FLAG    2048        /* field is a set */
  77. #define NUM_FLAG    32768        /* Field is num (for clients) */
  78. #define PART_KEY_FLAG    16384        /* Intern; Part of some key */
  79. #define GROUP_FLAG    32768        /* Intern: Group field */
  80. #define UNIQUE_FLAG    65536        /* Intern: Used by sql_yacc */
  81. #define BINCMP_FLAG    131072        /* Intern: Used by sql_yacc */
  82.  
  83. #define REFRESH_GRANT        1    /* Refresh grant tables */
  84. #define REFRESH_LOG        2    /* Start on new log file */
  85. #define REFRESH_TABLES        4    /* close all tables */
  86. #define REFRESH_HOSTS        8    /* Flush host cache */
  87. #define REFRESH_STATUS        16    /* Flush status variables */
  88. #define REFRESH_THREADS        32    /* Flush thread cache */
  89. #define REFRESH_SLAVE           64      /* Reset master info and restart slave
  90.                        thread */
  91. #define REFRESH_MASTER          128     /* Remove all bin logs in the index
  92.                        and truncate the index */
  93.  
  94. /* The following can't be set with mysql_refresh() */
  95. #define REFRESH_READ_LOCK    16384    /* Lock tables for read */
  96. #define REFRESH_FAST        32768    /* Intern flag */
  97.  
  98. /* RESET (remove all queries) from query cache */
  99. #define REFRESH_QUERY_CACHE    65536
  100. #define REFRESH_QUERY_CACHE_FREE 0x20000L /* pack query cache */
  101. #define REFRESH_DES_KEY_FILE    0x40000L
  102. #define REFRESH_USER_RESOURCES    0x80000L
  103.  
  104. #define CLIENT_LONG_PASSWORD    1    /* new more secure passwords */
  105. #define CLIENT_FOUND_ROWS    2    /* Found instead of affected rows */
  106. #define CLIENT_LONG_FLAG    4    /* Get all column flags */
  107. #define CLIENT_CONNECT_WITH_DB    8    /* One can specify db on connect */
  108. #define CLIENT_NO_SCHEMA    16    /* Don't allow database.table.column */
  109. #define CLIENT_COMPRESS        32    /* Can use compression protocol */
  110. #define CLIENT_ODBC        64    /* Odbc client */
  111. #define CLIENT_LOCAL_FILES    128    /* Can use LOAD DATA LOCAL */
  112. #define CLIENT_IGNORE_SPACE    256    /* Ignore spaces before '(' */
  113. #define CLIENT_PROTOCOL_41    512    /* New 4.1 protocol */
  114. #define CLIENT_INTERACTIVE    1024    /* This is an interactive client */
  115. #define CLIENT_SSL              2048    /* Switch to SSL after handshake */
  116. #define CLIENT_IGNORE_SIGPIPE   4096    /* IGNORE sigpipes */
  117. #define CLIENT_TRANSACTIONS    8192    /* Client knows about transactions */
  118. #define CLIENT_RESERVED         16384   /* Old flag for 4.1 protocol  */
  119. #define CLIENT_SECURE_CONNECTION 32768  /* New 4.1 authentication */
  120. #define CLIENT_MULTI_STATEMENTS 65536   /* Enable/disable multi-stmt support */
  121. #define CLIENT_MULTI_RESULTS    131072  /* Enable/disable multi-results */
  122. #define CLIENT_REMEMBER_OPTIONS    (((ulong) 1) << 31)
  123.  
  124. #define SERVER_STATUS_IN_TRANS     1    /* Transaction has started */
  125. #define SERVER_STATUS_AUTOCOMMIT   2    /* Server in auto_commit mode */
  126. #define SERVER_STATUS_MORE_RESULTS 4    /* More results on server */
  127. #define SERVER_MORE_RESULTS_EXISTS 8    /* Multi query - next query exists */
  128. #define SERVER_QUERY_NO_GOOD_INDEX_USED 16
  129. #define SERVER_QUERY_NO_INDEX_USED      32
  130.  
  131. #define MYSQL_ERRMSG_SIZE    512
  132. #define NET_READ_TIMEOUT    30        /* Timeout on read */
  133. #define NET_WRITE_TIMEOUT    60        /* Timeout on write */
  134. #define NET_WAIT_TIMEOUT    8*60*60        /* Wait for new query */
  135.  
  136. #define ONLY_KILL_QUERY         1
  137.  
  138. struct st_vio;                    /* Only C */
  139. typedef struct st_vio Vio;
  140.  
  141. #define MAX_CHAR_WIDTH        255    /* Max length for a CHAR colum */
  142. #define MAX_BLOB_WIDTH        8192    /* Default width for blob */
  143.  
  144. typedef struct st_net {
  145. #if !defined(CHECK_EMBEDDED_DIFFERENCES) || !defined(EMBEDDED_LIBRARY)
  146.   Vio* vio;
  147.   unsigned char *buff,*buff_end,*write_pos,*read_pos;
  148.   my_socket fd;                    /* For Perl DBI/dbd */
  149.   unsigned long max_packet,max_packet_size;
  150.   unsigned int pkt_nr,compress_pkt_nr;
  151.   unsigned int write_timeout, read_timeout, retry_count;
  152.   int fcntl;
  153.   my_bool compress;
  154.   /*
  155.     The following variable is set if we are doing several queries in one
  156.     command ( as in LOAD TABLE ... FROM MASTER ),
  157.     and do not want to confuse the client with OK at the wrong time
  158.   */
  159.   unsigned long remain_in_buf,length, buf_length, where_b;
  160.   unsigned int *return_status;
  161.   unsigned char reading_or_writing;
  162.   char save_char;
  163.   my_bool no_send_ok;  /* For SPs and other things that do multiple stmts */
  164.   my_bool no_send_eof; /* For SPs' first version read-only cursors */
  165.   /*
  166.     Pointer to query object in query cache, do not equal NULL (0) for
  167.     queries in cache that have not stored its results yet
  168.   */
  169. #endif
  170.   char last_error[MYSQL_ERRMSG_SIZE], sqlstate[SQLSTATE_LENGTH+1];
  171.   unsigned int last_errno;
  172.   unsigned char error;
  173.   gptr query_cache_query;
  174.   my_bool report_error; /* We should report error (we have unreported error) */
  175.   my_bool return_errno;
  176. } NET;
  177.  
  178. #define packet_error (~(unsigned long) 0)
  179.  
  180. enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,
  181.             MYSQL_TYPE_SHORT,  MYSQL_TYPE_LONG,
  182.             MYSQL_TYPE_FLOAT,  MYSQL_TYPE_DOUBLE,
  183.             MYSQL_TYPE_NULL,   MYSQL_TYPE_TIMESTAMP,
  184.             MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24,
  185.             MYSQL_TYPE_DATE,   MYSQL_TYPE_TIME,
  186.             MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
  187.             MYSQL_TYPE_NEWDATE,
  188.             MYSQL_TYPE_ENUM=247,
  189.             MYSQL_TYPE_SET=248,
  190.             MYSQL_TYPE_TINY_BLOB=249,
  191.             MYSQL_TYPE_MEDIUM_BLOB=250,
  192.             MYSQL_TYPE_LONG_BLOB=251,
  193.             MYSQL_TYPE_BLOB=252,
  194.             MYSQL_TYPE_VAR_STRING=253,
  195.             MYSQL_TYPE_STRING=254,
  196.             MYSQL_TYPE_GEOMETRY=255
  197.  
  198. };
  199.  
  200. /* For backward compatibility */
  201. #define CLIENT_MULTI_QUERIES    CLIENT_MULTI_STATEMENTS    
  202. #define FIELD_TYPE_DECIMAL     MYSQL_TYPE_DECIMAL
  203. #define FIELD_TYPE_TINY        MYSQL_TYPE_TINY
  204. #define FIELD_TYPE_SHORT       MYSQL_TYPE_SHORT
  205. #define FIELD_TYPE_LONG        MYSQL_TYPE_LONG
  206. #define FIELD_TYPE_FLOAT       MYSQL_TYPE_FLOAT
  207. #define FIELD_TYPE_DOUBLE      MYSQL_TYPE_DOUBLE
  208. #define FIELD_TYPE_NULL        MYSQL_TYPE_NULL
  209. #define FIELD_TYPE_TIMESTAMP   MYSQL_TYPE_TIMESTAMP
  210. #define FIELD_TYPE_LONGLONG    MYSQL_TYPE_LONGLONG
  211. #define FIELD_TYPE_INT24       MYSQL_TYPE_INT24
  212. #define FIELD_TYPE_DATE        MYSQL_TYPE_DATE
  213. #define FIELD_TYPE_TIME        MYSQL_TYPE_TIME
  214. #define FIELD_TYPE_DATETIME    MYSQL_TYPE_DATETIME
  215. #define FIELD_TYPE_YEAR        MYSQL_TYPE_YEAR
  216. #define FIELD_TYPE_NEWDATE     MYSQL_TYPE_NEWDATE
  217. #define FIELD_TYPE_ENUM        MYSQL_TYPE_ENUM
  218. #define FIELD_TYPE_SET         MYSQL_TYPE_SET
  219. #define FIELD_TYPE_TINY_BLOB   MYSQL_TYPE_TINY_BLOB
  220. #define FIELD_TYPE_MEDIUM_BLOB MYSQL_TYPE_MEDIUM_BLOB
  221. #define FIELD_TYPE_LONG_BLOB   MYSQL_TYPE_LONG_BLOB
  222. #define FIELD_TYPE_BLOB        MYSQL_TYPE_BLOB
  223. #define FIELD_TYPE_VAR_STRING  MYSQL_TYPE_VAR_STRING
  224. #define FIELD_TYPE_STRING      MYSQL_TYPE_STRING
  225. #define FIELD_TYPE_CHAR        MYSQL_TYPE_TINY
  226. #define FIELD_TYPE_INTERVAL    MYSQL_TYPE_ENUM
  227. #define FIELD_TYPE_GEOMETRY    MYSQL_TYPE_GEOMETRY
  228.  
  229. enum enum_shutdown_level {
  230.   /*
  231.     We want levels to be in growing order of hardness. So we leave room
  232.     for future intermediate levels. For now, escalating one level is += 10;
  233.     later if we insert new levels in between we will need a function
  234.     next_shutdown_level(level). Note that DEFAULT does not respect the
  235.     growing property.
  236.   */
  237.   SHUTDOWN_DEFAULT= 0, /* mapped to WAIT_ALL_BUFFERS for now */
  238.   /*
  239.     Here is the list in growing order (the next does the previous plus
  240.     something). WAIT_ALL_BUFFERS is what we have now. Others are "this MySQL
  241.     server does not support this shutdown level yet".
  242.   */
  243.   SHUTDOWN_WAIT_CONNECTIONS= 10, /* wait for existing connections to finish */
  244.   SHUTDOWN_WAIT_TRANSACTIONS= 20, /* wait for existing trans to finish */
  245.   SHUTDOWN_WAIT_STATEMENTS= 30, /* wait for existing updating stmts to finish */
  246.   SHUTDOWN_WAIT_ALL_BUFFERS= 40, /* flush InnoDB buffers */
  247.   SHUTDOWN_WAIT_CRITICAL_BUFFERS= 50, /* flush MyISAM buffs (no corruption) */
  248.   /* Now the 2 levels of the KILL command */
  249. #if MYSQL_VERSION_ID >= 50000
  250.   KILL_QUERY= 254,
  251. #endif
  252.   KILL_CONNECTION= 255
  253. };
  254.  
  255. /* options for mysql_set_option */
  256. enum enum_mysql_set_option
  257. {
  258.   MYSQL_OPTION_MULTI_STATEMENTS_ON,
  259.   MYSQL_OPTION_MULTI_STATEMENTS_OFF
  260. };
  261.  
  262. #define net_new_transaction(net) ((net)->pkt_nr=0)
  263.  
  264. #ifdef __cplusplus
  265. extern "C" {
  266. #endif
  267.  
  268. my_bool    my_net_init(NET *net, Vio* vio);
  269. void    my_net_local_init(NET *net);
  270. void    net_end(NET *net);
  271. void    net_clear(NET *net);
  272. my_bool net_realloc(NET *net, unsigned long length);
  273.  
  274. #ifndef EMBEDDED_LIBRARY /* To be removed by HF */
  275. my_bool    net_flush(NET *net);
  276. #else
  277. #define net_flush(A)
  278. #endif
  279.  
  280. my_bool    my_net_write(NET *net,const char *packet,unsigned long len);
  281. my_bool    net_write_command(NET *net,unsigned char command,
  282.               const char *header, unsigned long head_len,
  283.               const char *packet, unsigned long len);
  284. int    net_real_write(NET *net,const char *packet,unsigned long len);
  285. unsigned long my_net_read(NET *net);
  286.  
  287. /*
  288.   The following function is not meant for normal usage
  289.   Currently it's used internally by manager.c
  290. */
  291. struct sockaddr;
  292. int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen,
  293.            unsigned int timeout);
  294.  
  295. struct rand_struct {
  296.   unsigned long seed1,seed2,max_value;
  297.   double max_value_dbl;
  298. };
  299.  
  300. #ifdef __cplusplus
  301. }
  302. #endif
  303.  
  304.   /* The following is for user defined functions */
  305.  
  306. enum Item_result {STRING_RESULT, REAL_RESULT, INT_RESULT, ROW_RESULT};
  307.  
  308. typedef struct st_udf_args
  309. {
  310.   unsigned int arg_count;        /* Number of arguments */
  311.   enum Item_result *arg_type;        /* Pointer to item_results */
  312.   char **args;                /* Pointer to argument */
  313.   unsigned long *lengths;        /* Length of string arguments */
  314.   char *maybe_null;            /* Set to 1 for all maybe_null args */
  315.   char **attributes;                    /* Pointer to attribute name */
  316.   unsigned long *attribute_lengths;     /* Length of attribute arguments */
  317. } UDF_ARGS;
  318.  
  319.   /* This holds information about the result */
  320.  
  321. typedef struct st_udf_init
  322. {
  323.   my_bool maybe_null;            /* 1 if function can return NULL */
  324.   unsigned int decimals;        /* for real functions */
  325.   unsigned long max_length;        /* For string functions */
  326.   char      *ptr;                /* free pointer for function data */
  327.   my_bool const_item;            /* 0 if result is independent of arguments */
  328. } UDF_INIT;
  329.  
  330.   /* Constants when using compression */
  331. #define NET_HEADER_SIZE 4        /* standard header size */
  332. #define COMP_HEADER_SIZE 3        /* compression header extra size */
  333.  
  334.   /* Prototypes to password functions */
  335.  
  336. #ifdef __cplusplus
  337. extern "C" {
  338. #endif
  339.  
  340. /*
  341.   These functions are used for authentication by client and server and
  342.   implemented in sql/password.c
  343. */
  344.  
  345. void randominit(struct rand_struct *, unsigned long seed1,
  346.                 unsigned long seed2);
  347. double my_rnd(struct rand_struct *);
  348. void create_random_string(char *to, unsigned int length, struct rand_struct *rand_st);
  349.  
  350. void hash_password(unsigned long *to, const char *password, unsigned int password_len);
  351. void make_scrambled_password_323(char *to, const char *password);
  352. void scramble_323(char *to, const char *message, const char *password);
  353. my_bool check_scramble_323(const char *, const char *message,
  354.                            unsigned long *salt);
  355. void get_salt_from_password_323(unsigned long *res, const char *password);
  356. void make_password_from_salt_323(char *to, const unsigned long *salt);
  357.  
  358. void make_scrambled_password(char *to, const char *password);
  359. void scramble(char *to, const char *message, const char *password);
  360. my_bool check_scramble(const char *reply, const char *message,
  361.                        const unsigned char *hash_stage2);
  362. void get_salt_from_password(unsigned char *res, const char *password);
  363. void make_password_from_salt(char *to, const unsigned char *hash_stage2);
  364.  
  365. /* end of password.c */
  366.  
  367. char *get_tty_password(char *opt_message);
  368. const char *mysql_errno_to_sqlstate(unsigned int mysql_errno);
  369.  
  370. /* Some other useful functions */
  371.  
  372. my_bool my_init(void);
  373. int load_defaults(const char *conf_file, const char **groups,
  374.           int *argc, char ***argv);
  375. my_bool my_thread_init(void);
  376. void my_thread_end(void);
  377.  
  378. #ifdef _global_h
  379. ulong STDCALL net_field_length(uchar **packet);
  380. my_ulonglong net_field_length_ll(uchar **packet);
  381. char *net_store_length(char *pkg, ulonglong length);
  382. #endif
  383.  
  384. #ifdef __cplusplus
  385. }
  386. #endif
  387.  
  388. #define NULL_LENGTH ((unsigned long) ~0) /* For net_store_length */
  389. #define MYSQL_STMT_HEADER       4
  390. #define MYSQL_LONG_DATA_HEADER  6
  391.  
  392. #endif
  393.