~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/mysql_protocol/mysql_protocol.cc

  • Committer: Brian Aker
  • Date: 2010-07-09 17:59:07 UTC
  • Revision ID: brian@gaz-20100709175907-h014kkb6cztsr21d
Fix const_cast, disable the unittest for generators.

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
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or modify
7
7
 * it under the terms of the GNU General Public License as published by
14
14
 *
15
15
 * You should have received a copy of the GNU General Public License
16
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
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
 */
19
19
 
20
 
#include <config.h>
 
20
#include "config.h"
21
21
#include <drizzled/gettext.h>
22
22
#include <drizzled/error.h>
23
23
#include <drizzled/query_id.h>
24
 
#include <drizzled/error/sql_state.h>
 
24
#include <drizzled/sql_state.h>
25
25
#include <drizzled/session.h>
26
 
#include <drizzled/internal/m_string.h>
 
26
#include "drizzled/internal/m_string.h"
27
27
#include <algorithm>
28
28
#include <boost/program_options.hpp>
29
29
#include <drizzled/module/option_map.h>
30
 
#include <drizzled/util/tokenize.h>
31
30
#include "errmsg.h"
32
31
#include "mysql_protocol.h"
33
32
#include "mysql_password.h"
34
33
#include "options.h"
35
34
 
36
 
#include <drizzled/identifier.h>
37
 
 
38
 
#include <libdrizzle/constants.h>
39
 
 
40
 
#define PROTOCOL_VERSION 10
41
 
 
42
35
namespace po= boost::program_options;
43
36
using namespace std;
44
37
using namespace drizzled;
45
38
 
46
 
namespace drizzle_plugin
 
39
#define PROTOCOL_VERSION 10
 
40
 
 
41
namespace drizzled
47
42
{
 
43
extern uint32_t global_thread_id;
 
44
}
48
45
 
49
 
std::vector<std::string> ClientMySQLProtocol::mysql_admin_ip_addresses;
50
46
static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024;
51
 
 
52
 
static port_constraint port;
53
 
static timeout_constraint connect_timeout;
54
 
static timeout_constraint read_timeout;
55
 
static timeout_constraint write_timeout;
56
 
static retry_constraint retry_count;
57
 
static buffer_constraint buffer_length;
58
 
 
 
47
static uint32_t port;
 
48
static uint32_t connect_timeout;
 
49
static uint32_t read_timeout;
 
50
static uint32_t write_timeout;
 
51
static uint32_t retry_count;
 
52
static uint32_t buffer_length;
 
53
static char* bind_address;
59
54
static uint32_t random_seed1;
60
55
static uint32_t random_seed2;
61
56
static const uint32_t random_max= 0x3FFFFFFF;
62
57
static const double random_max_double= (double)0x3FFFFFFF;
63
58
 
64
 
 
65
 
ProtocolCounters *ListenMySQLProtocol::mysql_counters= new ProtocolCounters();
66
 
 
67
 
ListenMySQLProtocol::~ListenMySQLProtocol()
68
 
{ }
69
 
 
70
 
void ListenMySQLProtocol::addCountersToTable()
71
 
{
72
 
  counters.push_back(new drizzled::plugin::ListenCounter(new std::string("connection_count"), &getCounters()->connectionCount));
73
 
  counters.push_back(new drizzled::plugin::ListenCounter(new std::string("connected"), &getCounters()->connected));
74
 
  counters.push_back(new drizzled::plugin::ListenCounter(new std::string("failed_connections"), &getCounters()->failedConnections));
75
 
}
76
 
 
77
 
const std::string ListenMySQLProtocol::getHost(void) const
78
 
{
79
 
  return _hostname;
 
59
const char* ListenMySQLProtocol::getHost(void) const
 
60
{
 
61
  return bind_address;
80
62
}
81
63
 
82
64
in_port_t ListenMySQLProtocol::getPort(void) const
83
65
{
84
 
  return port.get();
 
66
  return (in_port_t) port;
85
67
}
86
68
 
87
69
plugin::Client *ListenMySQLProtocol::getClient(int fd)
91
73
  if (new_fd == -1)
92
74
    return NULL;
93
75
 
94
 
  return new ClientMySQLProtocol(new_fd, _using_mysql41_protocol, getCounters());
 
76
  return new (nothrow) ClientMySQLProtocol(new_fd, using_mysql41_protocol);
95
77
}
96
78
 
