~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/protocol.h

  • Committer: Monty Taylor
  • Date: 2008-09-15 00:46:33 UTC
  • mfrom: (383.1.55 client-split)
  • Revision ID: monty@inaugust.com-20080915004633-fmjw27fi41cxs35w
Merged from client-split.

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
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
 
 */
19
 
 
20
 
#ifndef PLUGIN_DRIZZLE_PROTOCOL_DRIZZLE_PROTOCOL_H
21
 
#define PLUGIN_DRIZZLE_PROTOCOL_DRIZZLE_PROTOCOL_H
22
 
 
23
 
#include <drizzled/plugin/listen_tcp.h>
24
 
#include <drizzled/plugin/client.h>
25
 
#include <drizzled/atomics.h>
26
 
#include "drizzled/plugin/table_function.h"
27
 
 
28
 
#include "net_serv.h"
29
 
 
30
 
namespace drizzle_protocol
31
 
{
32
 
 
33
 
class ListenDrizzleProtocol: public drizzled::plugin::ListenTcp
34
 
{
35
 
private:
36
 
  bool using_mysql41_protocol;
37
 
 
38
 
public:
39
 
  ListenDrizzleProtocol(std::string name_arg, bool using_mysql41_protocol_arg):
40
 
   drizzled::plugin::ListenTcp(name_arg),
41
 
   using_mysql41_protocol(using_mysql41_protocol_arg)
42
 
  { }
43
 
  virtual ~ListenDrizzleProtocol();
44
 
  virtual const char* getHost(void) const;
45
 
  virtual in_port_t getPort(void) const;
46
 
  virtual drizzled::plugin::Client *getClient(int fd);
47
 
};
48
 
 
49
 
class ClientDrizzleProtocol: public drizzled::plugin::Client
50
 
{
51
 
private:
52
 
  NET net;
53
 
  drizzled::String packet;
54
 
  uint32_t client_capabilities;
55
 
  bool using_mysql41_protocol;
56
 
 
57
 
  bool checkConnection(void);
58
 
  bool netStoreData(const unsigned char *from, size_t length);
59
 
  void writeEOFPacket(uint32_t server_status, uint32_t total_warn_count);
60
 
 
61
 
public:
62
 
  ClientDrizzleProtocol(int fd, bool using_mysql41_protocol_arg);
63
 
  virtual ~ClientDrizzleProtocol();
64
 
 
65
 
  static drizzled::atomic<uint64_t> connectionCount;
66
 
  static drizzled::atomic<uint64_t> failedConnections;
67
 
  static drizzled::atomic<uint64_t> connected;
68
 
 
69
 
  virtual int getFileDescriptor(void);
70
 
  virtual bool isConnected();
71
 
  virtual bool isReading(void);
72
 
  virtual bool isWriting(void);
73
 
  virtual bool flush(void);
74
 
  virtual void close(void);
75
 
 
76
 
  virtual bool authenticate(void);
77
 
  virtual bool readCommand(char **packet, uint32_t *packet_length);
78
 
 
79
 
  virtual void sendOK(void);
80
 
  virtual void sendEOF(void);
81
 
  virtual void sendError(uint32_t sql_errno, const char *err);
82
 
 
83
 
  virtual bool sendFields(drizzled::List<drizzled::Item> *list);
84
 
 
85
 
  using Client::store;
86
 
  virtual bool store(drizzled::Field *from);
87
 
  virtual bool store(void);
88
 
  virtual bool store(int32_t from);
89
 
  virtual bool store(uint32_t from);
90
 
  virtual bool store(int64_t from);
91
 
  virtual bool store(uint64_t from);
92
 
  virtual bool store(double from, uint32_t decimals, drizzled::String *buffer);
93
 
  virtual bool store(const char *from, size_t length);
94
 
 
95
 
  virtual bool haveError(void);
96
 
  virtual bool haveMoreData(void);
97
 
  virtual bool wasAborted(void);
98
 
};
99
 
 
100
 
} /* namespace drizzle_protocol */
101
 
 
102
 
#endif /* PLUGIN_DRIZZLE_PROTOCOL_DRIZZLE_PROTOCOL_H */
 
1
/* Copyright (C) 2002-2006 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 */
 
15
 
 
16
#ifdef USE_PRAGMA_INTERFACE
 
17
#pragma interface                       /* gcc class implementation */
 
18
#endif
 
19
 
 
20
 
 
21
class i_string;
 
22
class THD;
 
23
typedef struct st_drizzle_field DRIZZLE_FIELD;
 
24
typedef struct st_drizzle_rows DRIZZLE_ROWS;
 
25
 
 
26
class Protocol
 
