~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to include/drizzle_com.h

  • Committer: Brian Aker
  • Date: 2008-07-14 16:24:25 UTC
  • Revision ID: brian@tangent.org-20080714162425-juw3vw221gs9kysh
Cleanup around intptr_t

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
142
57
enum enum_server_command
143
58
{
144
59
  COM_SLEEP, COM_QUIT, COM_INIT_DB, COM_QUERY, COM_FIELD_LIST,
145
 
  COM_CREATE_DB, COM_DROP_DB, COM_REFRESH, COM_SHUTDOWN,
146
 
  COM_PROCESS_INFO, COM_CONNECT, COM_PROCESS_KILL, COM_PING,
147
 
  COM_TIME, COM_CHANGE_USER, COM_BINLOG_DUMP,
148
 
  COM_CONNECT_OUT, COM_REGISTER_SLAVE,
149
 
  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,
150
66
  /* don't forget to update const char *command_name[] in sql_parse.cc */
151
67
 
152
68
  /* Must be last */
171
87
#define MULTIPLE_KEY_FLAG 8             /* Field is part of a key */
172
88
#define BLOB_FLAG       16              /* Field is a blob */
173
89
#define UNSIGNED_FLAG   32              /* Field is unsigned */
174
 
#define DECIMAL_FLAG    64              /* Field is zerofill */
 
90
#define ZEROFILL_FLAG   64              /* Field is zerofill */
175
91
#define BINARY_FLAG     128             /* Field is binary   */
176
92
 
177
93
/* The following are only sent to new clients */
223
139
#define CLIENT_ODBC             64      /* Odbc client */
224
140
#define CLIENT_LOCAL_FILES      128     /* Can use LOAD DATA LOCAL */
225
141
#define CLIENT_IGNORE_SPACE     256     /* Ignore spaces before '(' */
226
 
#define UNUSED_CLIENT_PROTOCOL_41       512     /* New 4.1 protocol */
 
142
#define CLIENT_PROTOCOL_41      512     /* New 4.1 protocol */
227
143
#define CLIENT_INTERACTIVE      1024    /* This is an interactive client */
228
144
#define CLIENT_SSL              2048    /* Switch to SSL after handshake */
229
145
#define CLIENT_IGNORE_SIGPIPE   4096    /* IGNORE sigpipes */
246
162
                           CLIENT_ODBC | \
247
163
                           CLIENT_LOCAL_FILES | \
248
164
                           CLIENT_IGNORE_SPACE | \
 
165
                           CLIENT_PROTOCOL_41 | \
249
166
                           CLIENT_INTERACTIVE | \
250
167
                           CLIENT_SSL | \
251
168
                           CLIENT_IGNORE_SIGPIPE | \
291
208
*/
292
209
#define SERVER_QUERY_WAS_SLOW           1024
293
210
 
294
 
#define DRIZZLE_ERRMSG_SIZE     512
 
211
#define MYSQL_ERRMSG_SIZE       512
295
212
#define NET_READ_TIMEOUT        30              /* Timeout on read */
296
213
#define NET_WRITE_TIMEOUT       60              /* Timeout on write */
297
214
#define NET_WAIT_TIMEOUT        8*60*60         /* Wait for new query */
309
226
#define MAX_CHAR_WIDTH          255     /* Max length for a CHAR colum */
310
227
#define MAX_BLOB_WIDTH          16777216        /* Default width for blob */
311
228
 
312
 
#define DRIZZLE_PROTOCOL_NO_MORE_DATA 0xFE
313
 
 
314
 
 
 
229
typedef struct st_net {
 
230
#if !defined(CHECK_EMBEDDED_DIFFERENCES) || !defined(EMBEDDED_LIBRARY)
 
231
  Vio *vio;
 
232
  unsigned char *buff,*buff_end,*write_pos,*read_pos;
 
233
  my_socket fd;                                 /* For Perl DBI/dbd */
 
234
  /*
 
235
    The following variable is set if we are doing several queries in one
 
236
    command ( as in LOAD TABLE ... FROM MASTER ),
 
237
    and do not want to confuse the client with OK at the wrong time
 
238
  */
 
239
  unsigned long remain_in_buf,length, buf_length, where_b;
 
240
  unsigned long max_packet,max_packet_size;
 
241
  unsigned int pkt_nr,compress_pkt_nr;
 
242
  unsigned int write_timeout, read_timeout, retry_count;
 
243
  int fcntl;
 
244
  unsigned int *return_status;
 
245
  unsigned char reading_or_writing;
 
246
  char save_char;
 
247
  my_bool unused1; /* Please remove with the next incompatible ABI change. */
 
248
  my_bool unused2; /* Please remove with the next incompatible ABI change */
 
249
  my_bool compress;
 
250
  my_bool unused3; /* Please remove with the next incompatible ABI change. */
 
251
  /*
 
252
    Pointer to query object in query cache, do not equal NULL (0) for
 
253
    queries in cache that have not stored its results yet
 
254
  */
 
255
#endif
 
256
  /*
 
257
    Unused, please remove with the next incompatible ABI change.
 
258
  */
 
259
  unsigned char *unused;
 
260
  unsigned int last_errno;
 
261
  unsigned char error; 
 
262
  my_bool unused4; /* Please remove with the next incompatible ABI change. */
 
263
  my_bool unused5; /* Please remove with the next incompatible ABI change. */
 
264
  /** Client library error message buffer. Actually belongs to struct MYSQL. */
 
265
  char last_error[MYSQL_ERRMSG_SIZE];
 
266
  /** Client library sqlstate buffer. Set along with the error message. */
 
267
  char sqlstate[SQLSTATE_LENGTH+1];
 
268
  void *extension;
 
269
} NET;
315
270
 
316
271
 
317
272
#define packet_error (~(uint32_t) 0)
318
273
 
 
274
/* Start TINY at 1 because we removed DECIMAL from off the front of the enum */
 
275
enum enum_field_types { MYSQL_TYPE_TINY=1,
 
276
                        MYSQL_TYPE_SHORT,  MYSQL_TYPE_LONG,
 
277
                        MYSQL_TYPE_FLOAT,  MYSQL_TYPE_DOUBLE,
 
278
                        MYSQL_TYPE_NULL,   MYSQL_TYPE_TIMESTAMP,
 
279
                        MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24,
 
280
                        MYSQL_TYPE_DATE,   MYSQL_TYPE_TIME,
 
281
                        MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
 
282
                        MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
 
283
                        MYSQL_TYPE_NEWDECIMAL=250,
 
284
                        MYSQL_TYPE_ENUM=251,
 
285
                        MYSQL_TYPE_SET=252,
 
286
                        MYSQL_TYPE_BLOB=253,
 
287
                        MYSQL_TYPE_VAR_STRING=254,
 
288
                        MYSQL_TYPE_STRING=255
 
289
};
 
290
 
 
291
/* For backward compatibility */
 
292
#define CLIENT_MULTI_QUERIES    CLIENT_MULTI_STATEMENTS    
 
293
#define FIELD_TYPE_NEWDECIMAL  MYSQL_TYPE_NEWDECIMAL
 
294
#define FIELD_TYPE_TINY        MYSQL_TYPE_TINY
 
295
#define FIELD_TYPE_SHORT       MYSQL_TYPE_SHORT
 
296
#define FIELD_TYPE_LONG        MYSQL_TYPE_LONG
 
297
#define FIELD_TYPE_FLOAT       MYSQL_TYPE_FLOAT
 
298
#define FIELD_TYPE_DOUBLE      MYSQL_TYPE_DOUBLE
 
299
#define FIELD_TYPE_NULL        MYSQL_TYPE_NULL
 
300
#define FIELD_TYPE_TIMESTAMP   MYSQL_TYPE_TIMESTAMP
 
301
#define FIELD_TYPE_LONGLONG    MYSQL_TYPE_LONGLONG
 
302
#define FIELD_TYPE_TIME        MYSQL_TYPE_TIME
 
303
#define FIELD_TYPE_DATETIME    MYSQL_TYPE_DATETIME
 
304
#define FIELD_TYPE_YEAR        MYSQL_TYPE_YEAR
 
305
#define FIELD_TYPE_NEWDATE     MYSQL_TYPE_NEWDATE
 
306
#define FIELD_TYPE_ENUM        MYSQL_TYPE_ENUM
 
307
#define FIELD_TYPE_SET         MYSQL_TYPE_SET
 
308
#define FIELD_TYPE_TINY_BLOB   MYSQL_TYPE_TINY_BLOB
 
309
#define FIELD_TYPE_BLOB        MYSQL_TYPE_BLOB
 
310
#define FIELD_TYPE_VAR_STRING  MYSQL_TYPE_VAR_STRING
 
311
#define FIELD_TYPE_STRING      MYSQL_TYPE_STRING
 
312
#define FIELD_TYPE_CHAR        MYSQL_TYPE_TINY
 
313
#define FIELD_TYPE_INTERVAL    MYSQL_TYPE_ENUM
 
314
 
319
315
 
320
316
/* Shutdown/kill enums and constants */ 
321
317
 
322
318
/* Bits for THD::killable. */
323
 
#define DRIZZLE_SHUTDOWN_KILLABLE_CONNECT    (unsigned char)(1 << 0)
324
 
#define DRIZZLE_SHUTDOWN_KILLABLE_TRANS      (unsigned char)(1 << 1)
325
 
#define DRIZZLE_SHUTDOWN_KILLABLE_LOCK_TABLE (unsigned char)(1 << 2)
326
 
#define DRIZZLE_SHUTDOWN_KILLABLE_UPDATE     (unsigned char)(1 << 3)
 
319
#define MYSQL_SHUTDOWN_KILLABLE_CONNECT    (unsigned char)(1 << 0)
 
320
#define MYSQL_SHUTDOWN_KILLABLE_TRANS      (unsigned char)(1 << 1)
 
321
#define MYSQL_SHUTDOWN_KILLABLE_LOCK_TABLE (unsigned char)(1 << 2)
 
322
#define MYSQL_SHUTDOWN_KILLABLE_UPDATE     (unsigned char)(1 << 3)
327
323
 
328
 
/* Start TINY at 1 because we removed DECIMAL from off the front of the enum */
329
 
enum enum_field_types { DRIZZLE_TYPE_TINY=1,
330
 
                        DRIZZLE_TYPE_LONG,
331
 
                        DRIZZLE_TYPE_DOUBLE,
332
 
                        DRIZZLE_TYPE_NULL,   DRIZZLE_TYPE_TIMESTAMP,
333
 
                        DRIZZLE_TYPE_LONGLONG,
334
 
                        DRIZZLE_TYPE_TIME,
335
 
                        DRIZZLE_TYPE_DATETIME,
336
 
                        DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_VARCHAR,
337
 
                        DRIZZLE_TYPE_NEWDECIMAL=253,
338
 
                        DRIZZLE_TYPE_ENUM=254,
339
 
                        DRIZZLE_TYPE_BLOB=255
 
324
enum mysql_enum_shutdown_level {
 
325
  /*
 
326
    We want levels to be in growing order of hardness (because we use number
 
327
    comparisons). Note that DEFAULT does not respect the growing property, but
 
328
    it's ok.
 
329
  */
 
330
  SHUTDOWN_DEFAULT = 0,
 
331
  /* wait for existing connections to finish */
 
332
  SHUTDOWN_WAIT_CONNECTIONS= MYSQL_SHUTDOWN_KILLABLE_CONNECT,
 
333
  /* wait for existing trans to finish */
 
334
  SHUTDOWN_WAIT_TRANSACTIONS= MYSQL_SHUTDOWN_KILLABLE_TRANS,
 
335
  /* wait for existing updates to finish (=> no partial MyISAM update) */
 
336
  SHUTDOWN_WAIT_UPDATES= MYSQL_SHUTDOWN_KILLABLE_UPDATE,
 
337
  /* flush InnoDB buffers and other storage engines' buffers*/
 
338
  SHUTDOWN_WAIT_ALL_BUFFERS= (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1),
 
339
  /* don't flush InnoDB buffers, flush other storage engines' buffers*/
 
340
  SHUTDOWN_WAIT_CRITICAL_BUFFERS= (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1) + 1,
 
341
  /* Now the 2 levels of the KILL command */
 
342
  KILL_QUERY= 254,
 
343
  KILL_CONNECTION= 255
340
344
};
341
345
 
342
346
 
350
354
 
351
355
 
352
356
/* options for mysql_set_option */
353
 
enum enum_drizzle_set_option
 
357
enum enum_mysql_set_option
354
358
{
355
 
  DRIZZLE_OPTION_MULTI_STATEMENTS_ON,
356
 
  DRIZZLE_OPTION_MULTI_STATEMENTS_OFF
 
359
  MYSQL_OPTION_MULTI_STATEMENTS_ON,
 
360
  MYSQL_OPTION_MULTI_STATEMENTS_OFF
357
361
};
358
362
 
359
363
#define net_new_transaction(net) ((net)->pkt_nr=0)
362
366
extern "C" {
363
367
#endif
364
368
 
365
 
 
366
 
  struct rand_struct {
367
 
    unsigned long seed1,seed2,max_value;
368
 
    double max_value_dbl;
369
 
  };
 
369
my_bool my_net_init(NET *net, Vio* vio);
 
370
void    my_net_local_init(NET *net);
 
371
void    net_end(NET *net);
 
372
  void  net_clear(NET *net, my_bool clear_buffer);
 
373
my_bool net_realloc(NET *net, size_t length);
 
374
my_bool net_flush(NET *net);
 
375
my_bool my_net_write(NET *net,const unsigned char *packet, size_t len);
 
376
my_bool net_write_command(NET *net,unsigned char command,
 
377
                          const unsigned char *header, size_t head_len,
 
378
                          const unsigned char *packet, size_t len);
 
379
int     net_real_write(NET *net,const unsigned char *packet, size_t len);
 
380
unsigned long my_net_read(NET *net);
 
381
 
 
382
#ifdef _global_h
 
383
void my_net_set_write_timeout(NET *net, uint timeout);
 
384
void my_net_set_read_timeout(NET *net, uint timeout);
 
385
#endif
 
386
 
 
387
struct sockaddr;
 
388
int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen,
 
389
               unsigned int timeout);
 
390
 
 
391
struct rand_struct {
 
392
  unsigned long seed1,seed2,max_value;
 
393
  double max_value_dbl;
 
394
};
370
395
 
371
396
#ifdef __cplusplus
372
397
}
393
418
 
394
419
typedef struct st_udf_init
395
420
{
396
 
  bool maybe_null;          /* 1 if function can return NULL */
 
421
  my_bool maybe_null;          /* 1 if function can return NULL */
397
422
  unsigned int decimals;       /* for real functions */
398
423
  unsigned long max_length;    /* For string functions */
399
424
  char *ptr;                   /* free pointer for function data */
400
 
  bool const_item;          /* 1 if function always returns the same value */
 
425
  my_bool const_item;          /* 1 if function always returns the same value */
401
426
  void *extension;
402
427
} UDF_INIT;
403
428
/* 
420
445
  implemented in sql/password.c
421
446
*/
422
447
 
423
 
  void randominit(struct rand_struct *, uint32_t seed1, uint32_t seed2);
424
 
  double my_rnd(struct rand_struct *);
425
 
  void create_random_string(char *to, unsigned int length,
426
 
                            struct rand_struct *rand_st);
427
 
 
428
 
  void hash_password(uint32_t *to, const char *password, uint32_t password_len);
429
 
 
430
 
  void make_scrambled_password(char *to, const char *password);
431
 
  void scramble(char *to, const char *message, const char *password);
432
 
  bool check_scramble(const char *reply, const char *message,
433
 
                      const unsigned char *hash_stage2);
434
 
  void get_salt_from_password(unsigned char *res, const char *password);
435
 
  void make_password_from_salt(char *to, const unsigned char *hash_stage2);
436
 
  char *octet2hex(char *to, const char *str, unsigned int len);
 
448
void randominit(struct rand_struct *, unsigned long seed1,
 
449
                unsigned long seed2);
 
450
double my_rnd(struct rand_struct *);
 
451
void create_random_string(char *to, unsigned int length, struct rand_struct *rand_st);
 
452
 
 
453
void hash_password(unsigned long *to, const char *password, unsigned int password_len);
 
454
void make_scrambled_password_323(char *to, const char *password);
 
455
void scramble_323(char *to, const char *message, const char *password);
 
456
my_bool check_scramble_323(const char *, const char *message,
 
457
                           unsigned long *salt);
 
458
void get_salt_from_password_323(unsigned long *res, const char *password);
 
459
void make_password_from_salt_323(char *to, const unsigned long *salt);
 
460
 
 
461
void make_scrambled_password(char *to, const char *password);
 
462
void scramble(char *to, const char *message, const char *password);
 
463
my_bool check_scramble(const char *reply, const char *message,
 
464
                       const unsigned char *hash_stage2);
 
465
void get_salt_from_password(unsigned char *res, const char *password);
 
466
void make_password_from_salt(char *to, const unsigned char *hash_stage2);
 
467
char *octet2hex(char *to, const char *str, unsigned int len);
437
468
 
438
469
/* end of password.c */
439
470
 
440
 
  char *get_tty_password(const char *opt_message);
441
 
 
442
 
  uint32_t net_field_length(unsigned char **packet);
443
 
  uint64_t net_field_length_ll(unsigned char **packet);
444
 
  unsigned char *net_store_length(unsigned char *pkg, uint64_t length);
445
 
 
446
 
/*
447
 
  Define-funktions for reading and storing in machine independent format
448
 
  (low byte first)
449
 
*/
450
 
 
451
 
/* Optimized store functions for Intel x86 */
452
 
#if defined(__i386__)
453
 
#define sint2korr(A)    (*((int16_t *) (A)))
454
 
#define sint3korr(A)    ((int32_t) ((((unsigned char) (A)[2]) & 128) ? \
455
 
                                  (((uint32_t) 255L << 24) | \
456
 
                                   (((uint32_t) (unsigned char) (A)[2]) << 16) |\
457
 
                                   (((uint32_t) (unsigned char) (A)[1]) << 8) | \
458
 
                                   ((uint32_t) (unsigned char) (A)[0])) : \
459
 
                                  (((uint32_t) (unsigned char) (A)[2]) << 16) |\
460
 
                                  (((uint32_t) (unsigned char) (A)[1]) << 8) | \
461
 
                                  ((uint32_t) (unsigned char) (A)[0])))