97
 
ClientMySQLProtocol::ClientMySQLProtocol(int fd, bool using_mysql41_protocol, ProtocolCounters *set_counters):
98
 
  is_admin_connection(false),
99
 
  _using_mysql41_protocol(using_mysql41_protocol),
100
 
  counters(set_counters)
 
79
ClientMySQLProtocol::ClientMySQLProtocol(int fd, bool using_mysql41_protocol_arg):
 
80
  using_mysql41_protocol(using_mysql41_protocol_arg)
101
81
{
102
 
  
103
82
  net.vio= 0;
104
83
 
105
84
  if (fd == -1)
106
85
    return;
107
86
 
108
 
  if (drizzleclient_net_init_sock(&net, fd, buffer_length.get()))
 
87
  if (drizzleclient_net_init_sock(&net, fd, buffer_length))
109
88
    throw bad_alloc();
110
89
 
111
 
  drizzleclient_net_set_read_timeout(&net, read_timeout.get());
112
 
  drizzleclient_net_set_write_timeout(&net, write_timeout.get());
113
 
  net.retry_count=retry_count.get();
 
90
  drizzleclient_net_set_read_timeout(&net, read_timeout);
 
91
  drizzleclient_net_set_write_timeout(&net, write_timeout);
 
92
  net.retry_count=retry_count;
114
93
}
115
94
 
116
95
ClientMySQLProtocol::~ClientMySQLProtocol()
117
96
{
118
97
  if (net.vio)
119
 
    net.vio->close();
 
98
    vio_close(net.vio);
120
99
}
121
100
 
122
101
int ClientMySQLProtocol::getFileDescriptor(void)
155
134
  { 
156
135
    drizzleclient_net_close(&net);
157
136
    drizzleclient_net_end(&net);
158
 
    if (is_admin_connection)
159
 
      counters->adminConnected.decrement();
160
 
    else
161
 
      counters->connected.decrement();
162
137
  }
163
138
}
164
139
 
165
140
bool ClientMySQLProtocol::authenticate()
166
141
{
167
142
  bool connection_is_valid;
168
 
  if (is_admin_connection)
169
 
  {
170
 
    counters->adminConnectionCount.increment();
171
 
    counters->adminConnected.increment();
172
 
  }
173
 
  else
174
 
  {
175
 
    counters->connectionCount.increment();
176
 
    counters->connected.increment();
177
 
  }
178
143
 
179
144
  /* Use "connect_timeout" value during connection phase */
180
 
  drizzleclient_net_set_read_timeout(&net, connect_timeout.get());
181
 
  drizzleclient_net_set_write_timeout(&net, connect_timeout.get());
 
145
  drizzleclient_net_set_read_timeout(&net, connect_timeout);
 
146
  drizzleclient_net_set_write_timeout(&net, connect_timeout);
182
147
 
183
148
  connection_is_valid= checkConnection();
184
149
 
185
150
  if (connection_is_valid)
186
 
  {
187
 
    if (not is_admin_connection and (counters->connected > counters->max_connections))
188
 
    {
189
 
      std::string errmsg(ER(ER_CON_COUNT_ERROR));
190
 
      sendError(ER_CON_COUNT_ERROR, errmsg.c_str());
191
 
      counters->failedConnections.increment();
192
 
    }
193
 
    else
194
 
    {
195
 
      sendOK();
196
 
    }
197
 
  }
 
151
    sendOK();
198
152
  else
199
153
  {
200
154
    sendError(session->main_da.sql_errno(), session->main_da.message());
201
 
    counters->failedConnections.increment();
202
155
    return false;
203
156
  }
204
157
 
205
158
  /* Connect completed, set read/write timeouts back to default */
206
 
  drizzleclient_net_set_read_timeout(&net, read_timeout.get());
207
 
  drizzleclient_net_set_write_timeout(&net, write_timeout.get());
 
159
  drizzleclient_net_set_read_timeout(&net, read_timeout);
 
160
  drizzleclient_net_set_write_timeout(&net, write_timeout);
208
161
  return true;
209
162
}
210
163
 
241
194
      return false;                       // We have to close it.
242
195
 
243
196
    net.error= 0;
 
197
    *packet_length= 0;
 
198
    return true;
244
199
  }
245
200
 
