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