27
{
 
28
protected:
 
29
  THD    *thd;
 
30
  String *packet;
 
31
  String *convert;
 
32
  uint field_pos;
 
33
  uint field_count;
 
34
  bool net_store_data(const uchar *from, size_t length);
 
35
  bool net_store_data(const uchar *from, size_t length,
 
36
                      const CHARSET_INFO * const fromcs, const CHARSET_INFO * const tocs);
 
37
  bool store_string_aux(const char *from, size_t length,
 
38
                        const CHARSET_INFO * const fromcs, const CHARSET_INFO * const tocs);
 
39
public:
 
40
  Protocol() {}
 
41
  Protocol(THD *thd_arg) { init(thd_arg); }
 
42
  virtual ~Protocol() {}
 
43
  void init(THD* thd_arg);
 
44
 
 
45
  enum { SEND_NUM_ROWS= 1, SEND_DEFAULTS= 2, SEND_EOF= 4 };
 
46
  virtual bool send_fields(List<Item> *list, uint flags);
 
47
 
 
48
  bool store(I_List<i_string> *str_list);
 
49
  bool store(const char *from, const CHARSET_INFO * const cs);
 
50
  String *storage_packet() { return packet; }
 
51
  inline void free() { packet->free(); }
 
52
  virtual bool write();
 
53
  inline  bool store(int from)
 
54
  { return store_long((int64_t) from); }
 
55
  inline  bool store(uint32_t from)
 
56
  { return store_long((int64_t) from); }
 
57
  inline  bool store(int64_t from)
 
58
  { return store_int64_t((int64_t) from, 0); }
 
59
  inline  bool store(uint64_t from)
 
60
  { return store_int64_t((int64_t) from, 1); }
 
61
  inline bool store(String *str)
 
62
  { return store((char*) str->ptr(), str->length(), str->charset()); }
 
63
 
 
64
  virtual bool prepare_for_send(List<Item> *item_list) 
 
65
  {
 
66
    field_count=item_list->elements;
 
67
    return 0;
 
68
  }
 
69
  virtual bool flush();
 
70
  virtual void end_partial_result_set(THD *thd);
 
71
  virtual void prepare_for_resend()=0;
 
72
 
 
73
  virtual bool store_null()=0;
 
74
  virtual bool store_tiny(int64_t from)=0;
 
75
  virtual bool store_short(int64_t from)=0;
 
76
  virtual bool store_long(int64_t from)=0;
 
77
  virtual bool store_int64_t(int64_t from, bool unsigned_flag)=0;
 
78
  virtual bool store_decimal(const my_decimal *)=0;
 
79
  virtual bool store(const char *from, size_t length, const CHARSET_INFO * const cs)=0;
 
80
  virtual bool store(const char *from, size_t length, 
 
81
                     const CHARSET_INFO * const fromcs, const CHARSET_INFO * const tocs)=0;
 
82
  virtual bool store(float from, uint32_t decimals, String *buffer)=0;
 
83
  virtual bool store(double from, uint32_t decimals, String *buffer)=0;
 
84
  virtual bool store(DRIZZLE_TIME *time)=0;
 
85
  virtual bool store_date(DRIZZLE_TIME *time)=0;
 
86
  virtual bool store_time(DRIZZLE_TIME *time)=0;
 
87
  virtual bool store(Field *field)=0;
 
88
  void remove_last_row() {}
 
89
  enum enum_protocol_type
 
90
  {
 
91
    PROTOCOL_TEXT= 0, PROTOCOL_BINARY= 1
 
92
    /*
 
93
      before adding here or change the values, consider that it is cast to a
 
94
      bit in sql_cache.cc.
 
95
    */
 
96
  };
 
97
  virtual enum enum_protocol_type type()= 0;
 
98
};
 
99
 
 
100
 
 
101
/** Class used for the old (MySQL 4.0 protocol). */
 
102
 
 
103
class Protocol_text :public Protocol
 
104
{
 
105
public:
 
106
  Protocol_text() {}
 
107
  Protocol_text(THD *thd_arg) :Protocol(thd_arg) {}
 
108
  virtual void prepare_for_resend();
 
109
  virtual bool store_null();
 
110
  virtual bool store_tiny(int64_t from);
 
111
  virtual bool store_short(int64_t from);
 
112
  virtual bool store_long(int64_t from);
 
113
  virtual bool store_int64_t(int64_t from, bool unsigned_flag);
 
114
  virtual bool store_decimal(const my_decimal *);
 
115
  virtual bool store(const char *from, size_t length, const CHARSET_INFO * const cs);
 
116
  virtual bool store(const char *from, size_t length,
 
117
                     const CHARSET_INFO * const fromcs,  const CHARSET_INFO * const tocs);
 
118
  virtual bool store(DRIZZLE_TIME *time);
 
119
  virtual bool store_date(DRIZZLE_TIME *time);
 
120
  virtual bool store_time(DRIZZLE_TIME *time);
 
121
  virtual bool store(float nr, uint32_t decimals, String *buffer);
 
122
  virtual bool store(double from, uint32_t decimals, String *buffer);
 
123
  virtual bool store(Field *field);
 
124
  virtual enum enum_protocol_type type() { return PROTOCOL_TEXT; };
 
125
};
 
126
 
 
127
void send_warning(THD *thd, uint sql_errno, const char *err=0);
 
128
void net_send_error(THD *thd, uint sql_errno=0, const char *err=0);
 
129
void net_end_statement(THD *thd);
 
130
uchar *net_store_data(uchar *to,const uchar *from, size_t length);
 
131
uchar *net_store_data(uchar *to,int32_t from);
 
132
uchar *net_store_data(uchar *to,int64_t from);
 
133