~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to include/drizzle_com.h

Removed dead variable, sorted authors file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
 
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; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
19
15
 
20
16
/*
21
17
** Common definition between mysql server & client
22
18
*/
23
19
 
24
 
#ifndef _libdrizzle_drizzle_com_h
25
 
#define _libdrizzle_drizzle_com_h
26
 
 
27
 
#include <config.h>
28
 
#include <unistd.h>
29
 
#include <stdbool.h>
30
 
#include <stdint.h>
31
 
 
32
 
/*
33
 
   This is included in the server and in the client.
34
 
   Options for select set by the yacc parser (stored in lex->options).
35
 
 
36
 
   XXX:
37
 
   log_event.h defines OPTIONS_WRITTEN_TO_BIN_LOG to specify what THD
38
 
   options list are written into binlog. These options can NOT change their
39
 
   values, or it will break replication between version.
40
 
 
41
 
   context is encoded as following:
42
 
   SELECT - SELECT_LEX_NODE::options
43
 
   THD    - THD::options
44
 
   intern - neither. used only as
45
 
            func(..., select_node->options | thd->options | OPTION_XXX, ...)
46
 
 
47
 
   TODO: separate three contexts above, move them to separate bitfields.
48
 
*/
49
 
 
50
 
#define SELECT_DISTINCT         (UINT64_C(1) << 0)     // SELECT, user
51
 
#define SELECT_STRAIGHT_JOIN    (UINT64_C(1) << 1)     // SELECT, user
52
 
#define SELECT_DESCRIBE         (UINT64_C(1) << 2)     // SELECT, user
53
 
#define SELECT_SMALL_RESULT     (UINT64_C(1) << 3)     // SELECT, user
54
 
#define SELECT_BIG_RESULT       (UINT64_C(1) << 4)     // SELECT, user
55
 
#define OPTION_FOUND_ROWS       (UINT64_C(1) << 5)     // SELECT, user
56
 
#define SELECT_NO_JOIN_CACHE    (UINT64_C(1) << 7)     // intern
57
 
#define OPTION_BIG_TABLES       (UINT64_C(1) << 8)     // THD, user
58
 
#define OPTION_BIG_SELECTS      (UINT64_C(1) << 9)     // THD, user
59
 
#define OPTION_LOG_OFF          (UINT64_C(1) << 10)    // THD, user
60
 
#define OPTION_QUOTE_SHOW_CREATE (UINT64_C(1) << 11)   // THD, user, unused
61
 
#define TMP_TABLE_ALL_COLUMNS   (UINT64_C(1) << 12)    // SELECT, intern
62
 
#define OPTION_WARNINGS         (UINT64_C(1) << 13)    // THD, user
63
 
#define OPTION_AUTO_IS_NULL     (UINT64_C(1) << 14)    // THD, user, binlog
64
 
#define OPTION_FOUND_COMMENT    (UINT64_C(1) << 15)    // SELECT, intern, parser
65
 
#define OPTION_SAFE_UPDATES     (UINT64_C(1) << 16)    // THD, user
66
 
#define OPTION_BUFFER_RESULT    (UINT64_C(1) << 17)    // SELECT, user
67
 
#define OPTION_BIN_LOG          (UINT64_C(1) << 18)    // THD, user
68
 
#define OPTION_NOT_AUTOCOMMIT   (UINT64_C(1) << 19)    // THD, user
69
 
#define OPTION_BEGIN            (UINT64_C(1) << 20)    // THD, intern
70
 
#define OPTION_TABLE_LOCK       (UINT64_C(1) << 21)    // THD, intern
71
 
#define OPTION_QUICK            (UINT64_C(1) << 22)    // SELECT (for DELETE)
72
 
#define OPTION_KEEP_LOG         (UINT64_C(1) << 23)    // THD, user
73
 
 
74
 
/* The following is used to detect a conflict with DISTINCT */
75
 
#define SELECT_ALL              (UINT64_C(1) << 24)    // SELECT, user, parser
76
 
 
77
 
/** The following can be set when importing tables in a 'wrong order'
78
 
   to suppress foreign key checks */
79
 
#define OPTION_NO_FOREIGN_KEY_CHECKS    (UINT64_C(1) << 26) // THD, user, binlog
80
 
/** The following speeds up inserts to InnoDB tables by suppressing unique
81
 
   key checks in some cases */
82
 
#define OPTION_RELAXED_UNIQUE_CHECKS    (UINT64_C(1) << 27) // THD, user, binlog
83
 
#define SELECT_NO_UNLOCK                (UINT64_C(1) << 28) // SELECT, intern
84
 
#define OPTION_SCHEMA_TABLE             (UINT64_C(1) << 29) // SELECT, intern
85
 
/** Flag set if setup_tables already done */
86
 
#define OPTION_SETUP_TABLES_DONE        (UINT64_C(1) << 30) // intern
87
 
/** If not set then the thread will ignore all warnings with level notes. */
88
 
#define OPTION_SQL_NOTES                (UINT64_C(1) << 31) // THD, user
89
 
/**
90
 
  Force the used temporary table to be a MyISAM table (because we will use
91
 
  fulltext functions when reading from it.
92
 
*/
93
 
#define TMP_TABLE_FORCE_MYISAM          (UINT64_C(1) << 32)
94
 
#define OPTION_PROFILING                (UINT64_C(1) << 33)
95
 
 
96
 
/*
97
 
  Dont report errors for individual rows,
98
 
  But just report error on commit (or read ofcourse)
99
 
*/
100
 
#define OPTION_ALLOW_BATCH              (UINT64_C(1) << 33) // THD, intern (slave)
101
 
 
102
 
/**
103
 
  Maximum length of time zone name that we support
104
 
  (Time zone name is char(64) in db). mysqlbinlog needs it.
105
 
*/
106
 
#define MAX_TIME_ZONE_NAME_LENGTH       (NAME_LEN + 1)
 
