~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/protocol.h

  • Committer: Monty Taylor
  • Date: 2009-03-18 18:45:23 UTC
  • mto: (950.1.1 mordred)
  • mto: This revision was merged to the branch mainline in revision 943.
  • Revision ID: mordred@inaugust.com-20090318184523-mfbjyj5wkipv4n3b
Moved big tests to big suite. Added make target "make test-big" to allow for easy running of the big tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2010 Brian Aker
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
9
 
 *  (at your option) any later version.
 
8
 *  the Free Software Foundation; version 2 of the License.
10
9
 *
11
10
 *  This program is distributed in the hope that it will be useful,
12
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
18
 */
20
19
 
21
 
 
22
 
#ifndef PLUGIN_DRIZZLE_PROTOCOL_DRIZZLE_PROTOCOL_H
23
 
#define PLUGIN_DRIZZLE_PROTOCOL_DRIZZLE_PROTOCOL_H
24
 
 
25
 
#include <drizzled/plugin/listen_tcp.h>
26
 
#include <drizzled/plugin/client.h>
27
 
#include <drizzled/atomics.h>
28
 
#include <drizzled/plugin/table_function.h>
29
 
 
30
 
#include <plugin/mysql_protocol/mysql_protocol.h>
31
 
 
32
 
namespace drizzle_plugin
33
 
{
34
 
namespace drizzle_protocol
35
 
{
36
 
 
37
 
class ListenDrizzleProtocol: public ListenMySQLProtocol
38
 
{
39
 
public:
40
 
  ListenDrizzleProtocol(std::string name, 
41
 
                        const std::string &bind_address,
42
 
                        bool using_mysql41_protocol):
43
 
    ListenMySQLProtocol(name, bind_address, using_mysql41_protocol)
44
 
  { }
45
 
 
46
 
  ~ListenDrizzleProtocol();
47
 
  in_port_t getPort(void) const;
48
 
  static ProtocolCounters *drizzle_counters;
49
 
  virtual ProtocolCounters *getCounters(void) const { return drizzle_counters; }
50
 
  drizzled::plugin::Client *getClient(int fd);
51
 
};
52
 
 
53
 
class ClientDrizzleProtocol: public ClientMySQLProtocol
54
 
{
55
 
public:
56
 
  ClientDrizzleProtocol(int fd, ProtocolCounters *set_counters): ClientMySQLProtocol(fd, true, set_counters) {}
57
 
 
58
 
  static std::vector<std::string> drizzle_admin_ip_addresses;
59
 
  static void drizzle_compose_ip_addresses(std::vector<std::string> options);
60
 
  bool isAdminAllowed(void);
61
 
};
62
 
 
63
 
} /* namespace drizzle_protocol */
64
 
} /* namespace drizzle_plugin */
65
 
 
66
 
#endif /* PLUGIN_DRIZZLE_PROTOCOL_DRIZZLE_PROTOCOL_H */
 
20
#ifndef DRIZZLED_PROTOCOL_H
 
21
#define DRIZZLED_PROTOCOL_H
 
22
 
 
23
#include <drizzled/sql_list.h>
 
24
#include <drizzled/item.h>
 
25
 
 
26
class Field;
 
27
class String;
 
28
class i_string;
 
29
class Session;
 
30
class my_decimal;
 
31
typedef struct st_drizzle_field DRIZZLE_FIELD;
 
32
typedef struct st_drizzle_rows DRIZZLE_ROWS;
 
33
typedef struct st_drizzle_time DRIZZLE_TIME;
 
34
 
 
35
class Protocol
 
