~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/drizzle_protocol/drizzle_protocol.cc

  • Committer: Lee Bieber
  • Date: 2010-10-27 18:28:56 UTC
  • mfrom: (1883.1.3 build)
  • Revision ID: kalebral@gmail.com-20101027182856-q3wqtbv1t4egkjsk
Merge Andrew - fix bug 667360: --defaults-file not processed before paths read           
Merge Andrew - fix bug 656577: Importing SQL script results in silent failure    
Merge Andrew - fix bug 667053: drizzledump minor output cleanup needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
 
4
<<<<<<< TREE
4
5
 *  Copyright (C) 2010 Brian Aker
5
6
 *
6
7
 *  This program is free software; you can redistribute it and/or modify
16
17
 *  You should have received a copy of the GNU General Public License
17
18
 *  along with this program; if not, write to the Free Software
18
19
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
20
=======
 
21
 *  Copyright (C) 2008 Sun Microsystems
 
22
 *
 
23
 * This program is free software; you can redistribute it and/or modify
 
24
 * it under the terms of the GNU General Public License as published by
 
25
 * the Free Software Foundation; version 2 of the License.
 
26
 *
 
27
 * This program is distributed in the hope that it will be useful,
 
28
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
29
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
30
 * GNU General Public License for more details.
 
31
 *
 
32
 * You should have received a copy of the GNU General Public License
 
33
 * along with this program; if not, write to the Free Software
 
34
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
35
>>>>>>> MERGE-SOURCE
19
36
 */
20
37
 
21
38
 
23
40
#include <drizzled/gettext.h>
24
41
#include <drizzled/error.h>
25
42
#include <drizzled/query_id.h>
 
43
#include <drizzled/sql_state.h>
26
44
#include <drizzled/session.h>
27
45
#include "drizzled/internal/my_sys.h"
28
46
#include "drizzled/internal/m_string.h"
30
48
#include <iostream>
31
49
#include <boost/program_options.hpp>
32
50
#include <drizzled/module/option_map.h>
33
 
#include "drizzled/util/tokenize.h"
34
51
#include "drizzle_protocol.h"
 
52
#include "plugin/drizzle_protocol/status_table.h"
35
53
 
36
54
namespace po= boost::program_options;
37
55
using namespace drizzled;
38
56
using namespace std;
39
57
 
40
 
namespace drizzle_plugin
41
 
{
42
58
namespace drizzle_protocol
43
59
{
44
60
 
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;
 
61
static uint32_t port;
 
62
static uint32_t connect_timeout;
 
63
static uint32_t read_timeout;
 
64
static uint32_t write_timeout;
 
65
static uint32_t retry_count;
 
66
static uint32_t buffer_length;
 
67
static char* bind_address;
52
68
 
53
69
static const uint32_t DRIZZLE_TCP_PORT= 4427;
54
70
 
55
 
ProtocolCounters *ListenDrizzleProtocol::drizzle_counters= new ProtocolCounters();
56
 
 
57
71
ListenDrizzleProtocol::~ListenDrizzleProtocol()
58
72
{
 
73
  /* This is strdup'd from the options */
 
74
  free(bind_address);
 
75
}
 
76
 
 
77
const char* ListenDrizzleProtocol::getHost(void) const
 
78
{
 
79
  return bind_address;
59
80
}
60
81
 
61
82
in_port_t ListenDrizzleProtocol::getPort(void) const
62
83
{
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());
 
84
  return (in_port_t) port;
92
85
}
93
86
 
94
87
static int init(drizzled::module::Context &context)
95
88
{  
96
89
  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));
 
90
  if (vm.count("port"))
 
91
  { 
 
92
    if (port > 65535)
 
93
    {
 
94
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of port\n"));
 
95
      exit(-1);
 
96
    }
 
97
  }
 
98
 
 
99
  if (vm.count("connect-timeout"))
 
100
  {
 
101
    if (connect_timeout < 1 || connect_timeout > 300)
 
102
    {
 
103
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for connect_timeout\n"));
 
104
      exit(-1);
 
105
    }
 
106
  }
 
107
 
 
108
  if (vm.count("read-timeout"))
 
109
  {
 
110
    if (read_timeout < 1 || read_timeout > 300)
 
111
    {
 
112
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for read_timeout\n"));
 
113
      exit(-1);
 
114
    }
 
115
  }
 
116
 
 
117
  if (vm.count("write-timeout"))
 
118
  {
 
119
    if (write_timeout < 1 || write_timeout > 300)
 
120
    {
 
121
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for write_timeout\n"));
 
122
      exit(-1);
 
123
    }
 
124
  }
 
125
 
 
126
  if (vm.count("retry-count"))
 
127
  {
 
128
    if (retry_count < 1 || retry_count > 100)
 
129
    {
 
130
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for retry_count"));
 
131
      exit(-1);
 
132
    }
 
133
  }
 
134
 
 
135
  if (vm.count("buffer-length"))
 
136
  {
 
137
    if (buffer_length < 1024 || buffer_length > 1024*1024)
 
138
    {
 
139
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for buffer_length\n"));
 
140
      exit(-1);
 
141
    }
 
142
  }
 