20
#ifndef _mysql_com_h
 
21
#define _mysql_com_h
107
22
 
108
23
#define HOSTNAME_LENGTH 60
109
24
#define SYSTEM_CHARSET_MBMAXLEN 4
122
37
#define COLUMN_COMMENT_MAXLEN 1024
123
38
#define INDEX_COMMENT_MAXLEN 1024
124
39
 
125
 
/* The length of the header part for each virtual column in the .frm file. */
126
 
#define FRM_VCOL_HEADER_SIZE 3
127
 
/*
128
 
  Maximum length of the expression statement defined for virtual columns.
129
 
*/
130
 
#define VIRTUAL_COLUMN_EXPRESSION_MAXLEN 255 - FRM_VCOL_HEADER_SIZE
131
40
 
132
41
/*
133
42
  USER_HOST_BUFF_SIZE -- length of string buffer, that is enough to contain
148
57
enum enum_server_command
149
58
{
150
59
  COM_SLEEP, COM_QUIT, COM_INIT_DB, COM_QUERY, COM_FIELD_LIST,
151
 
  COM_CREATE_DB, COM_DROP_DB, COM_REFRESH, COM_SHUTDOWN,
152
 
  COM_PROCESS_INFO, COM_CONNECT, COM_PROCESS_KILL, COM_PING,
153
 
  COM_TIME, COM_CHANGE_USER, COM_BINLOG_DUMP,
154
 
  COM_CONNECT_OUT, COM_REGISTER_SLAVE,
155
 
  COM_SET_OPTION, COM_DAEMON,
 
60
  COM_CREATE_DB, COM_DROP_DB, COM_REFRESH, COM_SHUTDOWN, COM_STATISTICS,
 
61
  COM_PROCESS_INFO, COM_CONNECT, COM_PROCESS_KILL, COM_DEBUG, COM_PING,
 
62
  COM_TIME, COM_DELAYED_INSERT, COM_CHANGE_USER, COM_BINLOG_DUMP,
 
63
  COM_TABLE_DUMP, COM_CONNECT_OUT, COM_REGISTER_SLAVE,
 
64
  COM_STMT_PREPARE, COM_STMT_EXECUTE, COM_STMT_SEND_LONG_DATA, COM_STMT_CLOSE,
 
65
  COM_STMT_RESET, COM_SET_OPTION, COM_STMT_FETCH, COM_DAEMON,
156
66
  /* don't forget to update const char *command_name[] in sql_parse.cc */
157
67
 
158
68
  /* Must be last */
177
87
#define MULTIPLE_KEY_FLAG 8             /* Field is part of a key */
178
88
#define BLOB_FLAG       16              /* Field is a blob */
179
89
#define UNSIGNED_FLAG   32              /* Field is unsigned */
180
 
#define DECIMAL_FLAG    64              /* Field is zerofill */
 
90
#define ZEROFILL_FLAG   64              /* Field is zerofill */
181
91
#define BINARY_FLAG     128             /* Field is binary   */
182
92
 
183
93
/* The following are only sent to new clients */
229
139
#define CLIENT_ODBC             64      /* Odbc client */
230
140
#define CLIENT_LOCAL_FILES      128     /* Can use LOAD DATA LOCAL */
231
141
#define CLIENT_IGNORE_SPACE     256     /* Ignore spaces before '(' */
232
 
#define UNUSED_CLIENT_PROTOCOL_41       512     /* New 4.1 protocol */
 
142
#define CLIENT_PROTOCOL_41      512     /* New 4.1 protocol */
233
143
#define CLIENT_INTERACTIVE      1024    /* This is an interactive client */
234
144
#define CLIENT_SSL              2048    /* Switch to SSL after handshake */
235
145
#define CLIENT_IGNORE_SIGPIPE   4096    /* IGNORE sigpipes */
252
162
                           CLIENT_ODBC | \
253
163
                           CLIENT_LOCAL_FILES | \
254
164
                           CLIENT_IGNORE_SPACE | \
 
165
                           CLIENT_PROTOCOL_41 | \
255
166
                           CLIENT_INTERACTIVE | \
256
167
                           CLIENT_SSL | \
257
168
                           CLIENT_IGNORE_SIGPIPE | \
297
208
*/
298
209
#define SERVER_QUERY_WAS_SLOW           1024
299
210
 
300
 
#define DRIZZLE_ERRMSG_SIZE     512
 
211
#define MYSQL_ERRMSG_SIZE       512
301
212
#define NET_READ_TIMEOUT        30              /* Timeout on read */
302
213
#define NET_WRITE_TIMEOUT       60              /* Timeout on write */
303
214
#define NET_WAIT_TIMEOUT        8*60*60         /* Wait for new query */
315
226
#define MAX_CHAR_WIDTH          255     /* Max length for a CHAR colum */
316
227
#define MAX_BLOB_WIDTH          16777216        /* Default width for blob */
317
228
 
318
 
#define DRIZZLE_PROTOCOL_NO_MORE_DATA 0xFE
319
 
 
320
 
 
 
