~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/drizzle_protocol/oldlibdrizzle.cc

  • Committer: Eric Day
  • Date: 2009-11-10 21:50:22 UTC
  • mto: This revision was merged to the branch mainline in revision 1218.
  • Revision ID: eday@oddments.org-20091110215022-0b2nqmurv7b2l6wo
Duplicated oldlibdrizzle module, one for Drizzle protocol and one for MySQL, per Brian's request from merge proposal. Port options are now --drizzle-protocol-port and --mysql-protocol-port.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024;
39
39
static uint32_t port;
40
 
static uint32_t mysql_port;
41
40
static uint32_t connect_timeout;
42
41
static uint32_t read_timeout;
43
42
static uint32_t write_timeout;
45
44
static uint32_t buffer_length;
46
45
static char* bind_address;
47
46
 
48
 
const char* ListenOldLibdrizzle::getHost(void) const
 
47
const char* ListenDrizzleProtocol::getHost(void) const
49
48
{
50
49
  return bind_address;
51
50
}
52
51
 
53
 
in_port_t ListenOldLibdrizzle::getPort(void) const
 
52
in_port_t ListenDrizzleProtocol::getPort(void) const
54
53
{
55
54
  struct servent *serv_ptr;
56
55
  char *env;
57
56
 
58
 
  if (using_mysql41_protocol)
59
 
    return (in_port_t) mysql_port;
60
 
 
61
57
  if (port == 0)
62
58
  {
63
59
    port= DRIZZLE_TCP_PORT;
77
73
  return (in_port_t) port;
78
74
}
79
75
 
80
 
plugin::Client *ListenOldLibdrizzle::getClient(int fd)
 
76
plugin::Client *ListenDrizzleProtocol::getClient(int fd)
81
77
{
82
78
  int new_fd;
83
79
  new_fd= acceptTcp(fd);
84
80
  if (new_fd == -1)
85
81
    return NULL;
86
82
 
87
 
  return new (nothrow) ClientOldLibdrizzle(new_fd, using_mysql41_protocol);
 
83
  return new (nothrow) ClientDrizzleProtocol(new_fd, using_mysql41_protocol);
88
84
}
89
85
 
90
 
ClientOldLibdrizzle::ClientOldLibdrizzle(int fd, bool using_mysql41_protocol_arg):
 
86
ClientDrizzleProtocol::ClientDrizzleProtocol(int fd, bool using_mysql41_protocol_arg):
91
87
  using_mysql41_protocol(using_mysql41_protocol_arg)
92
88
{
93
89
  net.vio= 0;
103
99
  net.retry_count=retry_count;
104
100
}
105
101
 
106
 
ClientOldLibdrizzle::~ClientOldLibdrizzle()
 
102
ClientDrizzleProtocol::~ClientDrizzleProtocol()
107
103
{
108
104
  if (net.vio)
109
105
    drizzleclient_vio_close(net.vio);
110
106
}
111
107
 
112
 
int ClientOldLibdrizzle::getFileDescriptor(void)
 
108
int ClientDrizzleProtocol::getFileDescriptor(void)
113
109
{
114
110
  return drizzleclient_net_get_sd(&net);
115
111
}
116
112
 
117
 
bool ClientOldLibdrizzle::isConnected()
 
113
bool ClientDrizzleProtocol::isConnected()
118
114
{
119
115
  return net.vio != 0;
120
116
}
121
117
 
122
 
bool ClientOldLibdrizzle::isReading(void)
 
118
bool ClientDrizzleProtocol::isReading(void)
123
119
{
124
120
  return net.reading_or_writing == 1;
125
121
}
126
122
 
127
 
bool ClientOldLibdrizzle::isWriting(void)
 
123
bool ClientDrizzleProtocol::isWriting(void)
128
124
{
129
125
  return net.reading_or_writing == 2;
130
126
}
131
127
 
132
 
bool ClientOldLibdrizzle::flush()
 
128
bool ClientDrizzleProtocol::flush()
133
129
{
134
130
  if (net.vio == NULL)
135
131
    return false;
139
135
  return ret;
140
136
}
141
137
 
142
 
void ClientOldLibdrizzle::close(void)
 
138
void ClientDrizzleProtocol::close(void)
143
139
{
144
140
  if (net.vio)
145
141
  { 
148
144
  }
149
145
}
150
146
 
151
 
bool ClientOldLibdrizzle::authenticate()
 
147
bool ClientDrizzleProtocol::authenticate()
152
148
{
153
149
  bool connection_is_valid;
154
150
 
172
168
  return true;
173
169
}
174
170
 
175
 
bool ClientOldLibdrizzle::readCommand(char **l_packet, uint32_t *packet_length)
 
171
bool ClientDrizzleProtocol::readCommand(char **l_packet, uint32_t *packet_length)
176
172
{
177
173
  /*
178
174
    This thread will do a blocking read from the client which
288
284
  @param message       Message to send to the client (Used by mysql_status)
289
285
*/
290
286
 
291
 
void ClientOldLibdrizzle::sendOK()
 
287
void ClientDrizzleProtocol::sendOK()
292
288
{
293
289
  unsigned char buff[DRIZZLE_ERRMSG_SIZE+10],*pos;
294
290
  const char *message= NULL;
355
351
  client.
356
352
*/
357
353
 
358
 
void ClientOldLibdrizzle::sendEOF()
 
354
void ClientDrizzleProtocol::sendEOF()
359
355
{
360
356
  /* Set to true if no active vio, to work well in case of --init-file */
361
357
  if (net.vio != 0)
370
366
}
371
367
 
372
368
 
373
 
void ClientOldLibdrizzle::sendError(uint32_t sql_errno, const char *err)
 
369
void ClientDrizzleProtocol::sendError(uint32_t sql_errno, const char *err)
374
370
{
375
371
  uint32_t length;
376
372
  /*
440
436
    1    Error  (Note that in this case the error is not sent to the
441
437
    client)
442
438
*/
443
 
bool ClientOldLibdrizzle::sendFields(List<Item> *list)
 
439
bool ClientDrizzleProtocol::sendFields(List<Item> *list)
444
440
{
445
441
  List_iterator_fast<Item> it(*list);
446
442
  Item *item;
555
551
  return 1;
556
552
}
557
553
 
558
 
bool ClientOldLibdrizzle::store(Field *from)
 
554
bool ClientDrizzleProtocol::store(Field *from)
559
555
{
560
556
  if (from->is_null())
561
557
    return store();
567
563
  return netStoreData((const unsigned char *)str.ptr(), str.length());
568
564
}
569
565
 
570
 
bool ClientOldLibdrizzle::store(void)
 
566
bool ClientDrizzleProtocol::store(void)
571
567
{
572
568
  char buff[1];
573
569
  buff[0]= (char)251;
574
570
  return packet.append(buff, sizeof(buff), PACKET_BUFFER_EXTRA_ALLOC);
575
571
}
576
572
 
577
 
bool ClientOldLibdrizzle::store(int32_t from)
 
573
bool ClientDrizzleProtocol::store(int32_t from)
578
574
{
579
575
  char buff[12];
580
576
  return netStoreData((unsigned char*) buff,
581
577
                      (size_t) (int10_to_str(from, buff, -10) - buff));
582
578
}
583
579
 
584
 
bool ClientOldLibdrizzle::store(uint32_t from)
 
580
bool ClientDrizzleProtocol::store(uint32_t from)
585
581
{
586
582
  char buff[11];
587
583
  return netStoreData((unsigned char*) buff,
588
584
                      (size_t) (int10_to_str(from, buff, 10) - buff));
589
585
}
590
586
 
591
 
bool ClientOldLibdrizzle::store(int64_t from)
 
587
bool ClientDrizzleProtocol::store(int64_t from)
592
588
{
593
589
  char buff[22];
594
590
  return netStoreData((unsigned char*) buff,
595
591
                      (size_t) (int64_t10_to_str(from, buff, -10) - buff));
596
592
}
597
593
 
598
 
bool ClientOldLibdrizzle::store(uint64_t from)
 
594
bool ClientDrizzleProtocol::store(uint64_t from)
599
595
{
600
596
  char buff[21];
601
597
  return netStoreData((unsigned char*) buff,
602
598
                      (size_t) (int64_t10_to_str(from, buff, 10) - buff));
603
599
}
604
600
 
605
 
bool ClientOldLibdrizzle::store(double from, uint32_t decimals, String *buffer)
 
601
bool ClientDrizzleProtocol::store(double from, uint32_t decimals, String *buffer)
606
602
{
607
603
  buffer->set_real(from, decimals, session->charset());
608
604
  return netStoreData((unsigned char*) buffer->ptr(), buffer->length());
609
605
}
610
606
 
611
 
bool ClientOldLibdrizzle::store(const char *from, size_t length)
 
607
bool ClientDrizzleProtocol::store(const char *from, size_t length)
612
608
{
613
609
  return netStoreData((const unsigned char *)from, length);
614
610
}
615
611
 
616
 
bool ClientOldLibdrizzle::wasAborted(void)
 
612
bool ClientDrizzleProtocol::wasAborted(void)
617
613
{
618
614
  return net.error && net.vio != 0;
619
615
}
620
616
 
621
 
bool ClientOldLibdrizzle::haveMoreData(void)
 
617
bool ClientDrizzleProtocol::haveMoreData(void)
622
618
{
623
619
  return drizzleclient_net_more_data(&net);
624
620
}
625
621
 
626
 
bool ClientOldLibdrizzle::haveError(void)
 
622
bool ClientDrizzleProtocol::haveError(void)
627
623
{
628
624
  return net.error || net.vio == 0;
629
625
}
630
626
 
631
 
bool ClientOldLibdrizzle::checkConnection(void)
 
627
bool ClientDrizzleProtocol::checkConnection(void)
632
628
{
633
629
  uint32_t pkt_len= 0;
634
630
  char *end;
768
764
  return session->checkUser(passwd, passwd_len, l_db);
769
765
}
770
766
 
771
 
bool ClientOldLibdrizzle::netStoreData(const unsigned char *from, size_t length)
 
767
bool ClientDrizzleProtocol::netStoreData(const unsigned char *from, size_t length)
772
768
{
773
769
  size_t packet_length= packet.length();
774
770
  /*
789
785
  write it to the network output buffer.
790
786
*/
791
787
 
792
 
void ClientOldLibdrizzle::writeEOFPacket(uint32_t server_status,
 
788
void ClientDrizzleProtocol::writeEOFPacket(uint32_t server_status,
793
789
                                         uint32_t total_warn_count)
794
790
{
795
791
  unsigned char buff[5];
811
807
  drizzleclient_net_write(&net, buff, 5);
812
808
}
813
809
 
814
 
static ListenOldLibdrizzle *listen_obj= NULL;
815
 
static ListenOldLibdrizzle *listen_obj_mysql= NULL;
 
810
static ListenDrizzleProtocol *listen_obj= NULL;
816
811
 
817
812
static int init(drizzled::plugin::Registry &registry)
818
813
{
819
 
  listen_obj= new ListenOldLibdrizzle("oldlibdrizzle", false);
820
 
  listen_obj_mysql= new ListenOldLibdrizzle("oldlibdrizzle_mysql", true);
 
814
  listen_obj= new ListenDrizzleProtocol("drizzle_protocol", false);
821
815
  registry.add(listen_obj); 
822
 
  registry.add(listen_obj_mysql); 
823
816
  return 0;
824
817
}
825
818
 
826
819
static int deinit(drizzled::plugin::Registry &registry)
827
820
{
828
821
  registry.remove(listen_obj);
829
 
  registry.remove(listen_obj_mysql);
830
822
  delete listen_obj;
831
 
  delete listen_obj_mysql;
832
823
  return 0;
833
824
}
834
825
 
837
828
                              "preference, drizzle.cnf, $DRIZZLE_TCP_PORT, built-in default ("
838
829
                              STRINGIFY_ARG(DRIZZLE_TCP_PORT) ")."),
839
830
                           NULL, NULL, 0, 0, 65535, 0);
840
 
static DRIZZLE_SYSVAR_UINT(mysql_port, mysql_port, PLUGIN_VAR_RQCMDARG,
841
 
                           N_("Port number to use for connection or 0 for default to with MySQL "
842
 
                              "protocol."),
843
 
                           NULL, NULL, 3306, 0, 65535, 0);
844
831
static DRIZZLE_SYSVAR_UINT(connect_timeout, connect_timeout,
845
832
                           PLUGIN_VAR_RQCMDARG, N_("Connect Timeout."),
846
833
                           NULL, NULL, 10, 1, 300, 0);
858
845
 
859
846
static struct st_mysql_sys_var* system_variables[]= {
860
847
  DRIZZLE_SYSVAR(port),
861
 
  DRIZZLE_SYSVAR(mysql_port),
862
848
  DRIZZLE_SYSVAR(connect_timeout),
863
849
  DRIZZLE_SYSVAR(read_timeout),
864
850
  DRIZZLE_SYSVAR(write_timeout),
868
854
  NULL
869
855
};
870
856
 
871
 
drizzle_declare_plugin(oldlibdrizzle)
 
857
drizzle_declare_plugin(drizzle_protocol)
872
858
{
873
 
  "oldlibdrizzle",
 
859
  "drizzle_protocol",
874
860
  "0.1",
875
861
  "Eric Day",
876
 
  "Old libdrizzle Client",
 
862
  "Drizzle Protocol Module",
877
863
  PLUGIN_LICENSE_GPL,
878
864
  init,             /* Plugin Init */
879
865
  deinit,           /* Plugin Deinit */