Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

239 lines
8.5 KiB

  1. /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  2. This library is free software; you can redistribute it and/or
  3. modify it under the terms of the GNU Library General Public
  4. License as published by the Free Software Foundation; either
  5. version 2 of the License, or (at your option) any later version.
  6. This library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9. Library General Public License for more details.
  10. You should have received a copy of the GNU Library General Public
  11. License along with this library; if not, write to the Free
  12. Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  13. MA 02111-1307, USA */
  14. /*
  15. ** Common definition between mysql server & client
  16. */
  17. #ifndef _mysql_com_h
  18. #define _mysql_com_h
  19. #define NAME_LEN 64 /* Field/table name length */
  20. #define HOSTNAME_LENGTH 60
  21. #define USERNAME_LENGTH 16
  22. #define SERVER_VERSION_LENGTH 60
  23. #define LOCAL_HOST "localhost"
  24. #define LOCAL_HOST_NAMEDPIPE "."
  25. #if defined(__WIN__) && !defined( _CUSTOMCONFIG_)
  26. #define MYSQL_NAMEDPIPE "MySQL"
  27. #define MYSQL_SERVICENAME "MySql"
  28. #endif /* __WIN__ */
  29. enum enum_server_command {COM_SLEEP,COM_QUIT,COM_INIT_DB,COM_QUERY,
  30. COM_FIELD_LIST,COM_CREATE_DB,COM_DROP_DB,COM_REFRESH,
  31. COM_SHUTDOWN,COM_STATISTICS,
  32. COM_PROCESS_INFO,COM_CONNECT,COM_PROCESS_KILL,
  33. COM_DEBUG,COM_PING,COM_TIME,COM_DELAYED_INSERT,
  34. COM_CHANGE_USER, COM_BINLOG_DUMP,
  35. COM_TABLE_DUMP, COM_CONNECT_OUT};
  36. #define NOT_NULL_FLAG 1 /* Field can't be NULL */
  37. #define PRI_KEY_FLAG 2 /* Field is part of a primary key */
  38. #define UNIQUE_KEY_FLAG 4 /* Field is part of a unique key */
  39. #define MULTIPLE_KEY_FLAG 8 /* Field is part of a key */
  40. #define BLOB_FLAG 16 /* Field is a blob */
  41. #define UNSIGNED_FLAG 32 /* Field is unsigned */
  42. #define ZEROFILL_FLAG 64 /* Field is zerofill */
  43. #define BINARY_FLAG 128
  44. /* The following are only sent to new clients */
  45. #define ENUM_FLAG 256 /* field is an enum */
  46. #define AUTO_INCREMENT_FLAG 512 /* field is a autoincrement field */
  47. #define TIMESTAMP_FLAG 1024 /* Field is a timestamp */
  48. #define SET_FLAG 2048 /* field is a set */
  49. #define NUM_FLAG 32768 /* Field is num (for clients) */
  50. #define PART_KEY_FLAG 16384 /* Intern; Part of some key */
  51. #define GROUP_FLAG 32768 /* Intern: Group field */
  52. #define UNIQUE_FLAG 65536 /* Intern: Used by sql_yacc */
  53. #define REFRESH_GRANT 1 /* Refresh grant tables */
  54. #define REFRESH_LOG 2 /* Start on new log file */
  55. #define REFRESH_TABLES 4 /* close all tables */
  56. #define REFRESH_HOSTS 8 /* Flush host cache */
  57. #define REFRESH_STATUS 16 /* Flush status variables */
  58. #define REFRESH_THREADS 32 /* Flush thread cache */
  59. #define REFRESH_SLAVE 64 /* Reset master info and restart slave
  60. thread */
  61. #define REFRESH_MASTER 128 /* Remove all bin logs in the index
  62. and truncate the index */
  63. /* The following can't be set with mysql_refresh() */
  64. #define REFRESH_READ_LOCK 16384 /* Lock tables for read */
  65. #define REFRESH_FAST 32768 /* Intern flag */
  66. #define CLIENT_LONG_PASSWORD 1 /* new more secure passwords */
  67. #define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */
  68. #define CLIENT_LONG_FLAG 4 /* Get all column flags */
  69. #define CLIENT_CONNECT_WITH_DB 8 /* One can specify db on connect */
  70. #define CLIENT_NO_SCHEMA 16 /* Don't allow database.table.column */
  71. #define CLIENT_COMPRESS 32 /* Can use compression protocol */
  72. #define CLIENT_ODBC 64 /* Odbc client */
  73. #define CLIENT_LOCAL_FILES 128 /* Can use LOAD DATA LOCAL */
  74. #define CLIENT_IGNORE_SPACE 256 /* Ignore spaces before '(' */
  75. #define CLIENT_CHANGE_USER 512 /* Support the mysql_change_user() */
  76. #define CLIENT_INTERACTIVE 1024 /* This is an interactive client */
  77. #define CLIENT_SSL 2048 /* Switch to SSL after handshake */
  78. #define CLIENT_IGNORE_SIGPIPE 4096 /* IGNORE sigpipes */
  79. #define CLIENT_TRANSACTIONS 8192 /* Client knows about transactions */
  80. #define SERVER_STATUS_IN_TRANS 1 /* Transaction has started */
  81. #define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */
  82. #define MYSQL_ERRMSG_SIZE 200
  83. #define NET_READ_TIMEOUT 30 /* Timeout on read */
  84. #define NET_WRITE_TIMEOUT 60 /* Timeout on write */
  85. #define NET_WAIT_TIMEOUT 8*60*60 /* Wait for new query */
  86. #ifndef Vio_defined
  87. #define Vio_defined
  88. #ifdef HAVE_VIO
  89. class Vio; /* Fill Vio class in C++ */
  90. #else
  91. struct st_vio; /* Only C */
  92. typedef struct st_vio Vio;
  93. #endif
  94. #endif
  95. #define MAX_CHAR_WIDTH 255 /* Max length for a CHAR colum */
  96. #define MAX_BLOB_WIDTH 8192 /* Default width for blob */
  97. typedef struct st_net {
  98. Vio* vio;
  99. my_socket fd; /* For Perl DBI/dbd */
  100. int fcntl;
  101. unsigned char *buff,*buff_end,*write_pos,*read_pos;
  102. char last_error[MYSQL_ERRMSG_SIZE];
  103. unsigned int last_errno,max_packet,timeout,pkt_nr;
  104. unsigned char error;
  105. my_bool return_errno,compress;
  106. my_bool no_send_ok; /* needed if we are doing several
  107. queries in one command ( as in LOAD TABLE ... FROM MASTER ),
  108. and do not want to confuse the client with OK at the wrong time
  109. */
  110. unsigned long remain_in_buf,length, buf_length, where_b;
  111. unsigned int *return_status;
  112. unsigned char reading_or_writing;
  113. char save_char;
  114. } NET;
  115. #define packet_error ((unsigned int) -1)
  116. enum enum_field_types { FIELD_TYPE_DECIMAL, FIELD_TYPE_TINY,
  117. FIELD_TYPE_SHORT, FIELD_TYPE_LONG,
  118. FIELD_TYPE_FLOAT, FIELD_TYPE_DOUBLE,
  119. FIELD_TYPE_NULL, FIELD_TYPE_TIMESTAMP,
  120. FIELD_TYPE_LONGLONG,FIELD_TYPE_INT24,
  121. FIELD_TYPE_DATE, FIELD_TYPE_TIME,
  122. FIELD_TYPE_DATETIME, FIELD_TYPE_YEAR,
  123. FIELD_TYPE_NEWDATE,
  124. FIELD_TYPE_ENUM=247,
  125. FIELD_TYPE_SET=248,
  126. FIELD_TYPE_TINY_BLOB=249,
  127. FIELD_TYPE_MEDIUM_BLOB=250,
  128. FIELD_TYPE_LONG_BLOB=251,
  129. FIELD_TYPE_BLOB=252,
  130. FIELD_TYPE_VAR_STRING=253,
  131. FIELD_TYPE_STRING=254
  132. };
  133. #define FIELD_TYPE_CHAR FIELD_TYPE_TINY /* For compability */
  134. #define FIELD_TYPE_INTERVAL FIELD_TYPE_ENUM /* For compability */
  135. extern unsigned long max_allowed_packet;
  136. extern unsigned long net_buffer_length;
  137. #define net_new_transaction(net) ((net)->pkt_nr=0)
  138. int my_net_init(NET *net, Vio* vio);
  139. void net_end(NET *net);
  140. void net_clear(NET *net);
  141. int net_flush(NET *net);
  142. int my_net_write(NET *net,const char *packet,unsigned long len);
  143. int net_write_command(NET *net,unsigned char command,const char *packet,
  144. unsigned long len);
  145. int net_real_write(NET *net,const char *packet,unsigned long len);
  146. unsigned int my_net_read(NET *net);
  147. struct rand_struct {
  148. unsigned long seed1,seed2,max_value;
  149. double max_value_dbl;
  150. };
  151. /* The following is for user defined functions */
  152. enum Item_result {STRING_RESULT,REAL_RESULT,INT_RESULT};
  153. typedef struct st_udf_args
  154. {
  155. unsigned int arg_count; /* Number of arguments */
  156. enum Item_result *arg_type; /* Pointer to item_results */
  157. char **args; /* Pointer to argument */
  158. unsigned long *lengths; /* Length of string arguments */
  159. char *maybe_null; /* Set to 1 for all maybe_null args */
  160. } UDF_ARGS;
  161. /* This holds information about the result */
  162. typedef struct st_udf_init
  163. {
  164. my_bool maybe_null; /* 1 if function can return NULL */
  165. unsigned int decimals; /* for real functions */
  166. unsigned int max_length; /* For string functions */
  167. char *ptr; /* free pointer for function data */
  168. my_bool const_item; /* 0 if result is independent of arguments */
  169. } UDF_INIT;
  170. /* Constants when using compression */
  171. #define NET_HEADER_SIZE 4 /* standard header size */
  172. #define COMP_HEADER_SIZE 3 /* compression header extra size */
  173. /* Prototypes to password functions */
  174. #ifdef __cplusplus
  175. extern "C" {
  176. #endif
  177. void randominit(struct rand_struct *,unsigned long seed1,
  178. unsigned long seed2);
  179. double rnd(struct rand_struct *);
  180. void make_scrambled_password(char *to,const char *password);
  181. void get_salt_from_password(unsigned long *res,const char *password);
  182. void make_password_from_salt(char *to, unsigned long *hash_res);
  183. char *scramble(char *to,const char *message,const char *password,
  184. my_bool old_ver);
  185. my_bool check_scramble(const char *, const char *message,
  186. unsigned long *salt,my_bool old_ver);
  187. char *get_tty_password(char *opt_message);
  188. void hash_password(unsigned long *result, const char *password);
  189. /* Some other useful functions */
  190. void my_init(void);
  191. void load_defaults(const char *conf_file, const char **groups,
  192. int *argc, char ***argv);
  193. my_bool my_thread_init(void);
  194. void my_thread_end(void);
  195. #ifdef __cplusplus
  196. }
  197. #endif
  198. #define NULL_LENGTH ((unsigned long) ~0) /* For net_store_length */
  199. #endif