229
typedef struct st_net {
 
230
  Vio *vio;
 
231
  unsigned char *buff,*buff_end,*write_pos,*read_pos;
 
232
  my_socket fd;                                 /* For Perl DBI/dbd */
 
233
  /*
 
234
    The following variable is set if we are doing several queries in one
 
235
    command ( as in LOAD TABLE ... FROM MASTER ),
 
236
    and do not want to confuse the client with OK at the wrong time
 
237
  */
 
238
  unsigned long remain_in_buf,length, buf_length, where_b;
 
239
  unsigned long max_packet,max_packet_size;
 
240
  unsigned int pkt_nr,compress_pkt_nr;
 
241
  unsigned int write_timeout;
 
242
  unsigned int read_timeout;
 
243
  unsigned int retry_count;
 
244
  int fcntl;
 
245
  unsigned int *return_status;
 
246
  unsigned char reading_or_writing;
 
247
  char save_char;
 
248
  my_bool compress;
 
249
  /*
 
250
    Pointer to query object in query cache, do not equal NULL (0) for
 
251
    queries in cache that have not stored its results yet
 
252
  */
 
253
  /*
 
254
    Unused, please remove with the next incompatible ABI change.
 
255
  */
 
256
  unsigned char *unused;
 
257
  unsigned int last_errno;
 
258
  unsigned char error; 
 
259
  /** Client library error message buffer. Actually belongs to struct MYSQL. */
 
260
  char last_error[MYSQL_ERRMSG_SIZE];
 
261
  /** Client library sqlstate buffer. Set along with the error message. */
 
262
  char sqlstate[SQLSTATE_LENGTH+1];
 
263
  void *extension;
 
264
} NET;
321
265
 
322
266
 
323
267
#define packet_error (~(uint32_t) 0)
324
268
 
 
269
/* Start TINY at 1 because we removed DECIMAL from off the front of the enum */
 
270
enum enum_field_types { MYSQL_TYPE_TINY=1,
 
271
                        MYSQL_TYPE_SHORT,  MYSQL_TYPE_LONG,
 
272
                        MYSQL_TYPE_DOUBLE,
 
273
                        MYSQL_TYPE_NULL,   MYSQL_TYPE_TIMESTAMP,
 
274
                        MYSQL_TYPE_LONGLONG,
 
275
                        MYSQL_TYPE_DATE,   MYSQL_TYPE_TIME,
 
276
                        MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
 
277
                        MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
 
278
                        MYSQL_TYPE_NEWDECIMAL=250,
 
279
                        MYSQL_TYPE_ENUM=251,
 
280
                        MYSQL_TYPE_SET=252,
 
281
                        MYSQL_TYPE_BLOB=253,
 
282
                        MYSQL_TYPE_VAR_STRING=254,
 
283
                        MYSQL_TYPE_STRING=255
 
284
};
 
285
 
 
286
/* For backward compatibility */
 
287
#define CLIENT_MULTI_QUERIES    CLIENT_MULTI_STATEMENTS    
 
288
#define FIELD_TYPE_NEWDECIMAL  MYSQL_TYPE_NEWDECIMAL
 
289
#define FIELD_TYPE_TINY        MYSQL_TYPE_TINY
 
290
#define FIELD_TYPE_SHORT       MYSQL_TYPE_SHORT
 
291
#define FIELD_TYPE_LONG        MYSQL_TYPE_LONG
 
292
#define FIELD_TYPE_DOUBLE      MYSQL_TYPE_DOUBLE
 
293
#define FIELD_TYPE_NULL        MYSQL_TYPE_NULL
 
294
#define FIELD_TYPE_TIMESTAMP   MYSQL_TYPE_TIMESTAMP
 
295
#define FIELD_TYPE_LONGLONG    MYSQL_TYPE_LONGLONG
 
296
#define FIELD_TYPE_TIME        MYSQL_TYPE_TIME
 
297
#define FIELD_TYPE_DATETIME    MYSQL_TYPE_DATETIME
 
298
#define FIELD_TYPE_YEAR        MYSQL_TYPE_YEAR
 
299
#define FIELD_TYPE_NEWDATE     MYSQL_TYPE_NEWDATE
 
300
#define FIELD_TYPE_ENUM        MYSQL_TYPE_ENUM
 
301
#define FIELD_TYPE_SET         MYSQL_TYPE_SET
 
302
#define FIELD_TYPE_TINY_BLOB   MYSQL_TYPE_TINY_BLOB
 
303
#define FIELD_TYPE_BLOB        MYSQL_TYPE_BLOB
 
304
#define FIELD_TYPE_VAR_STRING  MYSQL_TYPE_VAR_STRING
 
305
#define FIELD_TYPE_STRING      MYSQL_TYPE_STRING
 
306
#define FIELD_TYPE_CHAR        MYSQL_TYPE_TINY
 
307
#define FIELD_TYPE_INTERVAL    MYSQL_TYPE_ENUM
 
308
 
325
309
 
326
310
/* Shutdown/kill enums and constants */ 
327
311
 
328
312
/* Bits for THD::killable. */
329
 
#define DRIZZLE_SHUTDOWN_KILLABLE_CONNECT    (unsigned char)(1 << 0)
330
 
#define DRIZZLE_SHUTDOWN_KILLABLE_TRANS      (unsigned char)(1 << 1)
331
 
#define DRIZZLE_SHUTDOWN_KILLABLE_LOCK_TABLE (unsigned char)(1 << 2)
332
 
#define DRIZZLE_SHUTDOWN_KILLABLE_UPDATE     (unsigned char)(1 << 3)
 
313
#define MYSQL_SHUTDOWN_KILLABLE_CONNECT    (unsigned char)(1 << 0)
 
314
#define MYSQL_SHUTDOWN_KILLABLE_TRANS      (unsigned char)(1 << 1)
 
315
#define MYSQL_SHUTDOWN_KILLABLE_LOCK_TABLE (unsigned char)(1 << 2)
 
316
#define MYSQL_SHUTDOWN_KILLABLE_UPDATE     (unsigned char)(1 << 3)
333
317
 
334
 
/* Start TINY at 1 because we removed DECIMAL from off the front of the enum */
335
 
enum enum_field_types { DRIZZLE_TYPE_TINY=1,
336
 
                        DRIZZLE_TYPE_LONG,
337
 
                        DRIZZLE_TYPE_DOUBLE,
338
 
                        DRIZZLE_TYPE_NULL,   DRIZZLE_TYPE_TIMESTAMP,
339
 
                        DRIZZLE_TYPE_LONGLONG,
340
 
                        DRIZZLE_TYPE_TIME,
341
 