246
201
  *l_packet= (char*) net.read_pos;
260
215
    (*l_packet)[0]= (unsigned char) COM_SLEEP;
261
216
    *packet_length= 1;
262
217
  }
263
 
  else if (_using_mysql41_protocol)
 
218
  else if (using_mysql41_protocol)
264
219
  {
265
220
    /* Map from MySQL commands to Drizzle commands. */
266
221
    switch ((int)(*l_packet)[0])
400
355
    drizzleclient_net_flush(&net);
401
356
    session->main_da.can_overwrite_status= false;
402
357
  }
403
 
  packet.shrink(buffer_length.get());
 
358
  packet.shrink(buffer_length);
404
359
}
405
360
 
406
361
 
407
 
void ClientMySQLProtocol::sendError(drizzled::error_t sql_errno, const char *err)
 
362
void ClientMySQLProtocol::sendError(uint32_t sql_errno, const char *err)
408
363
{
409
364
  uint32_t length;
410
365
  /*
412
367
  */
413
368
  unsigned char buff[2+1+SQLSTATE_LENGTH+DRIZZLE_ERRMSG_SIZE], *pos;
414
369
 
415
 
  assert(sql_errno != EE_OK);
 
370
  assert(sql_errno);
416
371
  assert(err && err[0]);
417
372
 
418
373
  /*
437
392
    return;
438
393
  }
439
394
 
440
 
  int2store(buff, static_cast<uint16_t>(sql_errno));
 
395
  int2store(buff,sql_errno);
441
396
  pos= buff+2;
442
397
 
443
398
  /* The first # is to make the client backward compatible */
444
399
  buff[2]= '#';
445
 
  pos= (unsigned char*) strcpy((char*) buff+3, error::convert_to_sqlstate(sql_errno));
446
 
  pos+= strlen(error::convert_to_sqlstate(sql_errno));
 
400
  pos= (unsigned char*) strcpy((char*) buff+3, drizzle_errno_to_sqlstate(sql_errno));
 
401
  pos+= strlen(drizzle_errno_to_sqlstate(sql_errno));
447
402
 
448
403
  char *tmp= strncpy((char*)pos, err, DRIZZLE_ERRMSG_SIZE-1);
449
404
  tmp+= strlen((char*)pos);
453
408
 
454
409
  drizzleclient_net_write_command(&net,(unsigned char) 255, (unsigned char*) "", 0, (unsigned char*) err, length);
455
410
 
456
 
  drizzleclient_net_flush(&net);
457
 
 
458
411
  session->main_da.can_overwrite_status= false;
459
412
}
460
413
 
