~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/drizzle_protocol/drizzle_protocol.cc

  • Committer: Stewart Smith
  • Author(s): Vasil Dimov
  • Date: 2010-12-06 06:43:46 UTC
  • mto: (2021.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1986.
  • Revision ID: stewart@flamingspork.com-20101206064346-nufczti0ml6c6ilk
Merge Revision revid:vasil.dimov@oracle.com-20100927170812-jma17im0ni8ve7ku from MySQL InnoDB

Original revid:vasil.dimov@oracle.com-20100927170812-jma17im0ni8ve7ku

Original Authors: Vasil Dimov <vasil.dimov@oracle.com>
Original commit message:
Use C-style comment instead of C++ in a C header.

Spotted by:     Davi Arnaut

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
 
22
 
#include <config.h>
 
22
#include "config.h"
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"
35
36
 
36
37
namespace po= boost::program_options;
37
38
using namespace drizzled;
38
39
using namespace std;
39
40
 
40
 
namespace drizzle_plugin
41
 
{
42
41
namespace drizzle_protocol
43
42
{
44
43
 
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;
 
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;
52
51
 
53
52
static const uint32_t DRIZZLE_TCP_PORT= 4427;
54
53
 
55
 
ProtocolCounters *ListenDrizzleProtocol::drizzle_counters= new ProtocolCounters();
56
 
 
57
54
ListenDrizzleProtocol::~ListenDrizzleProtocol()
58
55
{
 
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;
59
63
}
60
64
 
61
65
in_port_t ListenDrizzleProtocol::getPort(void) const
62
66
{
63
 
  return port;
64
 
}
65
 
 
66
 
void ClientDrizzleProtocol::drizzle_compose_ip_addresses(vector<string> options)
67
 
{
68
 
  for (vector<string>::iterator it= options.begin();
69
 
       it != options.end();
70
 
       ++it)
71
 
  {
72
 
    tokenize(*it, drizzle_admin_ip_addresses, ",", true);
73
 
  }
74
 
}
75
 
 
76
 
bool ClientDrizzleProtocol::isAdminAllowed(void)
77
 
{
78
 
  if (std::find(drizzle_admin_ip_addresses.begin(), drizzle_admin_ip_addresses.end(), session->user()->address()) != drizzle_admin_ip_addresses.end())
79
 
    return true;
80
 
 
81
 
  return false;
82
 
}
83
 
 
84
 
plugin::Client *ListenDrizzleProtocol::getClient(int fd)
85
 
{
86
 
  int new_fd;
87
 
  new_fd= acceptTcp(fd);
88
 
  if (new_fd == -1)
89
 
    return NULL;
90
 
 
91
 
  return new ClientDrizzleProtocol(new_fd, getCounters());
 
67
  return (in_port_t) port;
92
68
}
93
69
 
94
70
static int init(drizzled::module::Context &context)
95
71
{  
96
72
  const module::option_map &vm= context.getOptions();
97
 
 
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>()));
109
 
 
110
 
  context.registerVariable(new sys_var_uint32_t_ptr("max-connections", &ListenDrizzleProtocol::drizzle_counters->max_connections));
 
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
 
 
137
  context.add(new StatusTable);
 
138
  context.add(new ListenDrizzleProtocol("drizzle_protocol", true));
111
139
 
112
140
  return 0;
113
141
}
114
142
 
 
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);
115
160
 
116
161
static void init_options(drizzled::module::option_context &context)
117
162
{
118
163
  context("port",
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(""),
 
182
          po::value<string>(),
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."));
145
184
}
146
185
 
 
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
 
147
197
} /* namespace drizzle_protocol */
148
 
} /* namespace drizzle_plugin */
149
198
 
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);