                        DRIZZLE_TYPE_DATETIME,
342
 
                        DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_VARCHAR,
343
 
                                          DRIZZLE_TYPE_VIRTUAL=252,
344
 
                        DRIZZLE_TYPE_NEWDECIMAL=253,
345
 
                        DRIZZLE_TYPE_ENUM=254,
346
 
                        DRIZZLE_TYPE_BLOB=255
 
318
enum mysql_enum_shutdown_level {
 
319
  /*
 
320
    We want levels to be in growing order of hardness (because we use number
 
321
    comparisons). Note that DEFAULT does not respect the growing property, but
 
322
    it's ok.
 
323
  */
 
324
  SHUTDOWN_DEFAULT = 0,
 
325
  /* wait for existing connections to finish */
 
326
  SHUTDOWN_WAIT_CONNECTIONS= MYSQL_SHUTDOWN_KILLABLE_CONNECT,
 
327
  /* wait for existing trans to finish */
 
328
  SHUTDOWN_WAIT_TRANSACTIONS= MYSQL_SHUTDOWN_KILLABLE_TRANS,
 
329
  /* wait for existing updates to finish (=> no partial MyISAM update) */
 
330
  SHUTDOWN_WAIT_UPDATES= MYSQL_SHUTDOWN_KILLABLE_UPDATE,
 
331
  /* flush InnoDB buffers and other storage engines' buffers*/
 
332
  SHUTDOWN_WAIT_ALL_BUFFERS= (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1),
 
333
  /* don't flush InnoDB buffers, flush other storage engines' buffers*/
 
334
  SHUTDOWN_WAIT_CRITICAL_BUFFERS= (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1) + 1,
 
335
  /* Now the 2 levels of the KILL command */
 
336
  KILL_QUERY= 254,
 
337
  KILL_CONNECTION= 255
347
338
};
348
339
 
349
340
 
357
348
 
358
349
 
359
350
/* options for mysql_set_option */
360
 
enum enum_drizzle_set_option
 
351
enum enum_mysql_set_option
361
352
{
362
 
  DRIZZLE_OPTION_MULTI_STATEMENTS_ON,
363
 
  DRIZZLE_OPTION_MULTI_STATEMENTS_OFF
 
353
  MYSQL_OPTION_MULTI_STATEMENTS_ON,
 
354
  MYSQL_OPTION_MULTI_STATEMENTS_OFF
364
355
};
365
356
 
366
357
#define net_new_transaction(net) ((net)->pkt_nr=0)
369
360
extern "C" {
370
361
#endif
371
362
 
372
 
 
373
 
  struct rand_struct {
374
 
    unsigned long seed1,seed2,max_value;
375
 
    double max_value_dbl;
376
 
  };
 
363
bool    my_net_init(NET *net, Vio* vio);
 
364
void    my_net_local_init(NET *net);
 
365
void    net_end(NET *net);
 
366
void    net_clear(NET *net, bool clear_buffer);
 
367
bool    net_realloc(NET *net, size_t length);
 
368
bool    net_flush(NET *net);
 
369
bool    my_net_write(NET *net,const unsigned char *packet, size_t len);
 
370
bool    net_write_command(NET *net,unsigned char command,
 
371
                          const unsigned char *header, size_t head_len,
 
372
                          const unsigned char *packet, size_t len);
 
373
int32_t net_real_write(NET *net,const unsigned char *packet, size_t len);
 
374
uint32_t my_net_read(NET *net);
 
375
 
 
376
#ifdef _global_h
 
377
void my_net_set_write_timeout(NET *net, uint timeout);
 
378
void my_net_set_read_timeout(NET *net, uint timeout);
 
379
#endif
 
380
 
 
381
struct sockaddr;
 
382
int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen,
 
383
               unsigned int timeout);
 
384
 
 
385
struct rand_struct {
 
386
  unsigned long seed1,seed2,max_value;
 
387
  double max_value_dbl;
 
388
};
377
389
 
378
390
#ifdef __cplusplus
379
391
}
400
412
 
401
413
typedef struct st_udf_init
402
414
{
403
 
  bool maybe_null;          /* 1 if function can return NULL */
 
415
  my_bool maybe_null;          /* 1 if function can return NULL */
404
416
  unsigned int decimals;       /* for real functions */
405
417
  unsigned long max_length;    /* For string functions */
406
418
  char *ptr;                   /* free pointer for function data */
407
 
  bool const_item;          /* 1 if function always returns the same value */
 
419
  my_bool const_item;          /* 1 if function always returns the same value */
408
420
  void *extension;
409
421
} UDF_INIT;
410
422
/* 
427
439
  implemented in sql/password.c
428
440
*/
429
441
 
430
 
  void randominit(struct rand_struct *, uint32_t seed1, uint32_t seed2);
431
 
  double my_rnd(struct rand_struct *);
432
 
  void create_random_string(char *to, unsigned int length,
433
 
                            struct rand_struct *rand_st);
434
 
 
435
 
  void hash_password(uint32_t *to, const char *password, uint32_t password_len);
436
 
 
437
 
  void make_scrambled_password(char *to, const char *password);
438
 
  void scramble(char *to, const char *message, const char *password);
439
 
  bool check_scramble(const char *reply, const char *message,
440
 
                      const unsigned char *hash_stage2);
441
 
  void get_salt_from_password(unsigned char *res, const char *password);
442
 
  void make_password_from_salt(char *to, const unsigned char *hash_stage2);
443
 
  char *octet2hex(char *to, const char *str, unsigned int len);
 
442
void randominit(struct rand_struct *, uint32_t seed1, uint32_t seed2);
 
443
double my_rnd(struct rand_struct *);
 
444
void create_random_string(char *to, unsigned int length, struct rand_struct *rand_st);
 
445
 
 
446
void hash_password(uint32_t *to, const char *password, uint32_t password_len);
 
447
 
 
448
void make_scrambled_password(char *to, const char *password);
 