478
431
*/
479
432
bool ClientMySQLProtocol::sendFields(List<Item> *list)
480
433
{
481
 
  List<Item>::iterator it(list->begin());
 
434
  List_iterator_fast<Item> it(*list);
482
435
  Item *item;
483
436
  unsigned char buff[80];
484
437
  String tmp((char*) buff,sizeof(buff),&my_charset_bin);
510
463
    int2store(pos, field.charsetnr);
511
464
    int4store(pos+2, field.length);
512
465
 
513
 
    if (_using_mysql41_protocol)
 
466
    if (using_mysql41_protocol)
514
467
    {
515
468
      /* Switch to MySQL field numbering. */
516
469
      switch (field.type)
539
492
        pos[6]= 12;
540
493
        break;
541
494
 
542
 
      case DRIZZLE_TYPE_TIME:
543
 
        pos[6]= 13;
544
 
        break;
545
 
 
546
495
      case DRIZZLE_TYPE_DATE:
547
496
        pos[6]= 14;
548
497
        break;
551
500
        pos[6]= 15;
552
501
        break;
553
502
 
554
 
      case DRIZZLE_TYPE_MICROTIME:
555
 
        pos[6]= 15;
556
 
        break;
557
 
 
558
 
      case DRIZZLE_TYPE_UUID:
559
 
        pos[6]= 15;
560
 
        break;
561
 
 
562
 
      case DRIZZLE_TYPE_BOOLEAN:
563
 
        pos[6]= DRIZZLE_COLUMN_TYPE_TINY;
564
 
        break;
565
 
 
566
503
      case DRIZZLE_TYPE_DECIMAL:
567
504
        pos[6]= (char)246;
568
505
        break;
611
548
{
612
549
  if (from->is_null())
613
550
    return store();
614
 
  if (from->type() == DRIZZLE_TYPE_BOOLEAN)
615
 
  {
616
 
    return store(from->val_int());
617
 
  }
618
 
 
619
551
  char buff[MAX_FIELD_WIDTH];
620
552
  String str(buff,sizeof(buff), &my_charset_bin);
621
553
 
622
 
  from->val_str_internal(&str);
 
554
  from->val_str(&str);
623
555
 
624
556
  return netStoreData((const unsigned char *)str.ptr(), str.length());
625
557
}
690
622
  uint32_t pkt_len= 0;
691
623
  char *end;
692
624
  char scramble[SCRAMBLE_LENGTH];
693
 
  identifier::User::shared_ptr user_identifier= identifier::User::make_shared();
694
625
 
695
626
  makeScramble(scramble);
696
627
 
701
632
 
702
633
    if (drizzleclient_net_peer_addr(&net, ip, &peer_port, NI_MAXHOST))
703
634
    {
704
 
      my_error(ER_BAD_HOST_ERROR, MYF(0), ip);
 
635
      my_error(ER_BAD_HOST_ERROR, MYF(0), session->getSecurityContext().getIp().c_str());
705
636
      return false;
706
637
    }
707
638
 
708
 
    user_identifier->setAddress(ip);
 
639
    session->getSecurityContext().setIp(ip);
709
640
  }
710
641
  drizzleclient_net_keepalive(&net, true);
711
642
 
716
647
 
717
648
    server_capabilites= CLIENT_BASIC_FLAGS;
718
649
 
719
 
    if (_using_mysql41_protocol)
 
650
    if (using_mysql41_protocol)
720
651
      server_capabilites|= CLIENT_PROTOCOL_MYSQL41;
721
652
 
722
653
#ifdef HAVE_COMPRESS
730
661
    *end= 0;
731
662
    end++;
732
663
 
733
 
    int4store((unsigned char*) end, session->variables.pseudo_thread_id);
 
664
    int4store((unsigned char*) end, global_thread_id);
734
665
    end+= 4;
735
666
 
736
667
    /* We don't use scramble anymore. */
760
691
        ||    (pkt_len= drizzleclient_net_read(&net)) == packet_error 
761
692
        || pkt_len < MIN_HANDSHAKE_SIZE)
762
693
    {
763
 
      my_error(ER_HANDSHAKE_ERROR, MYF(0), user_identifier->address().c_str());
 
694
      my_error(ER_HANDSHAKE_ERROR, MYF(0), session->getSecurityContext().getIp().c_str());
764
695
      return false;
765
696
    }
766
697
  }
767
 
  if (packet.alloc(buffer_length.get()))
 
698
  if (packet.alloc(buffer_length))
768
699
    return false; /* The error is set by alloc(). */
769
700
 
770
701
  client_capabilities= uint2korr(net.read_pos);
771
702
  if (!(client_capabilities & CLIENT_PROTOCOL_MYSQL41))
772
703
  {
773
 
    my_error(ER_HANDSHAKE_ERROR, MYF(0), user_identifier->address().c_str());
 
704
    my_error(ER_HANDSHAKE_ERROR, MYF(0), session->getSecurityContext().getIp().c_str());
774
705
    return false;
775
706
  }
776
707
 
786
717
 
787
718
  if (end >= (char*) net.read_pos + pkt_len + 2)
788
719
  {
789
 
    my_error(ER_HANDSHAKE_ERROR, MYF(0), user_identifier->address().c_str());
 
720
    my_error(ER_HANDSHAKE_ERROR, MYF(0), session->getSecurityContext().getIp().c_str());
790
721
    return false;
791
722
  }
792
723
 
810
741
    passwd_len= (unsigned char)(*passwd++);
811
742
    if (passwd_len > 0)
812
743
    {
813
 
      user_identifier->setPasswordType(identifier::User::MYSQL_HASH);
814
 
      user_identifier->setPasswordContext(scramble, SCRAMBLE_LENGTH);
 
744
      session->getSecurityContext().setPasswordType(SecurityContext::MYSQL_HASH);
 
745
      session->getSecurityContext().setPasswordContext(scramble, SCRAMBLE_LENGTH);
815
746
    }
816
747
  }
817
748
  else
818
 
  {
819
749
    passwd_len= 0;
820
 
  }