462
 
#define sint4korr(A)    (*((long *) (A)))
463
 
#define uint2korr(A)    (*((uint16_t *) (A)))
464
 
#if defined(HAVE_purify)
465
 
#define uint3korr(A)    (uint32_t) (((uint32_t) ((unsigned char) (A)[0])) +\
466
 
                                  (((uint32_t) ((unsigned char) (A)[1])) << 8) +\
467
 
                                  (((uint32_t) ((unsigned char) (A)[2])) << 16))
468
 
#else
469
 
/*
470
 
   ATTENTION !
471
 
   
472
 
    Please, note, uint3korr reads 4 bytes (not 3) !
473
 
    It means, that you have to provide enough allocated space !
474
 
*/
475
 
#define uint3korr(A)    (long) (*((unsigned int *) (A)) & 0xFFFFFF)
476
 
#endif /* HAVE_purify */
477
 
#define uint4korr(A)    (*((uint32_t *) (A)))
478
 
#define uint5korr(A)    ((uint64_t)(((uint32_t) ((unsigned char) (A)[0])) +\
479
 
                                    (((uint32_t) ((unsigned char) (A)[1])) << 8) +\
480
 
                                    (((uint32_t) ((unsigned char) (A)[2])) << 16) +\
481
 
                                    (((uint32_t) ((unsigned char) (A)[3])) << 24)) +\