449
void scramble(char *to, const char *message, const char *password);
 
450
my_bool check_scramble(const char *reply, const char *message,
 
451
                       const unsigned char *hash_stage2);
 
452
void get_salt_from_password(unsigned char *res, const char *password);
 
453
void make_password_from_salt(char *to, const unsigned char *hash_stage2);
 
454
char *octet2hex(char *to, const char *str, unsigned int len);
444
455
 
445
456
/* end of password.c */
446
457
 
447
 
  char *get_tty_password(const char *opt_message);
448
 
 
449
 
  uint32_t net_field_length(unsigned char **packet);
450
 
  uint64_t net_field_length_ll(unsigned char **packet);
451
 
  unsigned char *net_store_length(unsigned char *pkg, uint64_t length);
452
 
 
453
 
/*
454
 
  Define-funktions for reading and storing in machine independent format
455
 
  (low byte first)
456
 
*/
457
 
 
458
 
/* Optimized store functions for Intel x86 */
459
 
#if defined(__i386__)
460
 
#define sint2korr(A)    (*((int16_t *) (A)))
461
 
#define sint3korr(A)    ((int32_t) ((((unsigned char) (A)[2]) & 128) ? \
462
 
                                  (((uint32_t) 255L << 24) | \
463
 
                                   (((uint32_t) (unsigned char) (A)[2]) << 16) |\
464
 
                                   (((uint32_t) (unsigned char) (A)[1]) << 8) | \
465
 
                                   ((uint32_t) (unsigned char) (A)[0])) : \
466
 
                                  (((uint32_t) (unsigned char) (A)[2]) << 16) |\
467
 
                                  (((uint32_t) (unsigned char) (A)[1]) << 8) | \
468
 
                                  ((uint32_t) (unsigned char) (A)[0])))
469
 
#define sint4korr(A)    (*((long *) (A)))
470
 
#define uint2korr(A)    (*((uint16_t *) (A)))
471
 
#if defined(HAVE_purify)
472
 
#define uint3korr(A)    (uint32_t) (((uint32_t) ((unsigned char) (A)[0])) +\
473
 
                                  (((uint32_t) ((unsigned char) (A)[1])) << 8) +\
474
 
                                  (((uint32_t) ((unsigned char) (A)[2])) << 16))
475
 
#else
476
 
/*
477
 
   ATTENTION !
478
 
   
479
 
    Please, note, uint3korr reads 4 bytes (not 3) !
480
 
    It means, that you have to provide enough allocated space !
481
 
*/
482
 
#define uint3korr(A)    (long) (*((unsigned int *) (A)) & 0xFFFFFF)
483
 
#endif /* HAVE_purify */
484
 
#define uint4korr(A)    (*((uint32_t *) (A)))
485
 
#define uint5korr(A)    ((uint64_t)(((uint32_t) ((unsigned char) (A)[0])) +\
486
 
                                    (((uint32_t) ((unsigned char) (A)[1])) << 8) +\
487
 
                                    (((uint32_t) ((unsigned char) (A)[2])) << 16) +\
488
 
                                    (((uint32_t) ((unsigned char) (A)[3])) << 24)) +\
489
 
                                    (((uint64_t) ((unsigned char) (A)[4])) << 32))
490
 
#define uint6korr(A)    ((uint64_t)(((uint32_t)    ((unsigned char) (A)[0]))          + \
491
 
                                     (((uint32_t)    ((unsigned char) (A)[1])) << 8)   + \
492
 
                                     (((uint32_t)    ((unsigned char) (A)[2])) << 16)  + \
493
 
                                     (((uint32_t)    ((unsigned char) (A)[3])) << 24)) + \
494
 
                         (((uint64_t) ((unsigned char) (A)[4])) << 32) +       \
495
 
                         (((uint64_t) ((unsigned char) (A)[5])) << 40))
496
 
#define uint8korr(A)    (*((uint64_t *) (A)))
497
 
#define sint8korr(A)    (*((int64_t *) (A)))
498
 
#define int2store(T,A)  *((uint16_t*) (T))= (uint16_t) (A)
499
 
#define int3store(T,A)  do { *(T)=  (unsigned char) ((A));\
500
 
                            *(T+1)=(unsigned char) (((uint32_t) (A) >> 8));\
501
 
                            *(T+2)=(unsigned char) (((A) >> 16)); } while (0)
502
 
#define int4store(T,A)  *((long *) (T))= (long) (A)
503
 
#define int5store(T,A)  do { *(T)= (unsigned char)((A));\
504
 
                             *((T)+1)=(unsigned char) (((A) >> 8));\
505
 
                             *((T)+2)=(unsigned char) (((A) >> 16));\
506
 
                             *((T)+3)=(unsigned char) (((A) >> 24)); \
507
 
                             *((T)+4)=(unsigned char) (((A) >> 32)); } while(0)
508
 
#define int6store(T,A)  do { *(T)=    (unsigned char)((A));          \
509
 
                             *((T)+1)=(unsigned char) (((A) >> 8));  \
510
 
                             *((T)+2)=(unsigned char) (((A) >> 16)); \
511
 
                             *((T)+3)=(unsigned char) (((A) >> 24)); \
512
 
                             *((T)+4)=(unsigned char) (((A) >> 32)); \
513
 
                             *((T)+5)=(unsigned char) (((A) >> 40)); } while(0)
514
 
#define int8store(T,A)  *((uint64_t *) (T))= (uint64_t) (A)
515
 
 
516
 
typedef union {
517
 
  double v;
518
 
  long m[2];
519
 
} doubleget_union;
520
 
#define doubleget(V,M)  \
521
 
do { doubleget_union _tmp; \
522
 
     _tmp.m[0] = *((long*)(M)); \
523
 
     _tmp.m[1] = *(((long*) (M))+1); \
524
 
     (V) = _tmp.v; } while(0)