821
750
 
822
751
  if (client_capabilities & CLIENT_CONNECT_WITH_DB &&
823
752
      passwd < (char *) net.read_pos + pkt_len)
825
754
    l_db= l_db + passwd_len + 1;
826
755
  }
827
756
  else
828
 
  {
829
757
    l_db= NULL;
830
 
  }
831
758
 
832
759
  /* strlen() can't be easily deleted without changing client */
833
760
  uint32_t db_len= l_db ? strlen(l_db) : 0;
834
761
 
835
762
  if (passwd + passwd_len + db_len > (char *) net.read_pos + pkt_len)
836
763
  {
837
 
    my_error(ER_HANDSHAKE_ERROR, MYF(0), user_identifier->address().c_str());
 
764
    my_error(ER_HANDSHAKE_ERROR, MYF(0), session->getSecurityContext().getIp().c_str());
838
765
    return false;
839
766
  }
840
767
 
846
773
    user_len-= 2;
847
774
  }
848
775
 
849
 
  if (client_capabilities & CLIENT_ADMIN)
850
 
  {
851
 
    if ((strncmp(user, "root", 4) == 0) and isAdminAllowed())
852
 
    {
853
 
      is_admin_connection= true;
854
 
    }
855
 
    else
856
 
    {
857
 
      my_error(ER_ADMIN_ACCESS, MYF(0));
858
 
      return false;
859
 
    }
860
 
  }
861
 
 
862
 
  user_identifier->setUser(user);
863
 
  session->setUser(user_identifier);
864
 
 
865
 
  return session->checkUser(string(passwd, passwd_len),
866
 
                            string(l_db ? l_db : ""));
867
 
 
868
 
}
869
 
 
870
 
bool ClientMySQLProtocol::isAdminAllowed(void)
871
 
{
872
 
  if (std::find(mysql_admin_ip_addresses.begin(), mysql_admin_ip_addresses.end(), session->user()->address()) != mysql_admin_ip_addresses.end())
873
 
    return true;
874
 
 
875
 
  return false;
 
776
  session->getSecurityContext().setUser(user);
 
777
 
 
778
  return session->checkUser(passwd, passwd_len, l_db);
876
779
}
877
780
 
878
781
bool ClientMySQLProtocol::netStoreData(const unsigned char *from, size_t length)
967
870
  uint32_t pointer_seed;
968
871
  memcpy(&pointer_seed, &pointer, 4);
969
872
  uint32_t random1= (seed + pointer_seed) % random_max;
970
 
  uint32_t random2= (seed + session->variables.pseudo_thread_id + net.vio->get_fd()) % random_max;
 
873
  uint32_t random2= (seed + global_thread_id + net.vio->sd) % random_max;
971
874
 
972
875
  for (char *end= scramble + SCRAMBLE_LENGTH; scramble != end; scramble++)
973
876
  {
977
880
  }
978
881
}
979
882
 
980
 
void ClientMySQLProtocol::mysql_compose_ip_addresses(vector<string> options)
981
 
{
982
 
  for (vector<string>::iterator it= options.begin();
983
 
       it != options.end();
984
 
       ++it)
985
 
  {
986
 
    tokenize(*it, mysql_admin_ip_addresses, ",", true);
987
 
  }
988
 
}
989
 
 
990
883
static ListenMySQLProtocol *listen_obj= NULL;
991
884
plugin::Create_function<MySQLPassword> *mysql_password= NULL;
992
885
 