482
 
                                    (((uint64_t) ((unsigned char) (A)[4])) << 32))
483
 
#define uint6korr(A)    ((uint64_t)(((uint32_t)    ((unsigned char) (A)[0]))          + \
484
 
                                     (((uint32_t)    ((unsigned char) (A)[1])) << 8)   + \
485
 
                                     (((uint32_t)    ((unsigned char) (A)[2])) << 16)  + \
486
 
                                     (((uint32_t)    ((unsigned char) (A)[3])) << 24)) + \
487
 
                         (((uint64_t) ((unsigned char) (A)[4])) << 32) +       \
488
 
                         (((uint64_t) ((unsigned char) (A)[5])) << 40))
489
 
#define uint8korr(A)    (*((uint64_t *) (A)))
490
 
#define sint8korr(A)    (*((int64_t *) (A)))
491
 
#define int2store(T,A)  *((uint16_t*) (T))= (uint16_t) (A)
492
 
#define int3store(T,A)  do { *(T)=  (unsigned char) ((A));\
493
 
                            *(T+1)=(unsigned char) (((uint32_t) (A) >> 8));\
494
 
                            *(T+2)=(unsigned char) (((A) >> 16)); } while (0)
495
 
#define int4store(T,A)  *((long *) (T))= (long) (A)
496
 
