mysql_com.h 9.14 KB
Newer Older
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1 2 3 4 5 6 7 8
/* Copyright (C) 2000 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
10 11 12 13 14 15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
16 17 18 19 20 21 22 23 24 25 26

/*
** Common definition between mysql server & client
*/

#ifndef _mysql_com_h
#define _mysql_com_h

#define NAME_LEN	64		/* Field/table name length */
#define HOSTNAME_LENGTH 60
#define USERNAME_LENGTH 16
27
#define SERVER_VERSION_LENGTH 60
bk@work.mysql.com's avatar
bk@work.mysql.com committed
28 29 30 31 32 33

#define LOCAL_HOST	"localhost"
#define LOCAL_HOST_NAMEDPIPE "."

#if defined(__WIN__) && !defined( _CUSTOMCONFIG_)
#define MYSQL_NAMEDPIPE "MySQL"
34
#define MYSQL_SERVICENAME "MySQL"
bk@work.mysql.com's avatar
bk@work.mysql.com committed
35 36
#endif /* __WIN__ */

37 38 39 40 41 42
#if defined(__WIN__) && !defined(MYSQL_SERVER) && !defined(MYSQL_CLIENT) && !defined(EMBEDDED_LIBRARY)
#define dll_import_spec __declspec( dllimport )
#else
#define dll_import_spec
#endif

43 44 45 46 47 48 49 50
enum enum_server_command {
  COM_SLEEP, COM_QUIT, COM_INIT_DB, COM_QUERY, COM_FIELD_LIST,
  COM_CREATE_DB, COM_DROP_DB, COM_REFRESH, COM_SHUTDOWN,  COM_STATISTICS,
  COM_PROCESS_INFO, COM_CONNECT, COM_PROCESS_KILL, COM_DEBUG, COM_PING,
  COM_TIME, COM_DELAYED_INSERT, COM_CHANGE_USER, COM_BINLOG_DUMP,
  COM_TABLE_DUMP,  COM_CONNECT_OUT, COM_REGISTER_SLAVE,
  COM_END					/* Must be last! */
};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64

#define NOT_NULL_FLAG	1		/* Field can't be NULL */
#define PRI_KEY_FLAG	2		/* Field is part of a primary key */
#define UNIQUE_KEY_FLAG 4		/* Field is part of a unique key */
#define MULTIPLE_KEY_FLAG 8		/* Field is part of a key */
#define BLOB_FLAG	16		/* Field is a blob */
#define UNSIGNED_FLAG	32		/* Field is unsigned */
#define ZEROFILL_FLAG	64		/* Field is zerofill */
#define BINARY_FLAG	128
/* The following are only sent to new clients */
#define ENUM_FLAG	256		/* field is an enum */
#define AUTO_INCREMENT_FLAG 512		/* field is a autoincrement field */
#define TIMESTAMP_FLAG	1024		/* Field is a timestamp */
#define SET_FLAG	2048		/* field is a set */
65
#define NUM_FLAG	32768		/* Field is num (for clients) */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
66 67 68 69 70 71 72 73 74
#define PART_KEY_FLAG	16384		/* Intern; Part of some key */
#define GROUP_FLAG	32768		/* Intern: Group field */
#define UNIQUE_FLAG	65536		/* Intern: Used by sql_yacc */

#define REFRESH_GRANT		1	/* Refresh grant tables */
#define REFRESH_LOG		2	/* Start on new log file */
#define REFRESH_TABLES		4	/* close all tables */
#define REFRESH_HOSTS		8	/* Flush host cache */
#define REFRESH_STATUS		16	/* Flush status variables */
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
75
#define REFRESH_THREADS		32	/* Flush thread cache */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
76 77 78 79 80 81 82 83 84
#define REFRESH_SLAVE           64      /* Reset master info and restart slave
					   thread */
#define REFRESH_MASTER          128     /* Remove all bin logs in the index
					   and truncate the index */

/* The following can't be set with mysql_refresh() */
#define REFRESH_READ_LOCK	16384	/* Lock tables for read */
#define REFRESH_FAST		32768	/* Intern flag */

85 86 87
/* RESET (remove all queries) from query cache */
#define REFRESH_QUERY_CACHE	65536
#define REFRESH_QUERY_CACHE_FREE 0x20000L /* pack query cache */
88
#define REFRESH_DES_KEY_FILE	0x40000L
89
#define REFRESH_USER_RESOURCES	0x80000L
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
90