36
{
 
37
protected:
 
38
  Session        *session;
 
39
  String *packet;
 
40
  String *convert;
 
41
  uint32_t field_pos;
 
42
  uint32_t field_count;
 
43
  bool net_store_data(const unsigned char *from, size_t length);
 
44
  bool net_store_data(const unsigned char *from, size_t length,
 
45
                      const CHARSET_INFO * const fromcs, const CHARSET_INFO * const tocs);
 
46
  bool store_string_aux(const char *from, size_t length,
 
47
                        const CHARSET_INFO * const fromcs, const CHARSET_INFO * const tocs);
 
48
public:
 
49
  Protocol() {}
 
50
  Protocol(Session *session_arg) { init(session_arg); }
 
51
  virtual ~Protocol() {}
 
52
  void init(Session* session_arg);
 
53
 
 
54
  enum { SEND_NUM_ROWS= 1, SEND_DEFAULTS= 2, SEND_EOF= 4 };
 
55
  virtual bool send_fields(List<Item> *list, uint32_t flags);
 
56
 
 
57
  virtual bool store(I_List<i_string> *str_list);
 
58
  virtual bool store(const char *from, const CHARSET_INFO * const cs);
 
59
  String *storage_packet() { return packet; }
 
60
  void free();
 
61
  virtual bool write();
 
62
  virtual bool store(int from)
 
63
  { return store_long((int64_t) from); }
 
64
  virtual  bool store(uint32_t from)
 
65
  { return store_long((int64_t) from); }
 
66
  virtual bool store(int64_t from)
 
67
  { return store_int64_t((int64_t) from, 0); }
 
68
  virtual bool store(uint64_t from)
 
69
  { return store_int64_t((int64_t) from, 1); }
 
70
  virtual bool store(String *str);
 
71
 
 
72
  virtual bool prepare_for_send(List<Item> *item_list)
 
73
  {
 
74
    field_count=item_list->elements;
 
75
    return 0;
 
76
  }
 
77
  virtual bool flush();
 
78
  virtual void prepare_for_resend()=0;
 
79
 
 
80
  virtual bool store_null()=0;
 
81
  virtual bool store_tiny(int64_t from)=0;
 
82
  virtual bool store_short(int64_t from)=0;
 
83
  virtual bool store_long(int64_t from)=0;
 
84
  virtual bool store_int64_t(int64_t from, bool unsigned_flag)=0;
 
85
  virtual bool store_decimal(const my_decimal * dec_value)=0;
 
86
  virtual bool store(const char *from, size_t length, const CHARSET_INFO * const cs)=0;
 
87
  virtual bool store(const char *from, size_t length,
 
88
                     const CHARSET_INFO * const fromcs, const CHARSET_INFO * const tocs)=0;
 
89
  virtual bool store(float from, uint32_t decimals, String *buffer)=0;
 
90
  virtual bool store(double from, uint32_t decimals, String *buffer)=0;
 
91
  virtual bool store(DRIZZLE_TIME *time)=0;
 
92
  virtual bool store_date(DRIZZLE_TIME *time)=0;
 
93
  virtual bool store_time(DRIZZLE_TIME *time)=0;
 
94
  virtual bool store(Field *field)=0;
 
95
  void remove_last_row() {}
 
96
  enum enum_protocol_type
 
97
  {
 
98
    PROTOCOL_TEXT= 0, PROTOCOL_BINARY= 1
 
99
    /*
 
100
      before adding here or change the values, consider that it is cast to a
 
101
      bit in sql_cache.cc.
 
102
    */
 
103
  };
 
104
  virtual enum enum_protocol_type type()= 0;
 
105
};
 
106
 
 
107
 
 
108
/** Class used for the old (MySQL 4.0 protocol). */
 
109
 
 
110
class Protocol_text :public Protocol
 
111
{
 
112
public:
 
113
  Protocol_text() {}
 
114
  Protocol_text(Session *session_arg) :Protocol(session_arg) {}
 
115
  virtual void prepare_for_resend();
 
116
  virtual bool store(I_List<i_string> *str_list)
 
117
  {
 
118
    return Protocol::store(str_list);
 
119
  }
 
120
  virtual bool store(const char *from, const CHARSET_INFO * const cs)
 
121
  {
 
122
    return Protocol::store(from, cs);
 
123
  }
 
124
  virtual bool store_null();
 
125
  virtual bool store_tiny(int64_t from);
 
126
  virtual bool store_short(int64_t from);
 
127
  virtual bool store_long(int64_t from);
 
128
  virtual bool store_int64_t(int64_t from, bool unsigned_flag);
 
129
  virtual bool store_decimal(const my_decimal *);
 
130
  virtual bool store(int from)
 
131
  { return store_long((int64_t) from); }
 
132
  virtual  bool store(uint32_t from)
 
133
  { return store_long((int64_t) from); }
 
134
  virtual bool store(int64_t from)
 
135
  { return store_int64_t((int64_t) from, 0); }
 
136
  virtual bool store(uint64_t from)
 
137
  { return store_int64_t((int64_t) from, 1); }
 
138
  virtual bool store(String *str)
 
139
  {
 
140
    return Protocol::store(str);
 
141
  }
 
142
  virtual bool store(const char *from, size_t length, const CHARSET_INFO * const cs);
 
143
  virtual bool store(const char *from, size_t length,
 
144
                     const CHARSET_INFO * const fromcs,  const CHARSET_INFO * const tocs);
 
145
  virtual bool store(DRIZZLE_TIME *time);
 
146
  virtual bool store_date(DRIZZLE_TIME *time);
 
147
  virtual bool store_time(DRIZZLE_TIME *time);
 
148
  virtual bool store(float nr, uint32_t decimals, String *buffer);
 
149
  virtual bool store(double from, uint32_t decimals, String *buffer);
 
150
  virtual bool store(Field *field);
 
151
  virtual enum enum_protocol_type type() { return PROTOCOL_TEXT; };
 
152
};
 
153
 
 
154
void send_warning(Session *session, uint32_t sql_errno, const char *err=0);
 
155
void net_send_error(Session *session, uint32_t sql_errno=0, const char *err=0);
 
156
void drizzleclient_net_end_statement(Session *session);
 
157
unsigned char *net_store_data(unsigned char *to,const unsigned char *from, size_t length);
 
158
unsigned char *net_store_data(unsigned char *to,int32_t from);
 
159
unsigned char *net_store_data(unsigned char *to,int64_t from);
 
160
 
 
161
#endif /* DRIZZLED_PROTOCOL_H */