#define int5store(T,A)  do { *(T)= (unsigned char)((A));\
497
 
                             *((T)+1)=(unsigned char) (((A) >> 8));\
498
 
                             *((T)+2)=(unsigned char) (((A) >> 16));\
499
 
                             *((T)+3)=(unsigned char) (((A) >> 24)); \
500
 
                             *((T)+4)=(unsigned char) (((A) >> 32)); } while(0)
501
 
#define int6store(T,A)  do { *(T)=    (unsigned char)((A));          \
502
 
                             *((T)+1)=(unsigned char) (((A) >> 8));  \
503
 
                             *((T)+2)=(unsigned char) (((A) >> 16)); \
504
 
                             *((T)+3)=(unsigned char) (((A) >> 24)); \
505
 
                             *((T)+4)=(unsigned char) (((A) >> 32)); \
506
 
                             *((T)+5)=(unsigned char) (((A) >> 40)); } while(0)
507
 
#define int8store(T,A)  *((uint64_t *) (T))= (uint64_t) (A)
508
 
 
509
 
typedef union {
510
 
  double v;
511
 
  long m[2];
512
 
} doubleget_union;
513
 
#define doubleget(V,M)  \
514
 
do { doubleget_union _tmp; \
515
 
     _tmp.m[0] = *((long*)(M)); \
516
 
     _tmp.m[1] = *(((long*) (M))+1); \
517
 
     (V) = _tmp.v; } while(0)
