20
20
#include <drizzled/server_includes.h>
21
#include <drizzled/gettext.h>
21
22
#include <drizzled/error.h>
23
#include <drizzled/query_id.h>
22
24
#include <drizzled/sql_state.h>
23
25
#include <drizzled/session.h>
25
27
#include "errmsg.h"
26
28
#include "oldlibdrizzle.h"
29
#include "libdrizzle.h"
28
31
#include <algorithm>
30
33
using namespace std;
34
using namespace drizzled;
32
36
#define PROTOCOL_VERSION 10
36
40
static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024;
37
41
static uint32_t _port= 0;
42
static uint32_t connect_timeout;
43
static uint32_t read_timeout;
44
static uint32_t write_timeout;
45
static uint32_t retry_count;
39
47
ListenOldLibdrizzle::ListenOldLibdrizzle()
62
70
return net.vio != 0;
65
void ProtocolOldLibdrizzle::setReadTimeout(uint32_t timeout)
67
drizzleclient_net_set_read_timeout(&net, timeout);
70
void ProtocolOldLibdrizzle::setWriteTimeout(uint32_t timeout)
72
drizzleclient_net_set_write_timeout(&net, timeout);
75
void ProtocolOldLibdrizzle::setRetryCount(uint32_t count)
77
net.retry_count=count;
80
73
void ProtocolOldLibdrizzle::setError(char error)
164
152
buff[0]=0; // No fields
165
153
if (session->main_da.status() == Diagnostics_area::DA_OK)
167
pos=drizzleclient_net_store_length(buff+1,session->main_da.affected_rows());
155
if (client_capabilities & CLIENT_FOUND_ROWS && session->main_da.found_rows())
156
pos=drizzleclient_net_store_length(buff+1,session->main_da.found_rows());
158
pos=drizzleclient_net_store_length(buff+1,session->main_da.affected_rows());
168
159
pos=drizzleclient_net_store_length(pos, session->main_da.last_insert_id());
169
160
int2store(pos, session->main_da.server_status());
347
338
1 Error (Note that in this case the error is not sent to the
350
bool ProtocolOldLibdrizzle::sendFields(List<Item> *list, uint32_t flags)
341
bool ProtocolOldLibdrizzle::sendFields(List<Item> *list)
352
343
List_iterator_fast<Item> it(*list);
354
345
unsigned char buff[80];
355
346
String tmp((char*) buff,sizeof(buff),&my_charset_bin);
357
if (flags & SEND_NUM_ROWS)
358
{ // Packet with number of elements
359
unsigned char *pos= drizzleclient_net_store_length(buff, list->elements);
360
(void) drizzleclient_net_write(&net, buff, (size_t) (pos-buff));
348
unsigned char *row_pos= drizzleclient_net_store_length(buff, list->elements);
349
(void) drizzleclient_net_write(&net, buff, (size_t) (row_pos-buff));
363
351
while ((item=it++))
393
381
packet->length((uint32_t) (pos - packet->ptr()));
394
if (flags & SEND_DEFAULTS)
395
item->send(this, &tmp); // Send default value
397
383
break; /* purecov: inspected */
400
if (flags & SEND_EOF)
403
Mark the end of meta-data result set, and store session->server_status,
404
to show that there is no cursor.
405
Send no warning information, as it will be sent at statement end.
407
write_eof_packet(session, &net, session->server_status, session->total_warn_count);
387
Mark the end of meta-data result set, and store session->server_status,
388
to show that there is no cursor.
389
Send no warning information, as it will be sent at statement end.
391
write_eof_packet(session, &net, session->server_status,
392
session->total_warn_count);
410
394
field_count= list->elements;
432
void ProtocolOldLibdrizzle::setRandom(uint64_t seed1, uint64_t seed2)
434
drizzleclient_randominit(&rand, seed1, seed2);
437
415
bool ProtocolOldLibdrizzle::setFileDescriptor(int fd)
439
417
if (drizzleclient_net_init_sock(&net, fd, 0))
420
drizzleclient_net_set_read_timeout(&net, read_timeout);
421
drizzleclient_net_set_write_timeout(&net, write_timeout);
422
net.retry_count=retry_count;
467
450
/* Connect completed, set read/write timeouts back to default */
468
drizzleclient_net_set_read_timeout(&net,
469
session->variables.net_read_timeout);
470
drizzleclient_net_set_write_timeout(&net,
471
session->variables.net_write_timeout);
451
drizzleclient_net_set_read_timeout(&net, read_timeout);
452
drizzleclient_net_set_write_timeout(&net, write_timeout);
717
int4store((unsigned char*) end, thread_id);
701
int4store((unsigned char*) end, global_thread_id);
720
704
So as _checkConnection is the only entry point to authorization
721
705
procedure, scramble is set here. This gives us new scramble for
709
drizzleclient_randominit(&rand, rnd_tmp + (uint64_t) &session,
710
rnd_tmp + (uint64_t)local_query_id.value());
724
711
drizzleclient_create_random_string(scramble, SCRAMBLE_LENGTH, &rand);
726
713
Old clients does not understand long scrambles, but can ignore packet
762
749
if (session->packet.alloc(session->variables.net_buffer_length))
763
750
return false; /* The error is set by alloc(). */
765
session->client_capabilities= uint2korr(net.read_pos);
768
session->client_capabilities|= ((uint32_t) uint2korr(net.read_pos + 2)) << 16;
752
client_capabilities= uint2korr(net.read_pos);
755
client_capabilities|= ((uint32_t) uint2korr(net.read_pos + 2)) << 16;
769
756
session->max_client_packet_length= uint4korr(net.read_pos + 4);
770
757
end= (char*) net.read_pos + 32;
773
760
Disable those bits which are not supported by the server.
774
761
This is a precautionary measure, if the client lies. See Bug#27944.
776
session->client_capabilities&= server_capabilites;
763
client_capabilities&= server_capabilites;
778
765
if (end >= (char*) net.read_pos + pkt_len + 2)
798
785
Cast *passwd to an unsigned char, so that it doesn't extend the sign for
799
786
*passwd > 127 and become 2**32-127+ after casting to uint.
801
uint32_t passwd_len= session->client_capabilities & CLIENT_SECURE_CONNECTION ?
788
uint32_t passwd_len= client_capabilities & CLIENT_SECURE_CONNECTION ?
802
789
(unsigned char)(*passwd++) : strlen(passwd);
803
l_db= session->client_capabilities & CLIENT_CONNECT_WITH_DB ? l_db + passwd_len + 1 : 0;
790
l_db= client_capabilities & CLIENT_CONNECT_WITH_DB ? l_db + passwd_len + 1 : 0;
805
792
/* strlen() can't be easily deleted without changing protocol */
806
793
uint32_t db_len= l_db ? strlen(l_db) : 0;
828
static DRIZZLE_SYSVAR_UINT(connect_timeout, connect_timeout,
829
PLUGIN_VAR_RQCMDARG, N_("Connect Timeout."),
830
NULL, NULL, 10, 1, 300, 0);
831
static DRIZZLE_SYSVAR_UINT(read_timeout, read_timeout, PLUGIN_VAR_RQCMDARG,
832
N_("Read Timeout."), NULL, NULL, 30, 1, 300, 0);
833
static DRIZZLE_SYSVAR_UINT(write_timeout, write_timeout, PLUGIN_VAR_RQCMDARG,
834
N_("Write Timeout."), NULL, NULL, 60, 1, 300, 0);
835
static DRIZZLE_SYSVAR_UINT(retry_count, retry_count, PLUGIN_VAR_RQCMDARG,
836
N_("Retry Count."), NULL, NULL, 10, 1, 100, 0);
838
static struct st_mysql_sys_var* system_variables[]= {
839
DRIZZLE_SYSVAR(connect_timeout),
840
DRIZZLE_SYSVAR(read_timeout),
841
DRIZZLE_SYSVAR(write_timeout),
842
DRIZZLE_SYSVAR(retry_count),
841
846
drizzle_declare_plugin(oldlibdrizzle)
846
851
"Old libdrizzle Protocol",
847
852
PLUGIN_LICENSE_GPL,
848
init, /* Plugin Init */
849
deinit, /* Plugin Deinit */
850
NULL, /* status variables */
851
NULL, /* system variables */
852
NULL /* config options */
853
init, /* Plugin Init */
854
deinit, /* Plugin Deinit */
855
NULL, /* status variables */
856
system_variables, /* system variables */
857
NULL /* config options */
854
859
drizzle_declare_plugin_end;