~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/protocol.h

Started abstracting Protocol, removed init_connect, init_file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#ifndef DRIZZLED_PROTOCOL_H
21
21
#define DRIZZLED_PROTOCOL_H
22
22
 
 
23
#include <drizzled/plugin/protocol.h>
23
24
#include <drizzled/sql_list.h>
24
25
#include <drizzled/item.h>
25
26
#include <libdrizzleclient/net_serv.h>
27
28
 
28
29
class Field;
29
30
class String;
30
 
class Session;
31
31
class i_string;
32
32
class my_decimal;
33
33
typedef struct st_vio Vio;
35
35
typedef struct st_drizzle_rows DRIZZLE_ROWS;
36
36
typedef struct st_drizzle_time DRIZZLE_TIME;
37
37
 
38
 
class Protocol
 
38
class Protocol_libdrizzleclient :public Protocol
39
39
{
40
 
protected:
41
 
  Session *session;
 
40
private:
42
41
  NET net;
43
 
  String *packet;
 
42
  Vio* save_vio;
 
43
  struct rand_struct rand;
 
44
  char scramble[SCRAMBLE_LENGTH+1];
44
45
  String *convert;
45
46
  uint32_t field_pos;
46
47
  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];
 
48
  bool netStoreData(const unsigned char *from, size_t length);
 
49
  bool netStoreData(const unsigned char *from, size_t length,
 
50
                    const CHARSET_INFO * const fromcs,
 
51
                    const CHARSET_INFO * const tocs);
 
52
  bool storeStringAux(const char *from, size_t length,
 
53
                      const CHARSET_INFO * const fromcs,
 
54
                      const CHARSET_INFO * const tocs);
146
55
 
147
56
  /**
148
57
   * Performs handshake with client and authorizes user.
150
59
   * Returns true is the connection is valid and the
151
60
   * user is authorized, otherwise false.
152
61
   */  
153
 
  bool _check_connection(void);
 
62
  bool checkConnection(void);
154
63
 
155
64
public:
156
 
  Protocol_text() { _scramble[0]= 0; }
157
 
  Protocol_text(Session *session_arg) :Protocol(session_arg) {}
 
65
  Protocol_libdrizzleclient();
 
66
 
 
67
  virtual void setSession(Session *session_arg);
 
68
 
 
69
  virtual bool isConnected();
 
70
 
 
71
  virtual void set_read_timeout(uint32_t timeout);
 
72
  virtual void set_write_timeout(uint32_t timeout);
 
73
  virtual void set_retry_count(uint32_t count);
 
74
  virtual void set_error(char error);
 
75
  virtual bool have_error(void);
 
76
  virtual bool was_aborted(void);
 
77
  virtual bool have_compression(void); 
 
78
  virtual void enable_compression(void);
 
79
  virtual bool have_more_data(void);
 
80
  virtual bool is_reading(void);
 
81
  virtual bool is_writing(void);
158
82
  virtual bool init_file_descriptor(int fd);
159
83
  virtual int file_descriptor(void);
160
84
  virtual void init_random(uint64_t seed1, uint64_t seed2);
161
85
  virtual bool authenticate(void);
162
86
  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);
 
87
  virtual void sendOK();
 
88
  virtual void sendEOF();
 
89
  virtual void sendError(uint32_t sql_errno, const char *err);
 
90
  virtual void sendErrorPacket(uint32_t sql_errno, const char *err);
165
91
  virtual void close(void);
166
92
  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
 
  }
 
93
  virtual void free();
 
94
  virtual bool write();
 
95
  virtual bool flush();
 
96
  virtual bool send_fields(List<Item> *list, uint32_t flags);
 
97
  virtual bool store(I_List<i_string> *str_list);
 
98
  virtual bool store(const char *from, const CHARSET_INFO * const cs);
175
99
  virtual bool store_null();
176
100
  virtual bool store_tiny(int64_t from);
177
101
  virtual bool store_short(int64_t from);
186
110
  { return store_int64_t((int64_t) from, 0); }
187
111
  virtual bool store(uint64_t from)
188
112
  { return store_int64_t((int64_t) from, 1); }
189
 
  virtual bool store(String *str)
190
 
  {
191
 
    return Protocol::store(str);
192
 
  }
 
113
  virtual bool store(String *str);
193
114
  virtual bool store(const char *from, size_t length, const CHARSET_INFO * const cs);
194
115
  virtual bool store(const char *from, size_t length,
195
116
                     const CHARSET_INFO * const fromcs,  const CHARSET_INFO * const tocs);
199
120
  virtual bool store(float nr, uint32_t decimals, String *buffer);
200
121
  virtual bool store(double from, uint32_t decimals, String *buffer);
201
122
  virtual bool store(Field *field);
202
 
  virtual enum enum_protocol_type type() { return PROTOCOL_TEXT; };
203
123
};
204
124
 
205
125
#endif /* DRIZZLED_PROTOCOL_H */