518
 
#define doublestore(T,V) do { *((long *) T) = ((doubleget_union *)&V)->m[0]; \
519
 
                             *(((long *) T)+1) = ((doubleget_union *)&V)->m[1]; \
520
 
                         } while (0)
521
 
#define float4get(V,M)   do { *((float *) &(V)) = *((float*) (M)); } while(0)
522
 
#define float8get(V,M)   doubleget((V),(M))
523
 
#define float4store(V,M) memcpy(V, (&M), sizeof(float))
524
 
#define floatstore(T,V)  memcpy((T), (&V), sizeof(float))
525
 
#define floatget(V,M)    memcpy(&V, (M), sizeof(float))
526
 
#define float8store(V,M) doublestore((V),(M))
527
 
#else
528
 
 
529
 
/*
530
 
  We're here if it's not a IA-32 architecture (Win32 and UNIX IA-32 defines
531
 
  were done before)
532
 
*/
533
 
#define sint2korr(A)    (int16_t) (((int16_t) ((unsigned char) (A)[0])) +\
534
 
                                 ((int16_t) ((int16_t) (A)[1]) << 8))
535
 
#define sint3korr(A)    ((int32_t) ((((unsigned char) (A)[2]) & 128) ? \
536
 
                                  (((uint32_t) 255L << 24) | \
537
 
                                   (((uint32_t) (unsigned char) (A)[2]) << 16) |\
538
 
                                   (((uint32_t) (unsigned char) (A)[1]) << 8) | \
539
 
                                   ((uint32_t) (unsigned char) (A)[0])) : \
540
 
                                  (((uint32_t) (unsigned char) (A)[2]) << 16) |\
541
 
                                  (((uint32_t) (unsigned char) (A)[1]) << 8) | \
542
 
                                  ((uint32_t) (unsigned char) (A)[0])))
543
 
#define sint4korr(A)    (int32_t) (((int32_t) ((unsigned char) (A)[0])) +\
544
 
                                (((int32_t) ((unsigned char) (A)[1]) << 8)) +\
545
 
                                (((int32_t) ((unsigned char) (A)[2]) << 16)) +\
546
 
                                (((int32_t) ((int16_t) (A)[3]) << 24)))
547
 
#define sint8korr(A)    (int64_t) uint8korr(A)
548
 
#define uint2korr(A)    (uint16_t) (((uint16_t) ((unsigned char) (A)[0])) +\
549
 
                                  ((uint16_t) ((unsigned char) (A)[1]) << 8))
