23
23
#include <drizzled/gettext.h>
24
24
#include <drizzled/error.h>
25
25
#include <drizzled/query_id.h>
26
#include <drizzled/sql_state.h>
26
27
#include <drizzled/session.h>
27
#include <drizzled/internal/my_sys.h>
28
#include <drizzled/internal/m_string.h>
28
#include "drizzled/internal/my_sys.h"
29
#include "drizzled/internal/m_string.h"
29
30
#include <algorithm>
30
31
#include <iostream>
31
32
#include <boost/program_options.hpp>
32
33
#include <drizzled/module/option_map.h>
33
#include <drizzled/util/tokenize.h>
34
34
#include "drizzle_protocol.h"
35
#include "plugin/drizzle_protocol/status_table.h"
36
37
namespace po= boost::program_options;
37
38
using namespace drizzled;
38
39
using namespace std;
40
namespace drizzle_plugin
42
41
namespace drizzle_protocol
45
std::vector<std::string> ClientDrizzleProtocol::drizzle_admin_ip_addresses;
46
static port_constraint port;
47
static timeout_constraint connect_timeout;
48
static timeout_constraint read_timeout;
49
static timeout_constraint write_timeout;
50
static retry_constraint retry_count;
51
static buffer_constraint buffer_length;
45
static uint32_t connect_timeout;
46
static uint32_t read_timeout;
47
static uint32_t write_timeout;
48
static uint32_t retry_count;
49
static uint32_t buffer_length;
50
static char* bind_address;
53
52
static const uint32_t DRIZZLE_TCP_PORT= 4427;
55
ProtocolCounters *ListenDrizzleProtocol::drizzle_counters= new ProtocolCounters();
57
54
ListenDrizzleProtocol::~ListenDrizzleProtocol()
56
/* This is strdup'd from the options */
60
const char* ListenDrizzleProtocol::getHost(void) const
61
65
in_port_t ListenDrizzleProtocol::getPort(void) const
66
void ClientDrizzleProtocol::drizzle_compose_ip_addresses(vector<string> options)
68
for (vector<string>::iterator it= options.begin();
72
tokenize(*it, drizzle_admin_ip_addresses, ",", true);
76
bool ClientDrizzleProtocol::isAdminAllowed(void)
78
if (std::find(drizzle_admin_ip_addresses.begin(), drizzle_admin_ip_addresses.end(), session->user()->address()) != drizzle_admin_ip_addresses.end())
84
plugin::Client *ListenDrizzleProtocol::getClient(int fd)
87
new_fd= acceptTcp(fd);
91
return new ClientDrizzleProtocol(new_fd, getCounters());
67
return (in_port_t) port;
94
70
static int init(drizzled::module::Context &context)
96
72
const module::option_map &vm= context.getOptions();
98
ListenDrizzleProtocol *protocol=new ListenDrizzleProtocol("drizzle_protocol", vm["bind-address"].as<std::string>(), true);
99
protocol->addCountersToTable();
100
context.add(protocol);
101
context.registerVariable(new sys_var_constrained_value_readonly<in_port_t>("port", port));
102
context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("connect_timeout", connect_timeout));
103
context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("read_timeout", read_timeout));
104
context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("write_timeout", write_timeout));
105
context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("retry_count", retry_count));
106
context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("buffer_length", buffer_length));
107
context.registerVariable(new sys_var_const_string_val("bind_address",
108
vm["bind-address"].as<std::string>()));
110
context.registerVariable(new sys_var_uint32_t_ptr("max-connections", &ListenDrizzleProtocol::drizzle_counters->max_connections));
77
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of port\n"));
82
if (vm.count("connect-timeout"))
84
if (connect_timeout < 1 || connect_timeout > 300)
86
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for connect_timeout\n"));
91
if (vm.count("read-timeout"))
93
if (read_timeout < 1 || read_timeout > 300)
95
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for read_timeout\n"));
100
if (vm.count("write-timeout"))
102
if (write_timeout < 1 || write_timeout > 300)
104
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for write_timeout\n"));
109
if (vm.count("retry-count"))
111
if (retry_count < 1 || retry_count > 100)
113
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for retry_count"));
118
if (vm.count("buffer-length"))
120
if (buffer_length < 1024 || buffer_length > 1024*1024)
122
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for buffer_length\n"));
127
if (vm.count("bind-address"))
129
bind_address= strdup(vm["bind-address"].as<string>().c_str());
137
context.add(new StatusTable);
138
context.add(new ListenDrizzleProtocol("drizzle_protocol", true));
143
static DRIZZLE_SYSVAR_UINT(port, port, PLUGIN_VAR_RQCMDARG,
144
N_("Port number to use for connection or 0 for default to with Drizzle/MySQL protocol."),
145
NULL, NULL, DRIZZLE_TCP_PORT, 0, 65535, 0);
146
static DRIZZLE_SYSVAR_UINT(connect_timeout, connect_timeout,
147
PLUGIN_VAR_RQCMDARG, N_("Connect Timeout."),
148
NULL, NULL, 10, 1, 300, 0);
149
static DRIZZLE_SYSVAR_UINT(read_timeout, read_timeout, PLUGIN_VAR_RQCMDARG,
150
N_("Read Timeout."), NULL, NULL, 30, 1, 300, 0);
151
static DRIZZLE_SYSVAR_UINT(write_timeout, write_timeout, PLUGIN_VAR_RQCMDARG,
152
N_("Write Timeout."), NULL, NULL, 60, 1, 300, 0);
153
static DRIZZLE_SYSVAR_UINT(retry_count, retry_count, PLUGIN_VAR_RQCMDARG,
154
N_("Retry Count."), NULL, NULL, 10, 1, 100, 0);
155
static DRIZZLE_SYSVAR_UINT(buffer_length, buffer_length, PLUGIN_VAR_RQCMDARG,
156
N_("Buffer length."), NULL, NULL, 16384, 1024,
158
static DRIZZLE_SYSVAR_STR(bind_address, bind_address, PLUGIN_VAR_READONLY,
159
N_("Address to bind to."), NULL, NULL, NULL);
116
161
static void init_options(drizzled::module::option_context &context)
119
po::value<port_constraint>(&port)->default_value(DRIZZLE_TCP_PORT),
164
po::value<uint32_t>(&port)->default_value(DRIZZLE_TCP_PORT),
120
165
N_("Port number to use for connection or 0 for default to with Drizzle/MySQL protocol."));
121
166
context("connect-timeout",
122
po::value<timeout_constraint>(&connect_timeout)->default_value(10),
167
po::value<uint32_t>(&connect_timeout)->default_value(10),
123
168
N_("Connect Timeout."));
124
169
context("read-timeout",
125
po::value<timeout_constraint>(&read_timeout)->default_value(30),
170
po::value<uint32_t>(&read_timeout)->default_value(30),
126
171
N_("Read Timeout."));
127
172
context("write-timeout",
128
po::value<timeout_constraint>(&write_timeout)->default_value(60),
173
po::value<uint32_t>(&write_timeout)->default_value(60),
129
174
N_("Write Timeout."));
130
175
context("retry-count",
131
po::value<retry_constraint>(&retry_count)->default_value(10),
176
po::value<uint32_t>(&retry_count)->default_value(10),
132
177
N_("Retry Count."));
133
178
context("buffer-length",
134
po::value<buffer_constraint>(&buffer_length)->default_value(16384),
179
po::value<uint32_t>(&buffer_length)->default_value(16384),
135
180
N_("Buffer length."));
136
181
context("bind-address",
137
po::value<std::string>()->default_value(""),
138
183
N_("Address to bind to."));
139
context("max-connections",
140
po::value<uint32_t>(&ListenDrizzleProtocol::drizzle_counters->max_connections)->default_value(1000),
141
N_("Maximum simultaneous connections."));
142
context("admin-ip-addresses",
143
po::value<vector<string> >()->composing()->notifier(&ClientDrizzleProtocol::drizzle_compose_ip_addresses),
144
N_("A restrictive IP address list for incoming admin connections."));
186
static drizzle_sys_var* sys_variables[]= {
187
DRIZZLE_SYSVAR(port),
188
DRIZZLE_SYSVAR(connect_timeout),
189
DRIZZLE_SYSVAR(read_timeout),
190
DRIZZLE_SYSVAR(write_timeout),
191
DRIZZLE_SYSVAR(retry_count),
192
DRIZZLE_SYSVAR(buffer_length),
193
DRIZZLE_SYSVAR(bind_address),
147
197
} /* namespace drizzle_protocol */
148
} /* namespace drizzle_plugin */
150
DRIZZLE_PLUGIN(drizzle_plugin::drizzle_protocol::init, NULL, drizzle_plugin::drizzle_protocol::init_options);
199
DRIZZLE_PLUGIN(drizzle_protocol::init, drizzle_protocol::sys_variables, drizzle_protocol::init_options);