~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/oldlibdrizzle/oldlibdrizzle.h

  • Committer: Monty Taylor
  • Date: 2009-04-09 05:35:58 UTC
  • mfrom: (984 merge)
  • mto: (992.1.1 mordred)
  • mto: This revision was merged to the branch mainline in revision 986.
  • Revision ID: mordred@inaugust.com-20090409053558-qi1x0zzsgf1d8f1p
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#ifndef DRIZZLED_PROTOCOL_H
21
 
#define DRIZZLED_PROTOCOL_H
22
 
 
23
 
#include <drizzled/sql_list.h>
24
 
#include <drizzled/item.h>
25
 
#include <libdrizzleclient/net_serv.h>
26
 
#include <libdrizzleclient/password.h>
27
 
 
28
 
class Field;
29
 
class String;
30
 
class Session;
31
 
class i_string;
32
 
class my_decimal;
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;
37
 
 
38
 
class Protocol
 
20
#ifndef DRIZZLED_PLUGIN_OLDLIBDRIZZLE_H
 
21
#define DRIZZLED_PLUGIN_OLDLIBDRIZZLE_H
 
22
 
 
23
#include <drizzled/plugin/protocol.h>
 
24
 
 
25
#include "net_serv.h"
 
26
#include "password.h"
 
27
 
 
28
class ProtocolOldLibdrizzle: public Protocol
39
29
{
40
 
protected:
41
 
  Session *session;
 
30
private:
42
31
  NET net;
 
32
  Vio* save_vio;
 
33
  struct rand_struct rand;
 
34
  char scramble[SCRAMBLE_LENGTH+1];
43
35
  String *packet;
44
36
  String *convert;
45
37
  uint32_t field_pos;
46
38
  uint32_t field_count;
47
 
  Vio* save_vio;
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);
53
 
public:
54
 
  Protocol() {}
55
 
  Protocol(Session *session_arg) { init(session_arg); }
56
 
  virtual ~Protocol() {}
57
 
  void init(Session* session_arg);
58
 
 
59
 
  bool io_ok();
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);
74
 
 
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) {};
83
 
 
84
 
  enum { SEND_NUM_ROWS= 1, SEND_DEFAULTS= 2, SEND_EOF= 4 };
85
 
  virtual bool send_fields(List<Item> *list, uint32_t flags);
86
 
 
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; }
90
 
  void free();
91
 
  virtual bool write();
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);
101
 
 
102
 
  virtual bool prepare_for_send(List<Item> *item_list)
103
 
  {
104
 
    field_count=item_list->elements;
105
 
    return 0;
106
 
  }
107
 
  virtual bool flush();
108
 
 
109
 
  virtual void prepare_for_resend()=0;
110
 
 
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
128
 
  {
129
 
    PROTOCOL_TEXT= 0, PROTOCOL_BINARY= 1
130
 
    /*
131
 
      before adding here or change the values, consider that it is cast to a
132
 
      bit in sql_cache.cc.
133
 
    */
134
 
  };
135
 
  virtual enum enum_protocol_type type()= 0;
136
 
};
137
 
 
138
 
 
139
 
/** Class used for the old (MySQL 4.0 protocol). */
140
 
 
141
 
class Protocol_text :public Protocol
142
 
{
143
 
private:
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);
146
46
 
147
47
  /**
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.
152
52
   */  
153
 
  bool _check_connection(void);
 
53
  bool checkConnection(void);
154
54
 
155
55
public:
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)
168
 
  {
169
 
    return Protocol::store(str_list);
170
 
  }
171
 
  virtual bool store(const char *from, const CHARSET_INFO * const cs)
172
 
  {
173
 
    return Protocol::store(from, cs);
174
 
  }
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)
190
 
  {
191
 
    return Protocol::store(str);
192
 
  }
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();
 
79
  virtual void free();
 
80
  virtual bool write();
 
81
 
 
82
  virtual bool sendFields(List<Item> *list, uint32_t flags);
 
83
 
 
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; };
203
 
};
204
 
 
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);
 
95
};
 
96
 
 
97
class ProtocolFactoryOldLibdrizzle: public ProtocolFactory
 
98
{
 
99
public:
 
100
  Protocol *operator()(void)
 
101
  {
 
102
    return new ProtocolOldLibdrizzle;
 
103
  }
 
104
};
 
105
 
 
106
#endif /* DRIZZLED_PLUGIN_OLDLIBDRIZZLE_H */