bk@work.mysql.com's avatar
bk@work.mysql.com committed
91 92 93 94 95 96 97 98 99 100 101 102
#define CLIENT_LONG_PASSWORD	1	/* new more secure passwords */
#define CLIENT_FOUND_ROWS	2	/* Found instead of affected rows */
#define CLIENT_LONG_FLAG	4	/* Get all column flags */
#define CLIENT_CONNECT_WITH_DB	8	/* One can specify db on connect */
#define CLIENT_NO_SCHEMA	16	/* Don't allow database.table.column */
#define CLIENT_COMPRESS		32	/* Can use compression protocol */
#define CLIENT_ODBC		64	/* Odbc client */
#define CLIENT_LOCAL_FILES	128	/* Can use LOAD DATA LOCAL */
#define CLIENT_IGNORE_SPACE	256	/* Ignore spaces before '(' */
#define CLIENT_INTERACTIVE	1024	/* This is an interactive client */
#define CLIENT_SSL              2048     /* Switch to SSL after handshake */
#define CLIENT_IGNORE_SIGPIPE   4096     /* IGNORE sigpipes */
103
#define CLIENT_TRANSACTIONS	8192	/* Client knows about transactions */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
104 105 106 107 108 109 110 111 112 113 114 115

#define SERVER_STATUS_IN_TRANS  1	/* Transaction has started */
#define SERVER_STATUS_AUTOCOMMIT 2	/* Server in auto_commit mode */

#define MYSQL_ERRMSG_SIZE	200
#define NET_READ_TIMEOUT	30		/* Timeout on read */
#define NET_WRITE_TIMEOUT	60		/* Timeout on write */
#define NET_WAIT_TIMEOUT	8*60*60		/* Wait for new query */

struct st_vio;					/* Only C */
typedef struct st_vio Vio;

116 117
#define MAX_CHAR_WIDTH		255	/* Max length for a CHAR colum */
#define MAX_BLOB_WIDTH		8192	/* Default width for blob */
118

bk@work.mysql.com's avatar
bk@work.mysql.com committed
119 120
typedef struct st_net {
  Vio* vio;
121
  unsigned char *buff,*buff_end,*write_pos,*read_pos;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
122
  my_socket fd;					/* For Perl DBI/dbd */
123 124
  unsigned long max_packet,max_packet_size;
  unsigned int last_errno,pkt_nr,compress_pkt_nr;
125
  unsigned int write_timeout, read_timeout, retry_count;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
126 127 128 129
  int fcntl;
  char last_error[MYSQL_ERRMSG_SIZE];
  unsigned char error;
  my_bool return_errno,compress;
130 131 132 133 134
  /*
    The following variable is set if we are doing several queries in one
    command ( as in LOAD TABLE ... FROM MASTER ),
    and do not want to confuse the client with OK at the wrong time
  */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
135 136 137 138
  unsigned long remain_in_buf,length, buf_length, where_b;
  unsigned int *return_status;
  unsigned char reading_or_writing;
  char save_char;
139
  my_bool no_send_ok;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
140
  gptr query_cache_query;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
141 142
} NET;

143
#define packet_error (~(unsigned long) 0)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159

enum enum_field_types { FIELD_TYPE_DECIMAL, FIELD_TYPE_TINY,
			FIELD_TYPE_SHORT,  FIELD_TYPE_LONG,
			FIELD_TYPE_FLOAT,  FIELD_TYPE_DOUBLE,
			FIELD_TYPE_NULL,   FIELD_TYPE_TIMESTAMP,
			FIELD_TYPE_LONGLONG,FIELD_TYPE_INT24,
			FIELD_TYPE_DATE,   FIELD_TYPE_TIME,
			FIELD_TYPE_DATETIME, FIELD_TYPE_YEAR,
			FIELD_TYPE_NEWDATE,
			FIELD_TYPE_ENUM=247,
			FIELD_TYPE_SET=248,
			FIELD_TYPE_TINY_BLOB=249,
			FIELD_TYPE_MEDIUM_BLOB=250,
			FIELD_TYPE_LONG_BLOB=251,
			FIELD_TYPE_BLOB=252,
			FIELD_TYPE_VAR_STRING=253,
160 161
			FIELD_TYPE_STRING=254,
			FIELD_TYPE_GEOMETRY=255
bk@work.mysql.com's avatar
bk@work.mysql.com committed
162 163 164 165 166 167 168
};

