1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
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.
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.
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
20
#ifndef PLUGIN_MYSQL_PROTOCOL_MYSQL_PROTOCOL_H
21
#define PLUGIN_MYSQL_PROTOCOL_MYSQL_PROTOCOL_H
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"
30
namespace drizzle_plugin
32
void compose_ip_addresses(std::vector<std::string> options);
34
class ProtocolCounters
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;
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;
52
class ListenMySQLProtocol: public drizzled::plugin::ListenTcp
55
const std::string _hostname;
56
bool _using_mysql41_protocol;
59
ListenMySQLProtocol(std::string name,
60
const std::string &hostname,
61
bool using_mysql41_protocol):
62
drizzled::plugin::ListenTcp(name),
64
_using_mysql41_protocol(using_mysql41_protocol)
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);
75
class ClientMySQLProtocol: public drizzled::plugin::Client
79
drizzled::String packet;
80
uint32_t client_capabilities;
81
bool is_admin_connection;
82
bool _using_mysql41_protocol;
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);
91
ClientMySQLProtocol(int fd, bool _using_mysql41_protocol, ProtocolCounters *set_counters);
92
virtual ~ClientMySQLProtocol();
94
ProtocolCounters *counters;
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);
103
virtual bool authenticate(void);
104
virtual bool readCommand(char **packet, uint32_t *packet_length);
106
virtual void sendOK(void);
107
virtual void sendEOF(void);
108
virtual void sendError(const drizzled::error_t sql_errno, const char *err);
110
virtual bool sendFields(drizzled::List<drizzled::Item> *list);
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);
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);
130
} /* namespace drizzle_plugin */
132
#endif /* PLUGIN_MYSQL_PROTOCOL_MYSQL_PROTOCOL_H */