993
886
static int init(drizzled::module::Context &context)
994
887
{  
 
888
 
995
889
  /* Initialize random seeds for the MySQL algorithm with minimal changes. */
996
890
  time_t seed_time= time(NULL);
997
891
  random_seed1= seed_time % random_max;
998
892
  random_seed2= (seed_time / 2) % random_max;
999
893
 
1000
894
  const module::option_map &vm= context.getOptions();
 
895
  if (vm.count("port"))
 
896
  { 
 
897
    if (port > 65535)
 
898
    {
 
899
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of port\n"));
 
900
      exit(-1);
 
901
    }
 
902
  }
 
903
 
 
904
  if (vm.count("connect-timeout"))
 
905
  {
 
906
    if (connect_timeout < 1 || connect_timeout > 300)
 
907
    {
 
908
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for connect_timeout\n"));
 
909
      exit(-1);
 
910
    }
 
911
  }
 
912
 
 
913
  if (vm.count("read-timeout"))
 
914
  {
 
915
    if (read_timeout < 1 || read_timeout > 300)
 
916
    {
 
917
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for read_timeout\n"));
 
918
      exit(-1);
 
919
    }
 
920
  }
 
921
 
 
922
  if (vm.count("write-timeout"))
 
923
  {
 
924
    if (write_timeout < 1 || write_timeout > 300)
 
925
    {
 
926
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for write_timeout\n"));
 
927
      exit(-1);
 
928
    }
 
929
  }
 
930
 
 
931
  if (vm.count("retry-count"))
 
932
  {
 
933
    if (retry_count < 1 || retry_count > 100)
 
934
    {
 
935
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for retry_count"));
 
936
      exit(-1);
 
937
    }
 
938
  }
 
939
 
 
940
  if (vm.count("buffer-length"))
 
941
  {
 
942
    if (buffer_length < 1024 || buffer_length > 1024*1024)
 
943
    {
 
944
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for buffer_length\n"));
 
945
      exit(-1);
 
946
    }
 
947
  }
 
948
 
 
949
  if (vm.count("bind-address"))
 
950
  {
 
951
    bind_address= strdup(vm["bind-address"].as<string>().c_str());
 
952
  }
 
953
 
 
954
  else
 
955
  {
 
956
    bind_address= NULL;
 
957
  }
1001
958
 
1002
959
  mysql_password= new plugin::Create_function<MySQLPassword>(MySQLPasswordName);
1003
960
  context.add(mysql_password);
1004
961
 
1005
 
  listen_obj= new ListenMySQLProtocol("mysql_protocol", vm["bind-address"].as<std::string>(), true);
1006
 
  listen_obj->addCountersToTable();
 
962
  listen_obj= new ListenMySQLProtocol("mysql_protocol", true);
1007
963
  context.add(listen_obj); 
1008
 
  context.registerVariable(new sys_var_constrained_value_readonly<in_port_t>("port", port));
1009
 
  context.registerVariable(new sys_var_constrained_value<uint32_t>("connect_timeout", connect_timeout));
1010
 
  context.registerVariable(new sys_var_constrained_value<uint32_t>("read_timeout", read_timeout));
1011
 
  context.registerVariable(new sys_var_constrained_value<uint32_t>("write_timeout", write_timeout));
1012
 
  context.registerVariable(new sys_var_constrained_value<uint32_t>("retry_count", retry_count));
1013
 
  context.registerVariable(new sys_var_constrained_value<uint32_t>("buffer_length", buffer_length));
1014
 
  context.registerVariable(new sys_var_const_string_val("bind_address",
1015
 
                                                        vm["bind-address"].as<std::string>()));
1016
 
 
1017
 
  context.registerVariable(new sys_var_uint32_t_ptr("max-connections", &ListenMySQLProtocol::mysql_counters->max_connections));
1018
964
 
1019
965
  return 0;
1020
966
}
1021
967
 
 
968
static DRIZZLE_SYSVAR_UINT(port, port, PLUGIN_VAR_RQCMDARG,
 
969
                           N_("Port number to use for connection or 0 for default to with MySQL "
 
970
                              "protocol."),
 
971
                           NULL, NULL, 3306, 0, 65535, 0);
 
972
static DRIZZLE_SYSVAR_UINT(connect_timeout, connect_timeout,
 
973
                           PLUGIN_VAR_RQCMDARG, N_("Connect Timeout."),
 
974
                           NULL, NULL, 10, 1, 300, 0);
 
975
static DRIZZLE_SYSVAR_UINT(read_timeout, read_timeout, PLUGIN_VAR_RQCMDARG,
 
976
                           N_("Read Timeout."), NULL, NULL, 30, 1, 300, 0);
 
977
static DRIZZLE_SYSVAR_UINT(write_timeout, write_timeout, PLUGIN_VAR_RQCMDARG,
 
978
                           N_("Write Timeout."), NULL, NULL, 60, 1, 300, 0);
 
979
static DRIZZLE_SYSVAR_UINT(retry_count, retry_count, PLUGIN_VAR_RQCMDARG,
 
980
                           N_("Retry Count."), NULL, NULL, 10, 1, 100, 0);
 
