~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/mysql_protocol/mysql_protocol.h

  • Committer: Brian Aker
  • Date: 2009-08-18 07:20:29 UTC
  • mfrom: (1117.1.9 merge)
  • Revision ID: brian@gaz-20090818072029-s9ch5lcmltxwidn7
Merge of Brian

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, Inc.
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_MYSQL_PROTOCOL_MYSQL_PROTOCOL_H
21
 
#define PLUGIN_MYSQL_PROTOCOL_MYSQL_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_plugin
31
 
{
32
 
void compose_ip_addresses(std::vector<std::string> options);
33
 
 
34
 
class ProtocolCounters
35
 
{
36
 
  public:
37
 
    ProtocolCounters():
38
 
      max_connections(1000)
39
 
    { }
40
 
    drizzled::atomic<uint64_t> connectionCount;
41
 
    drizzled::atomic<uint64_t> adminConnectionCount;
42
 
    drizzled::atomic<uint64_t> failedConnections;
43
 
    drizzled::atomic<uint64_t> connected;
44
 
    drizzled::atomic<uint64_t> adminConnected;
45
 
    uint32_t max_connections;
46
 
};
47
 
 
48
 
typedef drizzled::constrained_check<uint32_t, 300, 1> timeout_constraint;
49
 
typedef drizzled::constrained_check<uint32_t, 300, 1> retry_constraint;
50
 
typedef drizzled::constrained_check<uint32_t, 1048576, 1024, 1024> buffer_constraint;
51
 
 
52
 
class ListenMySQLProtocol: public drizzled::plugin::ListenTcp
53
 
{
54
 
protected:
55
 
  const std::string _hostname;
56
 
  bool _using_mysql41_protocol;
57
 
 
58
 
public:
59
 
  ListenMySQLProtocol(std::string name,
60
 
                      const std::string &hostname,
61
 
                      bool using_mysql41_protocol):
62
 
   drizzled::plugin::ListenTcp(name),
63
 
   _hostname(hostname),
64
 
   _using_mysql41_protocol(using_mysql41_protocol)
65
 
  { }
66
 
  virtual ~ListenMySQLProtocol();
67
 
  virtual const std::string getHost(void) const;
68
 
  virtual in_port_t getPort(void) const;
69
 
  virtual drizzled::plugin::Client *getClient(int fd);
70
 
  static ProtocolCounters *mysql_counters;
71
 
  virtual ProtocolCounters *getCounters(void) const { return mysql_counters; }
72
 
  void addCountersToTable(void);
73
 
};
74
 
 
75
 
class ClientMySQLProtocol: public drizzled::plugin::Client
76
 
{
77
 
protected:
78
 
  NET net;
79
 
  drizzled::String packet;
80
 
  uint32_t client_capabilities;
81
 
  bool is_admin_connection;
82
 
  bool _using_mysql41_protocol;
83
 
 
84
 
  bool checkConnection(void);
85
 
  bool netStoreData(const unsigned char *from, size_t length);
86
 
  void writeEOFPacket(uint32_t server_status, uint32_t total_warn_count);
87
 
  unsigned char *storeLength(unsigned char *packet, uint64_t length);
88
 
  void makeScramble(char *scramble);
89
 
 
90
 
public:
91
 
  ClientMySQLProtocol(int fd, bool _using_mysql41_protocol, ProtocolCounters *set_counters);
92
 
  virtual ~ClientMySQLProtocol();
93
 
 
94
 
  ProtocolCounters *counters;
95
 
 
96
 
  virtual int getFileDescriptor(void);
97
 
  virtual bool isConnected();
98
 
  virtual bool isReading(void);
99
 
  virtual bool isWriting(void);
100
 
  virtual bool flush(void);
101
 
  virtual void close(void);
102
 
 
103
 
  virtual bool authenticate(void);
104
 
  virtual bool readCommand(char **packet, uint32_t *packet_length);
105
 
 
106
 
  virtual void sendOK(void);
107
 
  virtual void sendEOF(void);
108
 
  virtual void sendError(const drizzled::error_t sql_errno, const char *err);
109
 
 
110
 
  virtual bool sendFields(drizzled::List<drizzled::Item> *list);
111
 
 
112
 
  using Client::store;
113
 
  virtual bool store(drizzled::Field *from);
114
 
  virtual bool store(void);
115
 
  virtual bool store(int32_t from);
116
 
  virtual bool store(uint32_t from);
117
 
  virtual bool store(int64_t from);
118
 
  virtual bool store(uint64_t from);
119
 
  virtual bool store(double from, uint32_t decimals, drizzled::String *buffer);
120
 
  virtual bool store(const char *from, size_t length);
121
 
 
122
 
  virtual bool haveError(void);
123
 
  virtual bool haveMoreData(void);
124
 
  virtual bool wasAborted(void);
125
 
  virtual bool isAdminAllowed(void);
126
 
  static std::vector<std::string> mysql_admin_ip_addresses;
127
 
  static void mysql_compose_ip_addresses(std::vector<std::string> options);
128
 
};
129
 
 
130
 
} /* namespace drizzle_plugin */
131
 
 
132
 
#endif /* PLUGIN_MYSQL_PROTOCOL_MYSQL_PROTOCOL_H */