~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/drizzle_protocol/drizzle_protocol.cc

  • Committer: Brian Aker
  • Date: 2010-12-18 10:14:05 UTC
  • mfrom: (2008.1.3 clean)
  • Revision ID: brian@tangent.org-20101218101405-qjbse29shi9coklg
Merge of user identifier work

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include <iostream>
32
32
#include <boost/program_options.hpp>
33
33
#include <drizzled/module/option_map.h>
 
34
#include "drizzled/util/tokenize.h"
34
35
#include "drizzle_protocol.h"
35
36
#include "plugin/drizzle_protocol/status_table.h"
36
37
 
38
39
using namespace drizzled;
39
40
using namespace std;
40
41
 
 
42
namespace drizzle_plugin
 
43
{
41
44
namespace drizzle_protocol
42
45
{
43
46
 
44
 
static uint32_t port;
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;
 
47
std::vector<std::string> ClientDrizzleProtocol::drizzle_admin_ip_addresses;
 
48
static port_constraint port;
 
49
static timeout_constraint connect_timeout;
 
50
static timeout_constraint read_timeout;
 
51
static timeout_constraint write_timeout;
 
52
static retry_constraint retry_count;
 
53
static buffer_constraint buffer_length;
51
54
 
52
55
static const uint32_t DRIZZLE_TCP_PORT= 4427;
53
56
 
 
57
ProtocolCounters *ListenDrizzleProtocol::drizzle_counters= new ProtocolCounters();
 
58
 
54
59
ListenDrizzleProtocol::~ListenDrizzleProtocol()
55
60
{
56
 
  /* This is strdup'd from the options */
57
 
  free(bind_address);
58
 
}
59
 
 
60
 
const char* ListenDrizzleProtocol::getHost(void) const
61
 
{
62
 
  return bind_address;
63
61
}
64
62
 
65
63
in_port_t ListenDrizzleProtocol::getPort(void) const
66
64
{
67
 
  return (in_port_t) port;
 
65
  return port;
 
66
}
 
67
 
 
68
void ClientDrizzleProtocol::drizzle_compose_ip_addresses(vector<string> options)
 
69
{
 
70
  for (vector<string>::iterator it= options.begin();
 
71
       it != options.end();
 
72
       ++it)
 
73
  {
 
74
    tokenize(*it, drizzle_admin_ip_addresses, ",", true);
 
75
  }
 
76
}
 
77
 
 
78
bool ClientDrizzleProtocol::isAdminAllowed(void)
 
79
{
 
80
  if (std::find(drizzle_admin_ip_addresses.begin(), drizzle_admin_ip_addresses.end(), session->user()->address()) != drizzle_admin_ip_addresses.end())
 
81
    return true;
 
82
 
 
83
  return false;
 
84
}
 
85
 
 
86
plugin::Client *ListenDrizzleProtocol::getClient(int fd)
 
87
{
 
88
  int new_fd;
 
89
  new_fd= acceptTcp(fd);
 
90
  if (new_fd == -1)
 
91
    return NULL;
 
92
 
 
93
  return new ClientDrizzleProtocol(new_fd, getCounters());
68
94
}
69
95
 
70
96
static int init(drizzled::module::Context &context)
71
97
{  
72
98
  const module::option_map &vm= context.getOptions();
73
 
  if (vm.count("port"))
74
 
  { 
75
 
    if (port > 65535)
76
 
    {
77
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of port\n"));
78
 
      exit(-1);
79
 
    }
80
 
  }
81
 
 
82
 
  if (vm.count("connect-timeout"))
83
 
  {
84
 
    if (connect_timeout < 1 || connect_timeout > 300)
85
 
    {
86
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for connect_timeout\n"));
87
 
      exit(-1);
88
 
    }
89
 
  }
90
 
 
91
 
  if (vm.count("read-timeout"))
92
 
  {
93
 
    if (read_timeout < 1 || read_timeout > 300)
94
 
    {
95
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for read_timeout\n"));
96
 
      exit(-1);
97
 
    }
98
 
  }
99
 
 
100
 
  if (vm.count("write-timeout"))
101
 
  {
102
 
    if (write_timeout < 1 || write_timeout > 300)
103
 
    {
104
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for write_timeout\n"));
105
 
      exit(-1);
106
 
    }
107
 
  }
108
 
 
109
 
  if (vm.count("retry-count"))
110
 
  {
111
 
    if (retry_count < 1 || retry_count > 100)
112
 
    {
113
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for retry_count"));
114
 
      exit(-1);
115
 
    }
116
 
  }
117
 
 
118
 
  if (vm.count("buffer-length"))
119
 
  {
120
 
    if (buffer_length < 1024 || buffer_length > 1024*1024)
121
 
    {
122
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for buffer_length\n"));
123
 
      exit(-1);
124
 
    }
125
 
  }
126
 
 
127
 
  if (vm.count("bind-address"))
128
 
  {
129
 
    bind_address= strdup(vm["bind-address"].as<string>().c_str());
130
 
  }
131
 
 
132
 
  else
133
 
  {
134
 
    bind_address= NULL;
135
 
  }
136
99
 
137
100
  context.add(new StatusTable);
138
 
  context.add(new ListenDrizzleProtocol("drizzle_protocol", true));
 
101
  context.add(new ListenDrizzleProtocol("drizzle_protocol", vm["bind-address"].as<std::string>(), true));
 
102
  context.registerVariable(new sys_var_constrained_value_readonly<in_port_t>("port", port));
 
103
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("connect_timeout", connect_timeout));
 
104
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("read_timeout", read_timeout));
 
105
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("write_timeout", write_timeout));
 