981
static DRIZZLE_SYSVAR_UINT(buffer_length, buffer_length, PLUGIN_VAR_RQCMDARG,
 
982
                           N_("Buffer length."), NULL, NULL, 16384, 1024,
 
983
                           1024*1024, 0);
 
984
static DRIZZLE_SYSVAR_STR(bind_address, bind_address, PLUGIN_VAR_READONLY,
 
985
                          N_("Address to bind to."), NULL, NULL, NULL);
 
986
 
1022
987
static void init_options(drizzled::module::option_context &context)
1023
988
{
1024
989
  context("port",
1025
 
          po::value<port_constraint>(&port)->default_value(3306),
1026
 
          _("Port number to use for connection or 0 for default to with MySQL "
 
990
          po::value<uint32_t>(&port)->default_value(3306),
 
991
          N_("Port number to use for connection or 0 for default to with MySQL "
1027
992
                              "protocol."));
1028
993
  context("connect-timeout",
1029
 
          po::value<timeout_constraint>(&connect_timeout)->default_value(10),
1030
 
          _("Connect Timeout."));
 
994
          po::value<uint32_t>(&connect_timeout)->default_value(10),
 
995
          N_("Connect Timeout."));
1031
996
  context("read-timeout",
1032
 
          po::value<timeout_constraint>(&read_timeout)->default_value(30),
1033
 
          _("Read Timeout."));
 
997
          po::value<uint32_t>(&read_timeout)->default_value(30),
 
998
          N_("Read Timeout."));
1034
999
  context("write-timeout",
1035
 
          po::value<timeout_constraint>(&write_timeout)->default_value(60),
1036
 
          _("Write Timeout."));
 
1000
          po::value<uint32_t>(&write_timeout)->default_value(60),
 
1001
          N_("Write Timeout."));
1037
1002
  context("retry-count",
1038
 
          po::value<retry_constraint>(&retry_count)->default_value(10),
1039
 
          _("Retry Count."));
 
1003
          po::value<uint32_t>(&retry_count)->default_value(10),
 
1004
          N_("Retry Count."));
1040
1005
  context("buffer-length",
1041
 
          po::value<buffer_constraint>(&buffer_length)->default_value(16384),
1042
 
          _("Buffer length."));
 
1006
          po::value<uint32_t>(&buffer_length)->default_value(16384),
 
1007
          N_("Buffer length."));
1043
1008
  context("bind-address",
1044
 
          po::value<string>()->default_value(""),
1045
 
          _("Address to bind to."));
1046
 
  context("max-connections",
1047
 
          po::value<uint32_t>(&ListenMySQLProtocol::mysql_counters->max_connections)->default_value(1000),
1048
 
          _("Maximum simultaneous connections."));
1049
 
  context("admin-ip-addresses",
1050
 
          po::value<vector<string> >()->composing()->notifier(&ClientMySQLProtocol::mysql_compose_ip_addresses),
1051
 
          _("A restrictive IP address list for incoming admin connections."));
 
1009
          po::value<string>(),
 
1010
          N_("Address to bind to."));
1052
1011
}
1053
1012
 
1054
 
} /* namespace drizzle_plugin */
 
1013
static drizzle_sys_var* sys_variables[]= {
 
1014
  DRIZZLE_SYSVAR(port),
 
1015
  DRIZZLE_SYSVAR(connect_timeout),
 
1016
  DRIZZLE_SYSVAR(read_timeout),
 
1017
  DRIZZLE_SYSVAR(write_timeout),
 
1018
  DRIZZLE_SYSVAR(retry_count),
 
1019
  DRIZZLE_SYSVAR(buffer_length),
 
1020
  DRIZZLE_SYSVAR(bind_address),
 
1021
  NULL
 
1022
};
1055
1023
 
1056
1024
DRIZZLE_DECLARE_PLUGIN
1057
1025
{
1061
1029
  "Eric Day",
1062
1030
  "MySQL Protocol Module",
1063
1031
  PLUGIN_LICENSE_GPL,
1064
 
  drizzle_plugin::init,             /* Plugin Init */
1065
 
  NULL, /* depends */
1066
 
  drizzle_plugin::init_options    /* config options */
 
1032
  init,             /* Plugin Init */
 
1033
  sys_variables, /* system variables */
 
1034
  init_options    /* config options */
1067
1035
}
1068
1036
DRIZZLE_DECLARE_PLUGIN_END;