550
 
#define uint3korr(A)    (uint32_t) (((uint32_t) ((unsigned char) (A)[0])) +\
551
 
                                  (((uint32_t) ((unsigned char) (A)[1])) << 8) +\
552
 
                                  (((uint32_t) ((unsigned char) (A)[2])) << 16))
553
 
#define uint4korr(A)    (uint32_t) (((uint32_t) ((unsigned char) (A)[0])) +\
554
 
                                  (((uint32_t) ((unsigned char) (A)[1])) << 8) +\
555
 
                                  (((uint32_t) ((unsigned char) (A)[2])) << 16) +\
556
 
                                  (((uint32_t) ((unsigned char) (A)[3])) << 24))
557
 
#define uint5korr(A)    ((uint64_t)(((uint32_t) ((unsigned char) (A)[0])) +\
558
 
                                    (((uint32_t) ((unsigned char) (A)[1])) << 8) +\
559
 
                                    (((uint32_t) ((unsigned char) (A)[2])) << 16) +\
560
 
                                    (((uint32_t) ((unsigned char) (A)[3])) << 24)) +\
561
 
                                    (((uint64_t) ((unsigned char) (A)[4])) << 32))
562
 
#define uint6korr(A)    ((uint64_t)(((uint32_t)    ((unsigned char) (A)[0]))          + \
563
 
                                     (((uint32_t)    ((unsigned char) (A)[1])) << 8)   + \
564
 
                                     (((uint32_t)    ((unsigned char) (A)[2])) << 16)  + \
565
 
                                     (((uint32_t)    ((unsigned char) (A)[3])) << 24)) + \
566
 
                         (((uint64_t) ((unsigned char) (A)[4])) << 32) +       \
567
 
                         (((uint64_t) ((unsigned char) (A)[5])) << 40))
568
 
#define uint8korr(A)    ((uint64_t)(((uint32_t) ((unsigned char) (A)[0])) +\
569
 
                                    (((uint32_t) ((unsigned char) (A)[1])) << 8) +\
570
 
                                    (((uint32_t) ((unsigned char) (A)[2])) << 16) +\
571
 
                                    (((uint32_t) ((unsigned char) (A)[3])) << 24)) +\
572
 
                        (((uint64_t) (((uint32_t) ((unsigned char) (A)[4])) +\
573
 
                                    (((uint32_t) ((unsigned char) (A)[5])) << 8) +\
574
 
                                    (((uint32_t) ((unsigned char) (A)[6])) << 16) +\
575
 
                                    (((uint32_t) ((unsigned char) (A)[7])) << 24))) <<\
576
 
                                    32))
577
 
#define int2store(T,A)       do { uint32_t def_temp= (uint32_t) (A) ;\
578
 
                                  *((unsigned char*) (T))=  (unsigned char)(def_temp); \
579
 
                                   *((unsigned char*) (T)+1)=(unsigned char)((def_temp >> 8)); \
580
 
                             } while(0)
581
 
#define int3store(T,A)       do { /*lint -save -e734 */\
582
 
                                  *((unsigned char*)(T))=(unsigned char) ((A));\
583
 
                                  *((unsigned char*) (T)+1)=(unsigned char) (((A) >> 8));\
584
 
                                  *((unsigned char*)(T)+2)=(unsigned char) (((A) >> 16)); \
585
 
                                  /*lint -restore */} while(0)
586
 
#define int4store(T,A)       do { *((char *)(T))=(char) ((A));\
587
 
                                  *(((char *)(T))+1)=(char) (((A) >> 8));\
588
 
                                  *(((char *)(T))+2)=(char) (((A) >> 16));\
589
 
                                  *(((char *)(T))+3)=(char) (((A) >> 24)); } while(0)
590
 
#define int5store(T,A)       do { *((char *)(T))=     (char)((A));  \
591
 
                                  *(((char *)(T))+1)= (char)(((A) >> 8)); \
592
 
                                  *(((char *)(T))+2)= (char)(((A) >> 16)); \
593
 
                                  *(((char *)(T))+3)= (char)(((A) >> 24)); \
594
 
                                  *(((char *)(T))+4)= (char)(((A) >> 32)); \
595
 
                                } while(0)
596
 
#define int6store(T,A)       do { *((char *)(T))=     (char)((A)); \
597
 
                                  *(((char *)(T))+1)= (char)(((A) >> 8)); \
598
 
                                  *(((char *)(T))+2)= (char)(((A) >> 16)); \
599
 
                                  *(((char *)(T))+3)= (char)(((A) >> 24)); \
600
 
                                  *(((char *)(T))+4)= (char)(((A) >> 32)); \
601
 
                                  *(((char *)(T))+5)= (char)(((A) >> 40)); \
602
 
                                } while(0)
603
 
#define int8store(T,A)       do { uint32_t def_temp= (uint32_t) (A), def_temp2= (uint32_t) ((A) >> 32); \
604
 
                                  int4store((T),def_temp); \
605
 
                                  int4store((T+4),def_temp2); } while(0)