106
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("retry_count", retry_count));
 
107
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("buffer_length", buffer_length));
 
108
  context.registerVariable(new sys_var_const_string_val("bind_address",
 
109
                                                        vm["bind-address"].as<std::string>()));
 
110
 
 
111
  context.registerVariable(new sys_var_uint32_t_ptr("max-connections", &ListenDrizzleProtocol::drizzle_counters->max_connections));
139
112
 
140
113
  return 0;
141
114
}
142
115
 
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,
157
 
                           1024*1024, 0);
158
 
static DRIZZLE_SYSVAR_STR(bind_address, bind_address, PLUGIN_VAR_READONLY,
159
 
                          N_("Address to bind to."), NULL, NULL, NULL);
160
116
 
161
117
static void init_options(drizzled::module::option_context &context)
162
118
{
163
119
  context("port",
164
 
          po::value<uint32_t>(&port)->default_value(DRIZZLE_TCP_PORT),
 
120
          po::value<port_constraint>(&port)->default_value(DRIZZLE_TCP_PORT),
165
121
          N_("Port number to use for connection or 0 for default to with Drizzle/MySQL protocol."));
166
122
  context("connect-timeout",
167
 
          po::value<uint32_t>(&connect_timeout)->default_value(10),
 
123
          po::value<timeout_constraint>(&connect_timeout)->default_value(10),
168
124
          N_("Connect Timeout."));
169
125
  context("read-timeout",
170
 
          po::value<uint32_t>(&read_timeout)->default_value(30),
 
126
          po::value<timeout_constraint>(&read_timeout)->default_value(30),
171
127
          N_("Read Timeout."));
172
128
  context("write-timeout",
173
 
          po::value<uint32_t>(&write_timeout)->default_value(60),
 
129
          po::value<timeout_constraint>(&write_timeout)->default_value(60),
174
130
          N_("Write Timeout."));
175
131
  context("retry-count",
176
 
          po::value<uint32_t>(&retry_count)->default_value(10),
 
132
          po::value<retry_constraint>(&retry_count)->default_value(10),
177
133
          N_("Retry Count."));
178
134
  context("buffer-length",
179
 
          po::value<uint32_t>(&buffer_length)->default_value(16384),
 
135
          po::value<buffer_constraint>(&buffer_length)->default_value(16384),
180
136
          N_("Buffer length."));
181
137
  context("bind-address",
182
 
          po::value<string>(),
 
138
          po::value<std::string>()->default_value(""),
183
139
          N_("Address to bind to."));
 
140
  context("max-connections",
 
141
          po::value<uint32_t>(&ListenDrizzleProtocol::drizzle_counters->max_connections)->default_value(1000),
 
142
          N_("Maximum simultaneous connections."));
 
143
  context("admin-ip-addresses",
 
144
          po::value<vector<string> >()->composing()->notifier(&ClientDrizzleProtocol::drizzle_compose_ip_addresses),
 
145
          N_("A restrictive IP address list for incoming admin connections."));
184
146
}
185
147
 
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),
194
 
  NULL
195
 
};
196
 
 
197
148
} /* namespace drizzle_protocol */
 
149
} /* namespace drizzle_plugin */
198
150
 
199
 
DRIZZLE_PLUGIN(drizzle_protocol::init, drizzle_protocol::sys_variables, drizzle_protocol::init_options);
 
151
DRIZZLE_PLUGIN(drizzle_plugin::drizzle_protocol::init, NULL, drizzle_plugin::drizzle_protocol::init_options);