17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLED_PROTOCOL_H
21
#define DRIZZLED_PROTOCOL_H
23
#include <drizzled/sql_list.h>
24
#include <drizzled/item.h>
25
#include <libdrizzleclient/net_serv.h>
26
#include <libdrizzleclient/password.h>
33
typedef struct st_vio Vio;
34
typedef struct st_drizzle_field DRIZZLE_FIELD;
35
typedef struct st_drizzle_rows DRIZZLE_ROWS;
36
typedef struct st_drizzle_time DRIZZLE_TIME;
20
#ifndef DRIZZLED_PLUGIN_OLDLIBDRIZZLE_H
21
#define DRIZZLED_PLUGIN_OLDLIBDRIZZLE_H
23
#include <drizzled/plugin/protocol.h>
28
class ProtocolOldLibdrizzle: public Protocol
33
struct rand_struct rand;
34
char scramble[SCRAMBLE_LENGTH+1];
45
37
uint32_t field_pos;
46
38
uint32_t field_count;
48
bool net_store_data(const unsigned char *from, size_t length);
49
bool net_store_data(const unsigned char *from, size_t length,
50
const CHARSET_INFO * const fromcs, const CHARSET_INFO * const tocs);
51
bool store_string_aux(const char *from, size_t length,
52
const CHARSET_INFO * const fromcs, const CHARSET_INFO * const tocs);
55
Protocol(Session *session_arg) { init(session_arg); }
56
virtual ~Protocol() {}
57
void init(Session* session_arg);
60
void end_statement(void);
61
void set_read_timeout(uint32_t timeout);
62
void set_write_timeout(uint32_t timeout);
63
void set_retry_count(uint32_t count);
64
void set_error(char error);
65
bool have_error(void);
66
bool was_aborted(void);
67
bool have_compression(void);
68
void enable_compression(void);
69
bool have_more_data(void);
70
bool is_reading(void);
71
bool is_writing(void);
72
void disable_results(void);
73
void enable_results(void);
75
virtual bool init_file_descriptor(int fd)=0;
76
virtual int file_descriptor(void)=0;
77
virtual void init_random(uint64_t, uint64_t) {};
78
virtual bool authenticate(void)=0;
79
virtual bool read_command(char **packet, uint32_t *packet_length)=0;
80
virtual void send_error(uint32_t sql_errno, const char *err)=0;
81
virtual void send_error_packet(uint32_t sql_errno, const char *err)=0;
82
virtual void close(void) {};
84
enum { SEND_NUM_ROWS= 1, SEND_DEFAULTS= 2, SEND_EOF= 4 };
85
virtual bool send_fields(List<Item> *list, uint32_t flags);
87
virtual bool store(I_List<i_string> *str_list);
88
virtual bool store(const char *from, const CHARSET_INFO * const cs);
89
String *storage_packet() { return packet; }
92
virtual bool store(int from)
93
{ return store_long((int64_t) from); }
94
virtual bool store(uint32_t from)
95
{ return store_long((int64_t) from); }
96
virtual bool store(int64_t from)
97
{ return store_int64_t((int64_t) from, 0); }
98
virtual bool store(uint64_t from)
99
{ return store_int64_t((int64_t) from, 1); }
100
virtual bool store(String *str);
102
virtual bool prepare_for_send(List<Item> *item_list)
104
field_count=item_list->elements;
107
virtual bool flush();
109
virtual void prepare_for_resend()=0;
111
virtual bool store_null()=0;
112
virtual bool store_tiny(int64_t from)=0;
113
virtual bool store_short(int64_t from)=0;
114
virtual bool store_long(int64_t from)=0;
115
virtual bool store_int64_t(int64_t from, bool unsigned_flag)=0;
116
virtual bool store_decimal(const my_decimal * dec_value)=0;
117
virtual bool store(const char *from, size_t length, const CHARSET_INFO * const cs)=0;
118
virtual bool store(const char *from, size_t length,
119
const CHARSET_INFO * const fromcs, const CHARSET_INFO * const tocs)=0;
120
virtual bool store(float from, uint32_t decimals, String *buffer)=0;
121
virtual bool store(double from, uint32_t decimals, String *buffer)=0;
122
virtual bool store(DRIZZLE_TIME *time)=0;
123
virtual bool store_date(DRIZZLE_TIME *time)=0;
124
virtual bool store_time(DRIZZLE_TIME *time)=0;
125
virtual bool store(Field *field)=0;
126
void remove_last_row() {}
127
enum enum_protocol_type
129
PROTOCOL_TEXT= 0, PROTOCOL_BINARY= 1
131
before adding here or change the values, consider that it is cast to a
135
virtual enum enum_protocol_type type()= 0;
139
/** Class used for the old (MySQL 4.0 protocol). */
141
class Protocol_text :public Protocol
144
struct rand_struct _rand;
145
char _scramble[SCRAMBLE_LENGTH+1];
39
bool netStoreData(const unsigned char *from, size_t length);
40
bool netStoreData(const unsigned char *from, size_t length,
41
const CHARSET_INFO * const fromcs,
42
const CHARSET_INFO * const tocs);
43
bool storeString(const char *from, size_t length,
44
const CHARSET_INFO * const fromcs,
45
const CHARSET_INFO * const tocs);
148
48
* Performs handshake with client and authorizes user.
150
50
* Returns true is the connection is valid and the
151
51
* user is authorized, otherwise false.
153
bool _check_connection(void);
53
bool checkConnection(void);
156
Protocol_text() { _scramble[0]= 0; }
157
Protocol_text(Session *session_arg) :Protocol(session_arg) {}
158
virtual bool init_file_descriptor(int fd);
159
virtual int file_descriptor(void);
160
virtual void init_random(uint64_t seed1, uint64_t seed2);
56
ProtocolOldLibdrizzle();
57
virtual void setSession(Session *session_arg);
58
virtual bool isConnected();
59
virtual void setReadTimeout(uint32_t timeout);
60
virtual void setWriteTimeout(uint32_t timeout);
61
virtual void setRetryCount(uint32_t count);
62
virtual void setError(char error);
63
virtual bool haveError(void);
64
virtual bool wasAborted(void);
65
virtual void enableCompression(void);
66
virtual bool haveMoreData(void);
67
virtual bool isReading(void);
68
virtual bool isWriting(void);
69
virtual bool setFileDescriptor(int fd);
70
virtual int fileDescriptor(void);
71
virtual void setRandom(uint64_t seed1, uint64_t seed2);
161
72
virtual bool authenticate(void);
162
virtual bool read_command(char **packet, uint32_t *packet_length);
163
virtual void send_error(uint32_t sql_errno, const char *err);
164
virtual void send_error_packet(uint32_t sql_errno, const char *err);
73
virtual bool readCommand(char **packet, uint32_t *packet_length);
74
virtual void sendOK();
75
virtual void sendEOF();
76
virtual void sendError(uint32_t sql_errno, const char *err);
165
77
virtual void close(void);
166
virtual void prepare_for_resend();
167
virtual bool store(I_List<i_string> *str_list)
169
return Protocol::store(str_list);
171
virtual bool store(const char *from, const CHARSET_INFO * const cs)
173
return Protocol::store(from, cs);
175
virtual bool store_null();
176
virtual bool store_tiny(int64_t from);
177
virtual bool store_short(int64_t from);
178
virtual bool store_long(int64_t from);
179
virtual bool store_int64_t(int64_t from, bool unsigned_flag);
180
virtual bool store_decimal(const my_decimal *);
181
virtual bool store(int from)
182
{ return store_long((int64_t) from); }
183
virtual bool store(uint32_t from)
184
{ return store_long((int64_t) from); }
185
virtual bool store(int64_t from)
186
{ return store_int64_t((int64_t) from, 0); }
187
virtual bool store(uint64_t from)
188
{ return store_int64_t((int64_t) from, 1); }
189
virtual bool store(String *str)
191
return Protocol::store(str);
193
virtual bool store(const char *from, size_t length, const CHARSET_INFO * const cs);
194
virtual bool store(const char *from, size_t length,
195
const CHARSET_INFO * const fromcs, const CHARSET_INFO * const tocs);
196
virtual bool store(DRIZZLE_TIME *time);
197
virtual bool store_date(DRIZZLE_TIME *time);
198
virtual bool store_time(DRIZZLE_TIME *time);
199
virtual bool store(float nr, uint32_t decimals, String *buffer);
78
virtual void prepareForResend();
82
virtual bool sendFields(List<Item> *list, uint32_t flags);
84
using Protocol::store;
85
virtual bool store(Field *from);
86
virtual bool store(void);
87
virtual bool store(int32_t from);
88
virtual bool store(uint32_t from);
89
virtual bool store(int64_t from);
90
virtual bool store(uint64_t from);
200
91
virtual bool store(double from, uint32_t decimals, String *buffer);
201
virtual bool store(Field *field);
202
virtual enum enum_protocol_type type() { return PROTOCOL_TEXT; };
205
#endif /* DRIZZLED_PROTOCOL_H */
92
virtual bool store(const DRIZZLE_TIME *from);
93
virtual bool store(const char *from, size_t length,
94
const CHARSET_INFO * const cs);
97
class ProtocolFactoryOldLibdrizzle: public ProtocolFactory
100
Protocol *operator()(void)
102
return new ProtocolOldLibdrizzle;
106
#endif /* DRIZZLED_PLUGIN_OLDLIBDRIZZLE_H */