#define FIELD_TYPE_CHAR FIELD_TYPE_TINY		/* For compability */
#define FIELD_TYPE_INTERVAL FIELD_TYPE_ENUM	/* For compability */

#define net_new_transaction(net) ((net)->pkt_nr=0)

169 170 171 172
#ifdef __cplusplus
extern "C" {
#endif

bk@work.mysql.com's avatar
bk@work.mysql.com committed
173
int	my_net_init(NET *net, Vio* vio);
174
void	my_net_local_init(NET *net);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
175 176 177 178 179 180 181
void	net_end(NET *net);
void	net_clear(NET *net);
int	net_flush(NET *net);
int	my_net_write(NET *net,const char *packet,unsigned long len);
int	net_write_command(NET *net,unsigned char command,const char *packet,
			  unsigned long len);
int	net_real_write(NET *net,const char *packet,unsigned long len);
182
unsigned long my_net_read(NET *net);
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
183 184 185

/* The following function is not meant for normal usage */
struct sockaddr;
186 187
int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen,
	       unsigned int timeout);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
188 189 190 191 192 193

struct rand_struct {
  unsigned long seed1,seed2,max_value;
  double max_value_dbl;
};

194 195 196 197
#ifdef __cplusplus
}
#endif

bk@work.mysql.com's avatar
bk@work.mysql.com committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
  /* The following is for user defined functions */

enum Item_result {STRING_RESULT,REAL_RESULT,INT_RESULT};

typedef struct st_udf_args
{
  unsigned int arg_count;		/* Number of arguments */
  enum Item_result *arg_type;		/* Pointer to item_results */
  char **args;				/* Pointer to argument */
  unsigned long *lengths;		/* Length of string arguments */
  char *maybe_null;			/* Set to 1 for all maybe_null args */
} UDF_ARGS;

  /* This holds information about the result */

typedef struct st_udf_init
{
  my_bool maybe_null;			/* 1 if function can return NULL */
  unsigned int decimals;		/* for real functions */
217
  unsigned long max_length;		/* For string functions */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
218 219 220 221 222 223 224 225 226 227 228 229 230
  char	  *ptr;				/* free pointer for function data */
  my_bool const_item;			/* 0 if result is independent of arguments */
} UDF_INIT;

  /* Constants when using compression */
#define NET_HEADER_SIZE 4		/* standard header size */
#define COMP_HEADER_SIZE 3		/* compression header extra size */

  /* Prototypes to password functions */

#ifdef __cplusplus
extern "C" {
#endif
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
231

232 233
dll_import_spec extern unsigned long max_allowed_packet;
dll_import_spec extern unsigned long net_buffer_length;
234

bk@work.mysql.com's avatar
bk@work.mysql.com committed
235 236
void randominit(struct rand_struct *,unsigned long seed1,
		unsigned long seed2);
237
double my_rnd(struct rand_struct *);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
238 239 240 241 242 243 244 245 246 247 248 249
void make_scrambled_password(char *to,const char *password);
void get_salt_from_password(unsigned long *res,const char *password);
void make_password_from_salt(char *to, unsigned long *hash_res);
char *scramble(char *to,const char *message,const char *password,
	       my_bool old_ver);
my_bool check_scramble(const char *, const char *message,
		       unsigned long *salt,my_bool old_ver);
char *get_tty_password(char *opt_message);
void hash_password(unsigned long *result, const char *password);

/* Some other useful functions */

250
my_bool my_init(void);
251 252
int load_defaults(const char *conf_file, const char **groups,
		  int *argc, char ***argv);
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
253
my_bool my_thread_init(void);
254
void my_thread_end(void);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
255

tonu@hundin.mysql.fi's avatar
tonu@hundin.mysql.fi committed
256 257 258 259
#ifdef __cplusplus
}
#endif

bk@work.mysql.com's avatar
bk@work.mysql.com committed
260 261 262
#define NULL_LENGTH ((unsigned long) ~0) /* For net_store_length */

#endif