1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
/* $%BEGINLICENSE%$
Copyright (C) 2007-2008 MySQL AB, 2008 Sun Microsystems, Inc
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; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
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
$%ENDLICENSE%$ */
#ifndef _NETWORK_MYSQLD_PROTO_H_
#define _NETWORK_MYSQLD_PROTO_H_
#include <glib.h>
#ifdef _WIN32
/* mysql.h needs SOCKET defined */
#include <winsock2.h>
#endif
#include <mysql.h>
#include "network-exports.h"
/**
* 4.0 is missing too many things for us to support it, so we have to error out.
*/
#if MYSQL_VERSION_ID < 41000
#error You need at least MySQL 4.1 to compile this software.
#endif
/**
* 4.1 uses other defines
*
* this should be one step to get closer to backward-compatibility
*/
#if MYSQL_VERSION_ID < 50000
#define COM_STMT_EXECUTE COM_EXECUTE
#define COM_STMT_PREPARE COM_PREPARE
#define COM_STMT_CLOSE COM_CLOSE_STMT
#define COM_STMT_SEND_LONG_DATA COM_LONG_DATA
#define COM_STMT_RESET COM_RESET_STMT
#endif
#define MYSQLD_PACKET_OK (0)
#define MYSQLD_PACKET_RAW (0xfa) /* used for proxy.response.type only */
#define MYSQLD_PACKET_NULL (0xfb) /* 0xfb */
/* 0xfc */
/* 0xfd */
#define MYSQLD_PACKET_EOF (0xfe) /* 0xfe */
#define MYSQLD_PACKET_ERR (0xff) /* 0xff */
#define PACKET_LEN_MAX (0x00ffffff)
typedef struct {
GString *data;
guint offset;
} network_packet;
NETWORK_API network_packet *network_packet_new(void);
NETWORK_API void network_packet_free(network_packet *packet);
typedef enum {
NETWORK_MYSQLD_LENENC_TYPE_INT,
NETWORK_MYSQLD_LENENC_TYPE_NULL,
NETWORK_MYSQLD_LENENC_TYPE_EOF,
NETWORK_MYSQLD_LENENC_TYPE_ERR
} network_mysqld_lenenc_type;
NETWORK_API int network_mysqld_proto_skip(network_packet *packet, gsize size);
NETWORK_API int network_mysqld_proto_skip_network_header(network_packet *packet);
NETWORK_API int network_mysqld_proto_get_int_len(network_packet *packet, guint64 *v, gsize size);
NETWORK_API int network_mysqld_proto_get_int8(network_packet *packet, guint8 *v);
NETWORK_API int network_mysqld_proto_get_int16(network_packet *packet, guint16 *v);
NETWORK_API int network_mysqld_proto_get_int24(network_packet *packet, guint32 *v);
NETWORK_API int network_mysqld_proto_get_int32(network_packet *packet, guint32 *v);
NETWORK_API int network_mysqld_proto_get_int48(network_packet *packet, guint64 *v);
NETWORK_API int network_mysqld_proto_get_int64(network_packet *packet, guint64 *v);
NETWORK_API int network_mysqld_proto_peek_int_len(network_packet *packet, guint64 *v, gsize size);
NETWORK_API int network_mysqld_proto_peek_int8(network_packet *packet, guint8 *v);
NETWORK_API int network_mysqld_proto_peek_int16(network_packet *packet, guint16 *v);
NETWORK_API int network_mysqld_proto_find_int8(network_packet *packet, guint8 c, guint *pos);
NETWORK_API int network_mysqld_proto_append_int8(GString *packet, guint8 num);
NETWORK_API int network_mysqld_proto_append_int16(GString *packet, guint16 num);
NETWORK_API int network_mysqld_proto_append_int24(GString *packet, guint32 num);
NETWORK_API int network_mysqld_proto_append_int32(GString *packet, guint32 num);
NETWORK_API int network_mysqld_proto_append_int48(GString *packet, guint64 num);
NETWORK_API int network_mysqld_proto_append_int64(GString *packet, guint64 num);
NETWORK_API int network_mysqld_proto_get_lenenc_string(network_packet *packet, gchar **s, guint64 *_len);
NETWORK_API int network_mysqld_proto_get_string_len(network_packet *packet, gchar **s, gsize len);
NETWORK_API int network_mysqld_proto_get_string(network_packet *packet, gchar **s);
NETWORK_API int network_mysqld_proto_get_lenenc_gstring(network_packet *packet, GString *out);
NETWORK_API int network_mysqld_proto_get_gstring_len(network_packet *packet, gsize len, GString *out);
NETWORK_API int network_mysqld_proto_get_gstring(network_packet *packet, GString *out);
NETWORK_API int network_mysqld_proto_peek_lenenc_type(network_packet *packet, network_mysqld_lenenc_type *type);
NETWORK_API int network_mysqld_proto_get_lenenc_int(network_packet *packet, guint64 *v);
NETWORK_API MYSQL_FIELD *network_mysqld_proto_fielddef_new(void);
NETWORK_API void network_mysqld_proto_fielddef_free(MYSQL_FIELD *fielddef);
NETWORK_API GPtrArray *network_mysqld_proto_fielddefs_new(void);
NETWORK_API void network_mysqld_proto_fielddefs_free(GPtrArray *fielddefs);
NETWORK_API guint32 network_mysqld_proto_get_packet_len(GString *_header);
NETWORK_API guint8 network_mysqld_proto_get_packet_id(GString *_header);
NETWORK_API int network_mysqld_proto_append_packet_len(GString *header, guint32 len);
NETWORK_API int network_mysqld_proto_append_packet_id(GString *header, guint8 id);
NETWORK_API int network_mysqld_proto_set_packet_len(GString *header, guint32 len);
NETWORK_API int network_mysqld_proto_set_packet_id(GString *header, guint8 id);
NETWORK_API int network_mysqld_proto_append_lenenc_int(GString *packet, guint64 len);
NETWORK_API int network_mysqld_proto_append_lenenc_string_len(GString *packet, const char *s, guint64 len);
NETWORK_API int network_mysqld_proto_append_lenenc_string(GString *packet, const char *s);
NETWORK_API int network_mysqld_proto_password_hash(GString *response,
const char *password, gsize password_len);
NETWORK_API int network_mysqld_proto_password_scramble(GString *response,
const char *challenge, gsize challenge_len,
const char *hashed_password, gsize hashed_password_len);
NETWORK_API gboolean network_mysqld_proto_password_check(
const char *challenge, gsize challenge_len,
const char *response, gsize response_len,
const char *double_hashed, gsize double_hashed_len);
NETWORK_API int network_mysqld_proto_password_unscramble(
GString *hashed_password,
const char *challenge, gsize challenge_len,
const char *response, gsize response_len,
const char *double_hashed, gsize double_hashed_len);
#endif
|