525
 
#define doublestore(T,V) do { *((long *) T) = ((doubleget_union *)&V)->m[0]; \
526
 
                             *(((long *) T)+1) = ((doubleget_union *)&V)->m[1]; \
527
 
                         } while (0)
528
 
#define float4get(V,M)   do { *((float *) &(V)) = *((float*) (M)); } while(0)
529
 
#define float8get(V,M)   doubleget((V),(M))
530
 
#define float4store(V,M) memcpy(V, (&M), sizeof(float))
531
 
#define floatstore(T,V)  memcpy((T), (&V), sizeof(float))
532
 
#define floatget(V,M)    memcpy(&V, (M), sizeof(float))
533
 
#define float8store(V,M) doublestore((V),(M))
534
 
#else
535
 
 
536
 
/*
537
 
  We're here if it's not a IA-32 architecture (Win32 and UNIX IA-32 defines
538
 
  were done before)
539
 
*/
540
 
#define sint2korr(A)    (int16_t) (((int16_t) ((unsigned char) (A)[0])) +\
541
 
                                 ((int16_t) ((int16_t) (A)[1]) << 8))
542
 
#define sint3korr(A)    ((int32_t) ((((unsigned char) (A)[2]) & 128) ? \
543
 
                                  (((uint32_t) 255L << 24) | \
544
 
                                   (((uint32_t) (unsigned char) (A)[2]) << 16) |\
545
 
                                   (((uint32_t) (unsigned char) (A)[1]) << 8) | \
546
 
                                   ((uint32_t) (unsigned char) (A)[0])) : \
547
 
                                  (((uint32_t) (unsigned char) (A)[2]) << 16) |\
548
 
                                  (((uint32_t) (unsigned char) (A)[1]) << 8) | \
549
 
                                  ((uint32_t) (unsigned char) (A)[0])))
550
 
#define sint4korr(A)    (int32_t) (((int32_t) ((unsigned char) (A)[0])) +\
551
 
                                (((int32_t) ((unsigned char) (A)[1]) << 8)) +\
552
 
                                (((int32_t) ((unsigned char) (A)[2]) << 16)) +\
553
 
                                (((int32_t) ((int16_t) (A)[3]) << 24)))
554
 
#define sint8korr(A)    (int64_t) uint8korr(A)
555
 
#define uint2korr(A)    (uint16_t) (((uint16_t) ((unsigned char) (A)[0])) +\
556
 
                                  ((uint16_t) ((unsigned char) (A)[1]) << 8))
557
 
#define uint3korr(A)    (uint32_t) (((uint32_t) ((unsigned char) (A)[0])) +\
558
 
                                  (((uint32_t) ((unsigned char) (A)[1])) << 8) +\
559
 
                                  (((uint32_t) ((unsigned char) (A)[2])) << 16))
560
 
#define uint4korr(A)    (uint32_t) (((uint32_t) ((unsigned char) (A)[0])) +\
561
 
                                  (((uint32_t) ((unsigned char) (A)[1])) << 8) +\
562
 
                                  (((uint32_t) ((unsigned char) (A)[2])) << 16) +\
563
 
                                  (((uint32_t) ((unsigned char) (A)[3])) << 24))
564
 
#define uint5korr(A)    ((uint64_t)(((uint32_t) ((unsigned char) (A)[0])) +\
565
 
                                    (((uint32_t) ((unsigned char) (A)[1])) << 8) +\
566
 
                                    (((uint32_t) ((unsigned char) (A)[2])) << 16) +\
567
 
                                    (((uint32_t) ((unsigned char) (A)[3])) << 24)) +\
568
 
                                    (((uint64_t) ((unsigned char) (A)[4])) << 32))
569
 
#define uint6korr(A)    ((uint64_t)(((uint32_t)    ((unsigned char) (A)[0]))          + \
570
 
                                     (((uint32_t)    ((unsigned char) (A)[1])) << 8)   + \
571
 
                                     (((uint32_t)    ((unsigned char) (A)[2])) << 16)  + \
572
 
                                     (((uint32_t)    ((unsigned char) (A)[3])) << 24)) + \
573
 
                         (((uint64_t) ((unsigned char) (A)[4])) << 32) +       \
574
 
                         (((uint64_t) ((unsigned char) (A)[5])) << 40))
575
 
#define uint8korr(A)    ((uint64_t)(((uint32_t) ((unsigned char) (A)[0])) +\
576
 
                                    (((uint32_t) ((unsigned char) (A)[1])) << 8) +\
577
 
                                    (((uint32_t) ((unsigned char) (A)[2])) << 16) +\
578
 
                                    (((uint32_t) ((unsigned char) (A)[3])) << 24)) +\
579
 
                        (((uint64_t) (((uint32_t) ((unsigned char) (A)[4])) +\
580
 
                                    (((uint32_t) ((unsigned char) (A)[5])) << 8) +\
581
 
                                    (((uint32_t) ((unsigned char) (A)[6])) << 16) +\
582
 
                                    (((uint32_t) ((unsigned char) (A)[7])) << 24))) <<\
583
 
                                    32))
584
 
#define int2store(T,A)       do { uint32_t def_temp= (uint32_t) (A) ;\
585
 
                                  *((unsigned char*) (T))=  (unsigned char)(def_temp); \
586
 
                                   *((unsigned char*) (T)+1)=(unsigned char)((def_temp >> 8)); \
587
 
                             } while(0)
588
 
#define int3store(T,A)       do { /*lint -save -e734 */\
589
 
                                  *((unsigned char*)(T))=(unsigned char) ((A));\
590
 
                                  *((unsigned char*) (T)+1)=(unsigned char) (((A) >> 8));\
591
 
                                  *((unsigned char*)(T)+2)=(unsigned char) (((A) >> 16)); \
592
 
                                  /*lint -restore */} while(0)
593
 