606
 
#ifdef WORDS_BIGENDIAN
607
 
#define float4store(T,A) do { *(T)= ((unsigned char *) &A)[3];\
608
 
                              *((T)+1)=(char) ((unsigned char *) &A)[2];\
609
 
                              *((T)+2)=(char) ((unsigned char *) &A)[1];\
610
 
                              *((T)+3)=(char) ((unsigned char *) &A)[0]; } while(0)
611
 
 
612
 
#define float4get(V,M)   do { float def_temp;\
613
 
                              ((unsigned char*) &def_temp)[0]=(M)[3];\
614
 
                              ((unsigned char*) &def_temp)[1]=(M)[2];\
615
 
                              ((unsigned char*) &def_temp)[2]=(M)[1];\
616
 
                              ((unsigned char*) &def_temp)[3]=(M)[0];\
617
 
                              (V)=def_temp; } while(0)
618
 
#define float8store(T,V) do { *(T)= ((unsigned char *) &V)[7];\
619
 
                              *((T)+1)=(char) ((unsigned char *) &V)[6];\
620
 
                              *((T)+2)=(char) ((unsigned char *) &V)[5];\
621
 
                              *((T)+3)=(char) ((unsigned char *) &V)[4];\
622
 
                              *((T)+4)=(char) ((unsigned char *) &V)[3];\
623
 
                              *((T)+5)=(char) ((unsigned char *) &V)[2];\
624
 
                              *((T)+6)=(char) ((unsigned char *) &V)[1];\
625
 
                              *((T)+7)=(char) ((unsigned char *) &V)[0]; } while(0)
626
 
 
627
 
#define float8get(V,M)   do { double def_temp;\
628
 
                              ((unsigned char*) &def_temp)[0]=(M)[7];\
629
 
                              ((unsigned char*) &def_temp)[1]=(M)[6];\
630
 
                              ((unsigned char*) &def_temp)[2]=(M)[5];\
631
 
                              ((unsigned char*) &def_temp)[3]=(M)[4];\
632
 
                              ((unsigned char*) &def_temp)[4]=(M)[3];\
633
 
                              ((unsigned char*) &def_temp)[5]=(M)[2];\
634
 
                              ((unsigned char*) &def_temp)[6]=(M)[1];\
635
 
                              ((unsigned char*) &def_temp)[7]=(M)[0];\
636
 
                              (V) = def_temp; } while(0)
637
 
#else
638
 
#define float4get(V,M)   memcpy(&V, (M), sizeof(float))
639
 
#define float4store(V,M) memcpy(V, (&M), sizeof(float))
640
 
 
641
 
#if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
642
 
#define doublestore(T,V) do { *(((char*)T)+0)=(char) ((unsigned char *) &V)[4];\
643
 
                              *(((char*)T)+1)=(char) ((unsigned char *) &V)[5];\
644
 
                              *(((char*)T)+2)=(char) ((unsigned char *) &V)[6];\
645
 
                              *(((char*)T)+3)=(char) ((unsigned char *) &V)[7];\
646
 
                              *(((char*)T)+4)=(char) ((unsigned char *) &V)[0];\
647
 
                              *(((char*)T)+5)=(char) ((unsigned char *) &V)[1];\
648
 
                              *(((char*)T)+6)=(char) ((unsigned char *) &V)[2];\
649
 
                              *(((char*)T)+7)=(char) ((unsigned char *) &V)[3]; }\
650
 
                         while(0)
651
 
#define doubleget(V,M)   do { double def_temp;\
652
 
                              ((unsigned char*) &def_temp)[0]=(M)[4];\
653
 
                              ((unsigned char*) &def_temp)[1]=(M)[5];\
654
 
                              ((unsigned char*) &def_temp)[2]=(M)[6];\
655
 
                              ((unsigned char*) &def_temp)[3]=(M)[7];\
656
 
                              ((unsigned char*) &def_temp)[4]=(M)[0];\
657
 
                              ((unsigned char*) &def_temp)[5]=(M)[1];\
658
 
                              ((unsigned char*) &def_temp)[6]=(M)[2];\
659
 
                              ((unsigned char*) &def_temp)[7]=(M)[3];\
660
 
                              (V) = def_temp; } while(0)
661
 
#endif /* __FLOAT_WORD_ORDER */
662
 
 
663
 
#define float8get(V,M)   doubleget((V),(M))
664
 
#define float8store(V,M) doublestore((V),(M))
665
 
#endif /* WORDS_BIGENDIAN */
666
 
 
667
 
#endif /* __i386__ */
668
 
 
669
 
/*
670
 
  Macro for reading 32-bit integer from network byte order (big-endian)
671
 
  from unaligned memory location.
672
 
*/
673
 
#define int4net(A)        (int32_t) (((uint32_t) ((unsigned char) (A)[3]))        |\
674
 
                                  (((uint32_t) ((unsigned char) (A)[2])) << 8)  |\
675
 
                                  (((uint32_t) ((unsigned char) (A)[1])) << 16) |\
676
 
                                  (((uint32_t) ((unsigned char) (A)[0])) << 24))