143
 
 
144
  if (vm.count("bind-address"))
 
145
  {
 
146
    bind_address= strdup(vm["bind-address"].as<string>().c_str());
 
147
  }
 
148
 
 
149
  else
 
150
  {
 
151
    bind_address= NULL;
 
152
  }
 
153
 
 
154
  context.add(new StatusTable);
 
155
  context.add(new ListenDrizzleProtocol("drizzle_protocol", true));
111
156
 
112
157
  return 0;
113
158
}
114
159
 
 
160
static DRIZZLE_SYSVAR_UINT(port, port, PLUGIN_VAR_RQCMDARG,
 
161
                           N_("Port number to use for connection or 0 for default to with Drizzle/MySQL protocol."),
 
162
                           NULL, NULL, DRIZZLE_TCP_PORT, 0, 65535, 0);
 
163
static DRIZZLE_SYSVAR_UINT(connect_timeout, connect_timeout,
 
164
                           PLUGIN_VAR_RQCMDARG, N_("Connect Timeout."),
 
165
                           NULL, NULL, 10, 1, 300, 0);
 
166
static DRIZZLE_SYSVAR_UINT(read_timeout, read_timeout, PLUGIN_VAR_RQCMDARG,
 
167
                           N_("Read Timeout."), NULL, NULL, 30, 1, 300, 0);
 
168
static DRIZZLE_SYSVAR_UINT(write_timeout, write_timeout, PLUGIN_VAR_RQCMDARG,
 
169
                           N_("Write Timeout."), NULL, NULL, 60, 1, 300, 0);
 
170
static DRIZZLE_SYSVAR_UINT(retry_count, retry_count, PLUGIN_VAR_RQCMDARG,
 
171
                           N_("Retry Count."), NULL, NULL, 10, 1, 100, 0);
 
172
static DRIZZLE_SYSVAR_UINT(buffer_length, buffer_length, PLUGIN_VAR_RQCMDARG,
 
173
                           N_("Buffer length."), NULL, NULL, 16384, 1024,
 
174
                           1024*1024, 0);
 
175
static DRIZZLE_SYSVAR_STR(bind_address, bind_address, PLUGIN_VAR_READONLY,
 
176
                          N_("Address to bind to."), NULL, NULL, NULL);
115
177
 
116
178
static void init_options(drizzled::module::option_context &context)
117
179
{
118
180
  context("port",
119
 
          po::value<port_constraint>(&port)->default_value(DRIZZLE_TCP_PORT),
 
181
          po::value<uint32_t>(&port)->default_value(DRIZZLE_TCP_PORT),
120
182
          N_("Port number to use for connection or 0 for default to with Drizzle/MySQL protocol."));
121
183
  context("connect-timeout",
122
 
          po::value<timeout_constraint>(&connect_timeout)->default_value(10),
 
184
          po::value<uint32_t>(&connect_timeout)->default_value(10),
123
185
          N_("Connect Timeout."));
124
186
  context("read-timeout",
125
 
          po::value<timeout_constraint>(&read_timeout)->default_value(30),
 
187
          po::value<uint32_t>(&read_timeout)->default_value(30),
126
188
          N_("Read Timeout."));
127
189
  context("write-timeout",
128
 
          po::value<timeout_constraint>(&write_timeout)->default_value(60),
 
190
          po::value<uint32_t>(&write_timeout)->default_value(60),
129
191
          N_("Write Timeout."));
130
192
  context("retry-count",
131
 
          po::value<retry_constraint>(&retry_count)->default_value(10),
 
193
          po::value<uint32_t>(&retry_count)->default_value(10),
132
194
          N_("Retry Count."));
133
195
  context("buffer-length",
134
 
          po::value<buffer_constraint>(&buffer_length)->default_value(16384),
 
196
          po::value<uint32_t>(&buffer_length)->default_value(16384),
135
197
          N_("Buffer length."));
136
198
  context("bind-address",
137
 
          po::value<std::string>()->default_value(""),
 
199
          po::value<string>(),
138
200
          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
201
}
146
202
 
 
203
static drizzle_sys_var* sys_variables[]= {
 
204
  DRIZZLE_SYSVAR(port),
 
205
  DRIZZLE_SYSVAR(connect_timeout),
 
206
  DRIZZLE_SYSVAR(read_timeout),
 
207
  DRIZZLE_SYSVAR(write_timeout),
 
208
  DRIZZLE_SYSVAR(retry_count),
 
209
  DRIZZLE_SYSVAR(buffer_length),
 
210
  DRIZZLE_SYSVAR(bind_address),
 
211
  NULL
 
212
};
 
213
 
147
214
} /* namespace drizzle_protocol */
148
 
} /* namespace drizzle_plugin */
149
215
 
150
 
DRIZZLE_PLUGIN(drizzle_plugin::drizzle_protocol::init, NULL, drizzle_plugin::drizzle_protocol::init_options);
 
216
DRIZZLE_PLUGIN(drizzle_protocol::init, drizzle_protocol::sys_variables, drizzle_protocol::init_options);