#define int4store(T,A)       do { *((char *)(T))=(char) ((A));\
594
 
                                  *(((char *)(T))+1)=(char) (((A) >> 8));\
595
 
                                  *(((char *)(T))+2)=(char) (((A) >> 16));\
596
 
                                  *(((char *)(T))+3)=(char) (((A) >> 24)); } while(0)
597
 
#define int5store(T,A)       do { *((char *)(T))=     (char)((A));  \
598
 
                                  *(((char *)(T))+1)= (char)(((A) >> 8)); \
599
 
                                  *(((char *)(T))+2)= (char)(((A) >> 16)); \
600
 
                                  *(((char *)(T))+3)= (char)(((A) >> 24)); \
601
 
                                  *(((char *)(T))+4)= (char)(((A) >> 32)); \
602
 
                                } while(0)
603
 
#define int6store(T,A)       do { *((char *)(T))=     (char)((A)); \
604
 
                                  *(((char *)(T))+1)= (char)(((A) >> 8)); \
605
 
                                  *(((char *)(T))+2)= (char)(((A) >> 16)); \
606
 
                                  *(((char *)(T))+3)= (char)(((A) >> 24)); \
607
 
                                  *(((char *)(T))+4)= (char)(((A) >> 32)); \
608
 
                                  *(((char *)(T))+5)= (char)(((A) >> 40)); \
609
 
                                } while(0)
610
 
#define int8store(T,A)       do { uint32_t def_temp= (uint32_t) (A), def_temp2= (uint32_t) ((A) >> 32); \
611
 
                                  int4store((T),def_temp); \
612
 
                                  int4store((T+4),def_temp2); } while(0)
613
 
#ifdef WORDS_BIGENDIAN
614
 
#define float4store(T,A) do { *(T)= ((unsigned char *) &A)[3];\
615
 
                              *((T)+1)=(char) ((unsigned char *) &A)[2];\
616
 
                              *((T)+2)=(char) ((unsigned char *) &A)[1];\
617
 
                              *((T)+3)=(char) ((unsigned char *) &A)[0]; } while(0)
618
 
 
619
 
#define float4get(V,M)   do { float def_temp;\
620
 
                              ((unsigned char*) &def_temp)[0]=(M)[3];\
621
 
                              ((unsigned char*) &def_temp)[1]=(M)[2];\
622
 
                              ((unsigned char*) &def_temp)[2]=(M)[1];\
623
 
                              ((unsigned char*) &def_temp)[3]=(M)[0];\
624
 
                              (V)=def_temp; } while(0)
625
 
#define float8store(T,V) do { *(T)= ((unsigned char *) &V)[7];\
626
 
                              *((T)+1)=(char) ((unsigned char *) &V)[6];\
627
 
                              *((T)+2)=(char) ((unsigned char *) &V)[5];\
628
 
                              *((T)+3)=(char) ((unsigned char *) &V)[4];\
629
 
                              *((T)+4)=(char) ((unsigned char *) &V)[3];\
630
 
                              *((T)+5)=(char) ((unsigned char *) &V)[2];\
631
 
                              *((T)+6)=(char) ((unsigned char *) &V)[1];\
632
 
                              *((T)+7)=(char) ((unsigned char *) &V)[0]; } while(0)
633
 
 
634
 
#define float8get(V,M)   do { double def_temp;\
635
 
                              ((unsigned char*) &def_temp)[0]=(M)[7];\
636
 
                              ((unsigned char*) &def_temp)[1]=(M)[6];\
637
 
                              ((unsigned char*) &def_temp)[2]=(M)[5];\
638
 
                              ((unsigned char*) &def_temp)[3]=(M)[4];\
639
 
                              ((unsigned char*) &def_temp)[4]=(M)[3];\
640
 
                              ((unsigned char*) &def_temp)[5]=(M)[2];\
641
 
                              ((unsigned char*) &def_temp)[6]=(M)[1];\
642
 
                              ((unsigned char*) &def_temp)[7]=(M)[0];\
643
 
                              (V) = def_temp; } while(0)
644
 
#else
645
 
#define float4get(V,M)   memcpy(&V, (M), sizeof(float))
646
 
#define float4store(V,M) memcpy(V, (&M), sizeof(float))
647
 
 
648
 
#if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
649
 
#define doublestore(T,V) do { *(((char*)T)+0)=(char) ((unsigned char *) &V)[4];\
650
 
                              *(((char*)T)+1)=(char) ((unsigned char *) &V)[5];\
651
 
                              *(((char*)T)+2)=(char) ((unsigned char *) &V)[6];\
652
 
                              *(((char*)T)+3)=(char) ((unsigned char *) &V)[7];\
653
 
                              *(((char*)T)+4)=(char) ((unsigned char *) &V)[0];\
654
 
                              *(((char*)T)+5)=(char) ((unsigned char *) &V)[1];\
655
 
                              *(((char*)T)+6)=(char) ((unsigned char *) &V)[2];\
656
 
                              *(((char*)T)+7)=(char) ((unsigned char *) &V)[3]; }\
657
 
                         while(0)
658
 
#define doubleget(V,M)   do { double def_temp;\
659
 
                              ((unsigned char*) &def_temp)[0]=(M)[4];\
660
 
                              ((unsigned char*) &def_temp)[1]=(M)[5];\
661
 
                              ((unsigned char*) &def_temp)[2]=(M)[6];\
662
 
                              ((unsigned char*) &def_temp)[3]=(M)[7];\
663
 
                              ((unsigned char*) &def_temp)[4]=(M)[0];\
664
 
                              ((unsigned char*) &def_temp)[5]=(M)[1];\
665
 
                              ((unsigned char*) &def_temp)[6]=(M)[2];\
666
 
                              ((unsigned char*) &def_temp)[7]=(M)[3];\
667
 
                              (V) = def_temp; } while(0)
668
 