677
 
/*
678
 
  Define-funktions for reading and storing in machine format from/to
679
 
  short/long to/from some place in memory V should be a (not
680
 
  register) variable, M is a pointer to byte
681
 
*/
682
 
 
683
 
#ifdef WORDS_BIGENDIAN
684
 
 
685
 
#define ushortget(V,M)  do { V = (uint16_t) (((uint16_t) ((unsigned char) (M)[1]))+\
686
 
                                 ((uint16_t) ((uint16_t) (M)[0]) << 8)); } while(0)
687
 
#define shortget(V,M)   do { V = (short) (((short) ((unsigned char) (M)[1]))+\
688
 
                                 ((short) ((short) (M)[0]) << 8)); } while(0)
689
 
#define longget(V,M)    do { int32_t def_temp;\
690
 
                             ((unsigned char*) &def_temp)[0]=(M)[0];\
691
 
                             ((unsigned char*) &def_temp)[1]=(M)[1];\
692
 
                             ((unsigned char*) &def_temp)[2]=(M)[2];\
693
 
                             ((unsigned char*) &def_temp)[3]=(M)[3];\
694
 
                             (V)=def_temp; } while(0)
695
 
#define ulongget(V,M)   do { uint32_t def_temp;\
696
 
                            ((unsigned char*) &def_temp)[0]=(M)[0];\
697
 
                            ((unsigned char*) &def_temp)[1]=(M)[1];\
698
 
                            ((unsigned char*) &def_temp)[2]=(M)[2];\
699
 
                            ((unsigned char*) &def_temp)[3]=(M)[3];\
700
 
                            (V)=def_temp; } while(0)
701
 
#define shortstore(T,A) do { uint32_t def_temp=(uint32_t) (A) ;\
702
 
                             *(((char*)T)+1)=(char)(def_temp); \
703
 
                             *(((char*)T)+0)=(char)(def_temp >> 8); } while(0)
704
 
#define longstore(T,A)  do { *(((char*)T)+3)=((A));\
705
 
                             *(((char*)T)+2)=(((A) >> 8));\
706
 
                             *(((char*)T)+1)=(((A) >> 16));\
707
 
                             *(((char*)T)+0)=(((A) >> 24)); } while(0)
708
 
 
709
 
#define floatget(V,M)     memcpy(&V, (M), sizeof(float))
710
 
#define floatstore(T, V)   memcpy((T), (&V), sizeof(float))
711
 
#define doubleget(V, M)   memcpy(&V, (M), sizeof(double))
712
 
#define doublestore(T, V)  memcpy((T), &V, sizeof(double))
713
 
#define int64_tget(V, M)   memcpy(&V, (M), sizeof(uint64_t))
714
 
#define int64_tstore(T, V) memcpy((T), &V, sizeof(uint64_t))
715
 
 
716
 
#else
717
 
 
718
 
#define ushortget(V,M)  do { V = uint2korr(M); } while(0)
719
 
#define shortget(V,M)   do { V = sint2korr(M); } while(0)
720
 
#define longget(V,M)    do { V = sint4korr(M); } while(0)
721
 
#define ulongget(V,M)   do { V = uint4korr(M); } while(0)
722
 
#define shortstore(T,V) int2store(T,V)
723
 
#define longstore(T,V)  int4store(T,V)
724
 
#ifndef floatstore
725
 
#define floatstore(T,V)   memcpy((T), (&V), sizeof(float))
726
 
#define floatget(V,M)     memcpy(&V, (M), sizeof(float))
 
471
char *get_tty_password(const char *opt_message);
 
472
const char *mysql_errno_to_sqlstate(unsigned int mysql_errno);
 
473
 
 
474
 
 
475
#ifdef _global_h
 
476
ulong STDCALL net_field_length(uchar **packet);
 
477
uint64_t net_field_length_ll(uchar **packet);
 
478
uchar *net_store_length(uchar *pkg, uint64_t length);
727
479
#endif
728
 
#ifndef doubleget
729
 
#define doubleget(V, M)   memcpy(&V, (M), sizeof(double))
730
 
#define doublestore(T,V)  memcpy((T), &V, sizeof(double))
731
 
#endif /* doubleget */
732
 
#define int64_tget(V,M)   memcpy(&V, (M), sizeof(uint64_t))
733
 
#define int64_tstore(T,V) memcpy((T), &V, sizeof(uint64_t))
734
 
 
735
 
#endif /* WORDS_BIGENDIAN */
736
 
 
737
480
 
738
481
#ifdef __cplusplus
739
482
}
740
483
#endif
741
484
 
742
 
#define NULL_LENGTH UINT32_MAX /* For net_store_length */
743
 
#define DRIZZLE_STMT_HEADER       4
744
 
#define DRIZZLE_LONG_DATA_HEADER  6
 
485
#define NULL_LENGTH ((unsigned long) ~0) /* For net_store_length */
 
486
#define MYSQL_STMT_HEADER       4
 
487
#define MYSQL_LONG_DATA_HEADER  6
745
488
 
746
489
#endif