#endif /* __FLOAT_WORD_ORDER */
669
 
 
670
 
#define float8get(V,M)   doubleget((V),(M))
671
 
#define float8store(V,M) doublestore((V),(M))
672
 
#endif /* WORDS_BIGENDIAN */
673
 
 
674
 
#endif /* __i386__ */
675
 
 
676
 
/*
677
 
  Macro for reading 32-bit integer from network byte order (big-endian)
678
 
  from unaligned memory location.
679
 
*/
680
 
#define int4net(A)        (int32_t) (((uint32_t) ((unsigned char) (A)[3]))        |\
681
 
                                  (((uint32_t) ((unsigned char) (A)[2])) << 8)  |\
682
 
                                  (((uint32_t) ((unsigned char) (A)[1])) << 16) |\
683
 
                                  (((uint32_t) ((unsigned char) (A)[0])) << 24))
684
 
/*
685
 
  Define-funktions for reading and storing in machine format from/to
686
 
  short/long to/from some place in memory V should be a (not
687
 
  register) variable, M is a pointer to byte
688
 
*/
689
 
 
690
 
#ifdef WORDS_BIGENDIAN
691
 
 
692
 
#define ushortget(V,M)  do { V = (uint16_t) (((uint16_t) ((unsigned char) (M)[1]))+\
693
 
                                 ((uint16_t) ((uint16_t) (M)[0]) << 8)); } while(0)
694
 
#define shortget(V,M)   do { V = (short) (((short) ((unsigned char) (M)[1]))+\
695
 
                                 ((short) ((short) (M)[0]) << 8)); } while(0)
696
 
#define longget(V,M)    do { int32_t def_temp;\
697
 
                             ((unsigned char*) &def_temp)[0]=(M)[0];\
698
 
                             ((unsigned char*) &def_temp)[1]=(M)[1];\
699
 
                             ((unsigned char*) &def_temp)[2]=(M)[2];\
700
 
                             ((unsigned char*) &def_temp)[3]=(M)[3];\
701
 
                             (V)=def_temp; } while(0)
702
 
#define ulongget(V,M)   do { uint32_t def_temp;\
703
 
                            ((unsigned char*) &def_temp)[0]=(M)[0];\
704
 
                            ((unsigned char*) &def_temp)[1]=(M)[1];\
705
 
                            ((unsigned char*) &def_temp)[2]=(M)[2];\
706
 
                            ((unsigned char*) &def_temp)[3]=(M)[3];\
707
 
                            (V)=def_temp; } while(0)
708
 
#define shortstore(T,A) do { uint32_t def_temp=(uint32_t) (A) ;\
709
 
                             *(((char*)T)+1)=(char)(def_temp); \
710
 
                             *(((char*)T)+0)=(char)(def_temp >> 8); } while(0)
711
 
#define longstore(T,A)  do { *(((char*)T)+3)=((A));\
712
 
                             *(((char*)T)+2)=(((A) >> 8));\
713
 
                             *(((char*)T)+1)=(((A) >> 16));\
714
 
                             *(((char*)T)+0)=(((A) >> 24)); } while(0)
715
 
 
716
 
#define floatget(V,M)     memcpy(&V, (M), sizeof(float))
717
 
#define floatstore(T, V)   memcpy((T), (&V), sizeof(float))
718
 
#define doubleget(V, M)   memcpy(&V, (M), sizeof(double))
719
 
#define doublestore(T, V)  memcpy((T), &V, sizeof(double))
720
 
#define int64_tget(V, M)   memcpy(&V, (M), sizeof(uint64_t))
721
 
#define int64_tstore(T, V) memcpy((T), &V, sizeof(uint64_t))
722
 
 
723
 
#else
724
 
 
725
 
#define ushortget(V,M)  do { V = uint2korr(M); } while(0)
726
 
#define shortget(V,M)   do { V = sint2korr(M); } while(0)
727
 
#define longget(V,M)    do { V = sint4korr(M); } while(0)
728
 
#define ulongget(V,M)   do { V = uint4korr(M); } while(0)
729
 
#define shortstore(T,V) int2store(T,V)
730
 
#define longstore(T,V)  int4store(T,V)
731
 
#ifndef floatstore
732
 
#define floatstore(T,V)   memcpy((T), (&V), sizeof(float))
733
 
#define floatget(V,M)     memcpy(&V, (M), sizeof(float))
 
458
char *get_tty_password(const char *opt_message);
 
459
const char *mysql_errno_to_sqlstate(unsigned int mysql_errno);
 
460
 
 
461
 
 
462
#ifdef _global_h
 
463
ulong STDCALL net_field_length(uchar **packet);
 
464
uint64_t net_field_length_ll(uchar **packet);
 
465
uchar *net_store_length(uchar *pkg, uint64_t length);
734
466
#endif
735
 
#ifndef doubleget
736
 
#define doubleget(V, M)   memcpy(&V, (M), sizeof(double))
737
 
#define doublestore(T,V)  memcpy((T), &V, sizeof(double))
738
 
#endif /* doubleget */
739
 
#define int64_tget(V,M)   memcpy(&V, (M), sizeof(uint64_t))
740
 
#define int64_tstore(T,V) memcpy((T), &V, sizeof(uint64_t))
741
 
 
742
 
#endif /* WORDS_BIGENDIAN */
743
 
 
744
467
 
745
468
#ifdef __cplusplus
746
469
}
747
470
#endif
748
471
 
749
 
#define NULL_LENGTH UINT32_MAX /* For net_store_length */
750
 
#define DRIZZLE_STMT_HEADER       4
751
 
#define DRIZZLE_LONG_DATA_HEADER  6
 
472
#define NULL_LENGTH ((unsigned long) ~0) /* For net_store_length */
 
473
#define MYSQL_STMT_HEADER       4
 
474
#define MYSQL_LONG_DATA_HEADER  6
752
475
 
753
476
#endif