~drizzle-trunk/drizzle/development

971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; version 2 of the License.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 */
1 by brian
clean slate
19
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
20
#include "config.h"
971.3.60 by Eric Day
Moved connect_timeout, net_*_timeout, and retry_count to plugin.
21
#include <drizzled/gettext.h>
549 by Monty Taylor
Took gettext.h out of header files.
22
#include <drizzled/error.h>
971.3.61 by Eric Day
Removed setRandom from Protocol class.
23
#include <drizzled/query_id.h>
468 by Monty Taylor
Repaced sql_state stuff with template function and c++ algorithm.
24
#include <drizzled/sql_state.h>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
25
#include <drizzled/session.h>
1241.9.64 by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal.
26
#include "drizzled/internal/my_sys.h"
27
#include "drizzled/internal/m_string.h"
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
28
#include <algorithm>
29
971.3.14 by Eric Day
Created Protocol plugin interface and changed libdrizzleclient to be a plugin.
30
#include "pack.h"
31
#include "errmsg.h"
1300.5.1 by Monty Taylor
Put drizzle_protocol plugin in to its own namespace so that symbols won't
32
#include "drizzle_protocol.h"
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
33
#include "options.h"
1067.4.8 by Nathan Williams
Converted all usages of cmin/cmax in plugin directory to std::min/max.
34
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
35
#define PROTOCOL_VERSION 10
36
37
namespace drizzled
38
{
39
extern uint32_t global_thread_id;
40
}
41
1320.2.1 by Monty Taylor
Merged in drizzle_protocol namespace change.
42
using namespace drizzled;
1067.4.8 by Nathan Williams
Converted all usages of cmin/cmax in plugin directory to std::min/max.
43
using namespace std;
1300.5.1 by Monty Taylor
Put drizzle_protocol plugin in to its own namespace so that symbols won't
44
45
namespace drizzle_protocol
46
{
47
1067.4.8 by Nathan Williams
Converted all usages of cmin/cmax in plugin directory to std::min/max.
48
1192.3.40 by Monty Taylor
Removed port setting from configure. The situation is a bit different now than that code was designed for.
49
static const uint32_t DRIZZLE_TCP_PORT= 4427;
1 by brian
clean slate
50
static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024;
971.7.8 by Eric Day
Moved port options into protocol plugin and added MySQL protocol support.
51
static uint32_t port;
971.3.60 by Eric Day
Moved connect_timeout, net_*_timeout, and retry_count to plugin.
52
static uint32_t connect_timeout;
53
static uint32_t read_timeout;
54
static uint32_t write_timeout;
55
static uint32_t retry_count;
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
56
static uint32_t buffer_length;
57
static char* bind_address;
58
971.7.10 by Eric Day
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.
59
const char* ListenDrizzleProtocol::getHost(void) const
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
60
{
61
  return bind_address;
62
}
971.3.48 by Eric Day
New Listen interface about done, not quite compiling yet, but need a backup.
63
971.7.10 by Eric Day
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.
64
in_port_t ListenDrizzleProtocol::getPort(void) const
971.3.48 by Eric Day
New Listen interface about done, not quite compiling yet, but need a backup.
65
{
971.7.8 by Eric Day
Moved port options into protocol plugin and added MySQL protocol support.
66
  char *env;
67
68
  if (port == 0)
69
  {
70
    port= DRIZZLE_TCP_PORT;
71
72
    if ((env = getenv("DRIZZLE_TCP_PORT")))
73
      port= (uint32_t) atoi(env);
74
75
    assert(port != 0);
76
  }
77
78
  return (in_port_t) port;
971.3.48 by Eric Day
New Listen interface about done, not quite compiling yet, but need a backup.
79
}
80
971.7.10 by Eric Day
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.
81
plugin::Client *ListenDrizzleProtocol::getClient(int fd)
971.3.48 by Eric Day
New Listen interface about done, not quite compiling yet, but need a backup.
82
{
971.6.7 by Eric Day
Reworked listen interface to not require binding of TCP ports.
83
  int new_fd;
84
  new_fd= acceptTcp(fd);
85
  if (new_fd == -1)
86
    return NULL;
87
971.7.10 by Eric Day
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.
88
  return new (nothrow) ClientDrizzleProtocol(new_fd, using_mysql41_protocol);
971.3.48 by Eric Day
New Listen interface about done, not quite compiling yet, but need a backup.
89
}
971.3.8 by Eric Day
Moved NET to Protocol. libdrizzleclient is now completely isolated, need to start reworking Protocol now.
90
971.7.10 by Eric Day
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.
91
ClientDrizzleProtocol::ClientDrizzleProtocol(int fd, bool using_mysql41_protocol_arg):
971.7.9 by Eric Day
Renamed mysql protocol variable from Jay's suggestion.
92
  using_mysql41_protocol(using_mysql41_protocol_arg)
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
93
{
94
  net.vio= 0;
95
96
  if (fd == -1)
97
    return;
98
99
  if (drizzleclient_net_init_sock(&net, fd, 0, buffer_length))
100
    throw bad_alloc();
101
102
  drizzleclient_net_set_read_timeout(&net, read_timeout);
103
  drizzleclient_net_set_write_timeout(&net, write_timeout);
104
  net.retry_count=retry_count;
105
}
106
971.7.10 by Eric Day
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.
107
ClientDrizzleProtocol::~ClientDrizzleProtocol()
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
108
{
109
  if (net.vio)
110
    drizzleclient_vio_close(net.vio);
111
}
112
971.7.10 by Eric Day
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.
113
int ClientDrizzleProtocol::getFileDescriptor(void)
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
114
{
115
  return drizzleclient_net_get_sd(&net);
116
}
1 by brian
clean slate
117
971.7.10 by Eric Day
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.
118
bool ClientDrizzleProtocol::isConnected()
971.3.5 by Eric Day
Moved more drizzleclient/NET specific code to Protocol class.
119
{
971.3.8 by Eric Day
Moved NET to Protocol. libdrizzleclient is now completely isolated, need to start reworking Protocol now.
120
  return net.vio != 0;
971.3.5 by Eric Day
Moved more drizzleclient/NET specific code to Protocol class.
121
}
122
971.7.10 by Eric Day
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.
123
bool ClientDrizzleProtocol::isReading(void)
971.3.8 by Eric Day
Moved NET to Protocol. libdrizzleclient is now completely isolated, need to start reworking Protocol now.
124
{
125
  return net.reading_or_writing == 1;
126
}
127
971.7.10 by Eric Day
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.
128
bool ClientDrizzleProtocol::isWriting(void)
971.3.8 by Eric Day
Moved NET to Protocol. libdrizzleclient is now completely isolated, need to start reworking Protocol now.
129
{
130
  return net.reading_or_writing == 2;
971.3.5 by Eric Day
Moved more drizzleclient/NET specific code to Protocol class.
131
}
132
971.7.10 by Eric Day
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.
133
bool ClientDrizzleProtocol::flush()
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
134
{
135
  if (net.vio == NULL)
136
    return false;
137
  bool ret= drizzleclient_net_write(&net, (unsigned char*) packet.ptr(),
138
                           packet.length());
139
  packet.length(0);
140
  return ret;
141
}
142
971.7.10 by Eric Day
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.
143
void ClientDrizzleProtocol::close(void)
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
144
{
145
  if (net.vio)
146
  { 
147
    drizzleclient_net_close(&net);
148
    drizzleclient_net_end(&net);
149
  }
150
}
151
971.7.10 by Eric Day
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.
152
bool ClientDrizzleProtocol::authenticate()
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
153
{
154
  bool connection_is_valid;
155
156
  /* Use "connect_timeout" value during connection phase */
157
  drizzleclient_net_set_read_timeout(&net, connect_timeout);
158
  drizzleclient_net_set_write_timeout(&net, connect_timeout);
159
160
  connection_is_valid= checkConnection();
161
162
  if (connection_is_valid)
163
    sendOK();
164
  else
165
  {
166
    sendError(session->main_da.sql_errno(), session->main_da.message());
167
    return false;
168
  }
169
170
  /* Connect completed, set read/write timeouts back to default */
171
  drizzleclient_net_set_read_timeout(&net, read_timeout);
172
  drizzleclient_net_set_write_timeout(&net, write_timeout);
173
  return true;
174
}
175
971.7.10 by Eric Day
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.
176
bool ClientDrizzleProtocol::readCommand(char **l_packet, uint32_t *packet_length)
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
177
{
178
  /*
179
    This thread will do a blocking read from the client which
180
    will be interrupted when the next command is received from
181
    the client, the connection is closed or "net_wait_timeout"
182
    number of seconds has passed
183
  */
184
#ifdef NEVER
185
  /* We can do this much more efficiently with poll timeouts or watcher thread,
186
     disabling for now, which means net_wait_timeout == read_timeout. */
187
  drizzleclient_net_set_read_timeout(&net,
188
                                     session->variables.net_wait_timeout);
189
#endif
190
191
  net.pkt_nr=0;
192
193
  *packet_length= drizzleclient_net_read(&net);
194
  if (*packet_length == packet_error)
195
  {
196
    /* Check if we can continue without closing the connection */
197
198
    if(net.last_errno== CR_NET_PACKET_TOO_LARGE)
199
      my_error(ER_NET_PACKET_TOO_LARGE, MYF(0));
200
    if (session->main_da.status() == Diagnostics_area::DA_ERROR)
201
      sendError(session->main_da.sql_errno(), session->main_da.message());
202
    else
203
      sendOK();
204
205
    if (net.error != 3)
206
      return false;                       // We have to close it.
207
208
    net.error= 0;
209
    *packet_length= 0;
210
    return true;
211
  }
212
213
  *l_packet= (char*) net.read_pos;
214
215
  /*
216
    'packet_length' contains length of data, as it was stored in packet
217
    header. In case of malformed header, drizzleclient_net_read returns zero.
218
    If packet_length is not zero, drizzleclient_net_read ensures that the returned
219
    number of bytes was actually read from network.
220
    There is also an extra safety measure in drizzleclient_net_read:
221
    it sets packet[packet_length]= 0, but only for non-zero packets.
222
  */
223
224
  if (*packet_length == 0)                       /* safety */
225
  {
226
    /* Initialize with COM_SLEEP packet */
227
    (*l_packet)[0]= (unsigned char) COM_SLEEP;
228
    *packet_length= 1;
229
  }
971.7.9 by Eric Day
Renamed mysql protocol variable from Jay's suggestion.
230
  else if (using_mysql41_protocol)
971.7.8 by Eric Day
Moved port options into protocol plugin and added MySQL protocol support.
231
  {
232
    /* Map from MySQL commands to Drizzle commands. */
233
    switch ((int)(*l_packet)[0])
234
    {
235
    case 0: /* SLEEP */
236
    case 1: /* QUIT */
237
    case 2: /* INIT_DB */
238
    case 3: /* QUERY */
239
      break;
240
241
    case 8: /* SHUTDOWN */
242
      (*l_packet)[0]= (unsigned char) COM_SHUTDOWN;
243
      break;
244
245
    case 14: /* PING */
246
      (*l_packet)[0]= (unsigned char) COM_SHUTDOWN;
247
      break;
248
249
250
    default:
251
      /* Just drop connection for MySQL commands we don't support. */
252
      (*l_packet)[0]= (unsigned char) COM_QUIT;
253
      *packet_length= 1;
254
      break;
255
    }
256
  }
257
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
258
  /* Do not rely on drizzleclient_net_read, extra safety against programming errors. */
259
  (*l_packet)[*packet_length]= '\0';                  /* safety */
260
261
#ifdef NEVER
262
  /* See comment above. */
263
  /* Restore read timeout value */
264
  drizzleclient_net_set_read_timeout(&net,
265
                                     session->variables.net_read_timeout);
266
#endif
267
268
  return true;
269
}
1 by brian
clean slate
270
271
/**
272
  Return ok to the client.
273
274
  The ok packet has the following structure:
275
276
  - 0               : Marker (1 byte)
971.3.17 by Eric Day
Cleaned up int/date related store functions.
277
  - affected_rows    : Stored in 1-9 bytes
278
  - id        : Stored in 1-9 bytes
279
  - server_status    : Copy of session->server_status;  Can be used by client
1 by brian
clean slate
280
  to check if we are inside an transaction.
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
281
  New in 4.0 client
282
  - warning_count    : Stored in 2 bytes; New in 4.1 client
971.3.17 by Eric Day
Cleaned up int/date related store functions.
283
  - message        : Stored as packed length (1-9 bytes) + message.
1 by brian
clean slate
284
  Is not stored if no message.
285
971.3.17 by Eric Day
Cleaned up int/date related store functions.
286
  @param session           Thread handler
287
  @param affected_rows       Number of rows changed by statement
288
  @param id           Auto_increment id for first row (if used)
289
  @param message       Message to send to the client (Used by mysql_status)
1 by brian
clean slate
290
*/
291
971.7.10 by Eric Day
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.
292
void ClientDrizzleProtocol::sendOK()
971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
293
{
294
  unsigned char buff[DRIZZLE_ERRMSG_SIZE+10],*pos;
295
  const char *message= NULL;
296
  uint32_t tmp;
297
971.3.17 by Eric Day
Cleaned up int/date related store functions.
298
  if (!net.vio)    // hack for re-parsing queries
971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
299
  {
300
    return;
301
  }
302
971.3.17 by Eric Day
Cleaned up int/date related store functions.
303
  buff[0]=0;                    // No fields
971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
304
  if (session->main_da.status() == Diagnostics_area::DA_OK)
305
  {
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
306
    if (client_capabilities & CLIENT_FOUND_ROWS && session->main_da.found_rows())
307
      pos=drizzleclient_net_store_length(buff+1,session->main_da.found_rows());
308
    else
309
      pos=drizzleclient_net_store_length(buff+1,session->main_da.affected_rows());
971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
310
    pos=drizzleclient_net_store_length(pos, session->main_da.last_insert_id());
311
    int2store(pos, session->main_da.server_status());
312
    pos+=2;
1067.4.8 by Nathan Williams
Converted all usages of cmin/cmax in plugin directory to std::min/max.
313
    tmp= min(session->main_da.total_warn_count(), (uint32_t)65535);
971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
314
    message= session->main_da.message();
315
  }
316
  else
317
  {
318
    pos=drizzleclient_net_store_length(buff+1,0);
319
    pos=drizzleclient_net_store_length(pos, 0);
320
    int2store(pos, session->server_status);
321
    pos+=2;
1067.4.8 by Nathan Williams
Converted all usages of cmin/cmax in plugin directory to std::min/max.
322
    tmp= min(session->total_warn_count, (uint32_t)65535);
971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
323
  }
324
325
  /* We can only return up to 65535 warnings in two bytes */
326
  int2store(pos, tmp);
327
  pos+= 2;
328
329
  session->main_da.can_overwrite_status= true;
330
331
  if (message && message[0])
332
  {
333
    size_t length= strlen(message);
334
    pos=drizzleclient_net_store_length(pos,length);
335
    memcpy(pos,(unsigned char*) message,length);
336
    pos+=length;
337
  }
338
  drizzleclient_net_write(&net, buff, (size_t) (pos-buff));
339
  drizzleclient_net_flush(&net);
340
341
  session->main_da.can_overwrite_status= false;
342
}
1 by brian
clean slate
343
344
/**
345
  Send eof (= end of result set) to the client.
346
347
  The eof packet has the following structure:
348
971.3.17 by Eric Day
Cleaned up int/date related store functions.
349
  - 254    (DRIZZLE_PROTOCOL_NO_MORE_DATA)    : Marker (1 byte)
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
350
  - warning_count    : Stored in 2 bytes; New in 4.1 client
971.3.17 by Eric Day
Cleaned up int/date related store functions.
351
  - status_flag    : Stored in 2 bytes;
1 by brian
clean slate
352
  For flags like SERVER_MORE_RESULTS_EXISTS.
353
354
  Note that the warning count will not be sent if 'no_flush' is set as
355
  we don't want to report the warning count until all data is sent to the
356
  client.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
357
*/
1 by brian
clean slate
358
971.7.10 by Eric Day
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.
359
void ClientDrizzleProtocol::sendEOF()
971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
360
{
361
  /* Set to true if no active vio, to work well in case of --init-file */
362
  if (net.vio != 0)
363
  {
364
    session->main_da.can_overwrite_status= true;
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
365
    writeEOFPacket(session->main_da.server_status(),
366
                   session->main_da.total_warn_count());
971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
367
    drizzleclient_net_flush(&net);
368
    session->main_da.can_overwrite_status= false;
369
  }
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
370
  packet.shrink(buffer_length);
371
}
372
1 by brian
clean slate
373
971.7.10 by Eric Day
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.
374
void ClientDrizzleProtocol::sendError(uint32_t sql_errno, const char *err)
1 by brian
clean slate
375
{
482 by Brian Aker
Remove uint.
376
  uint32_t length;
1 by brian
clean slate
377
  /*
261.4.1 by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR.
378
    buff[]: sql_errno:2 + ('#':1 + SQLSTATE_LENGTH:5) + DRIZZLE_ERRMSG_SIZE:512
1 by brian
clean slate
379
  */
481 by Brian Aker
Remove all of uchar.
380
  unsigned char buff[2+1+SQLSTATE_LENGTH+DRIZZLE_ERRMSG_SIZE], *pos;
1 by brian
clean slate
381
971.3.17 by Eric Day
Cleaned up int/date related store functions.
382
  assert(sql_errno);
383
  assert(err && err[0]);
384
385
  /*
386
    It's one case when we can push an error even though there
387
    is an OK or EOF already.
388
  */
389
  session->main_da.can_overwrite_status= true;
390
391
  /* Abort multi-result sets */
392
  session->server_status&= ~SERVER_MORE_RESULTS_EXISTS;
393
394
  /**
395
    Send a error string to client.
396
397
    For SIGNAL/RESIGNAL and GET DIAGNOSTICS functionality it's
398
    critical that every error that can be intercepted is issued in one
399
    place only, my_message_sql.
400
  */
401
971.3.8 by Eric Day
Moved NET to Protocol. libdrizzleclient is now completely isolated, need to start reworking Protocol now.
402
  if (net.vio == 0)
1 by brian
clean slate
403
  {
51.1.76 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
404
    return;
1 by brian
clean slate
405
  }
406
407
  int2store(buff,sql_errno);
408
  pos= buff+2;
264.2.4 by Andrey Hristov
Remove support for the old, pre-4.1, protocol
409
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
410
  /* The first # is to make the client backward compatible */
264.2.4 by Andrey Hristov
Remove support for the old, pre-4.1, protocol
411
  buff[2]= '#';
971.3.4 by Eric Day
Further drizzleclient cleanup. Starting to move all NET related functions into Protocol, removed some dead code, removing drizzleclient dependencies spread throughout drizzled.
412
  pos= (unsigned char*) strcpy((char*) buff+3, drizzle_errno_to_sqlstate(sql_errno));
413
  pos+= strlen(drizzle_errno_to_sqlstate(sql_errno));
264.2.4 by Andrey Hristov
Remove support for the old, pre-4.1, protocol
414
629.5.3 by Toru Maesaka
Third pass of replacing MySQL's strmake() with libc calls
415
  char *tmp= strncpy((char*)pos, err, DRIZZLE_ERRMSG_SIZE-1);
416
  tmp+= strlen((char*)pos);
417
  tmp[0]= '\0';
418
  length= (uint32_t)(tmp-(char*)buff);
1 by brian
clean slate
419
  err= (char*) buff;
420
971.3.8 by Eric Day
Moved NET to Protocol. libdrizzleclient is now completely isolated, need to start reworking Protocol now.
421
  drizzleclient_net_write_command(&net,(unsigned char) 255, (unsigned char*) "", 0, (unsigned char*) err, length);
422
423
  session->main_da.can_overwrite_status= false;
1 by brian
clean slate
424
}
425
426
/**
427
  Send name and type of result to client.
428
429
  Sum fields has table name empty and field_name.
430
971.3.17 by Eric Day
Cleaned up int/date related store functions.
431
  @param Session        Thread data object
432
  @param list            List of items to send to client
433
  @param flag            Bit mask with the following functions:
1 by brian
clean slate
434
                        - 1 send number of rows
435
                        - 2 send default values
436
                        - 4 don't write eof packet
437
438
  @retval
971.3.17 by Eric Day
Cleaned up int/date related store functions.
439
    0    ok
1 by brian
clean slate
440
  @retval
971.3.17 by Eric Day
Cleaned up int/date related store functions.
441
    1    Error  (Note that in this case the error is not sent to the
1 by brian
clean slate
442
    client)
443
*/
971.7.10 by Eric Day
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.
444
bool ClientDrizzleProtocol::sendFields(List<Item> *list)
1 by brian
clean slate
445
{
446
  List_iterator_fast<Item> it(*list);
447
  Item *item;
481 by Brian Aker
Remove all of uchar.
448
  unsigned char buff[80];
1 by brian
clean slate
449
  String tmp((char*) buff,sizeof(buff),&my_charset_bin);
450
971.3.63 by Eric Day
Removed protocol field flags.
451
  unsigned char *row_pos= drizzleclient_net_store_length(buff, list->elements);
452
  (void) drizzleclient_net_write(&net, buff, (size_t) (row_pos-buff));
1 by brian
clean slate
453
454
  while ((item=it++))
455
  {
456
    char *pos;
1052.2.4 by Nathan Williams
No actual code changes. Changed Send_field to SendField to be consistent with coding standards.
457
    SendField field;
1 by brian
clean slate
458
    item->make_field(&field);
459
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
460
    packet.length(0);
971.6.2 by Eric Day
Fixed bug, accidently removed prepareForResend call.
461
1054.2.9 by Monty Taylor
Removed CHARSET_INFO stuff from protocol plugin interface - it makes no sense.
462
    if (store(STRING_WITH_LEN("def")) ||
463
        store(field.db_name) ||
464
        store(field.table_name) ||
465
        store(field.org_table_name) ||
466
        store(field.col_name) ||
467
        store(field.org_col_name) ||
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
468
        packet.realloc(packet.length()+12))
264.2.4 by Andrey Hristov
Remove support for the old, pre-4.1, protocol
469
      goto err;
470
471
    /* Store fixed length fields */
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
472
    pos= (char*) packet.ptr()+packet.length();
971.3.17 by Eric Day
Cleaned up int/date related store functions.
473
    *pos++= 12;                // Length of packed fields
1054.2.9 by Monty Taylor
Removed CHARSET_INFO stuff from protocol plugin interface - it makes no sense.
474
    /* No conversion */
475
    int2store(pos, field.charsetnr);
476
    int4store(pos+2, field.length);
971.7.8 by Eric Day
Moved port options into protocol plugin and added MySQL protocol support.
477
971.7.9 by Eric Day
Renamed mysql protocol variable from Jay's suggestion.
478
    if (using_mysql41_protocol)
971.7.8 by Eric Day
Moved port options into protocol plugin and added MySQL protocol support.
479
    {
480
      /* Switch to MySQL field numbering. */
481
      switch (field.type)
482
      {
483
      case DRIZZLE_TYPE_LONG:
484
        pos[6]= 3;
485
        break;
486
487
      case DRIZZLE_TYPE_DOUBLE:
488
        pos[6]= 5;
489
        break;
490
491
      case DRIZZLE_TYPE_NULL:
492
        pos[6]= 6;
493
        break;
494
495
      case DRIZZLE_TYPE_TIMESTAMP:
496
        pos[6]= 7;
497
        break;
498
499
      case DRIZZLE_TYPE_LONGLONG:
500
        pos[6]= 8;
501
        break;
502
503
      case DRIZZLE_TYPE_DATETIME:
504
        pos[6]= 12;
505
        break;
506
507
      case DRIZZLE_TYPE_DATE:
508
        pos[6]= 14;
509
        break;
510
511
      case DRIZZLE_TYPE_VARCHAR:
512
        pos[6]= 15;
513
        break;
514
1218 by Brian Aker
Merge Eric
515
      case DRIZZLE_TYPE_DECIMAL:
971.7.8 by Eric Day
Moved port options into protocol plugin and added MySQL protocol support.
516
        pos[6]= (char)246;
517
        break;
518
519
      case DRIZZLE_TYPE_ENUM:
520
        pos[6]= (char)247;
521
        break;
522
523
      case DRIZZLE_TYPE_BLOB:
524
        pos[6]= (char)252;
525
        break;
526
      }
527
    }
528
    else
529
    {
530
      /* Add one to compensate for tinyint removal from enum. */
531
      pos[6]= field.type + 1;
532
    }
533
264.2.4 by Andrey Hristov
Remove support for the old, pre-4.1, protocol
534
    int2store(pos+7,field.flags);
535
    pos[9]= (char) field.decimals;
971.3.17 by Eric Day
Cleaned up int/date related store functions.
536
    pos[10]= 0;                // For the future
537
    pos[11]= 0;                // For the future
264.2.4 by Andrey Hristov
Remove support for the old, pre-4.1, protocol
538
    pos+= 12;
1 by brian
clean slate
539
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
540
    packet.length((uint32_t) (pos - packet.ptr()));
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
541
    if (flush())
971.6.11 by Eric Day
Removed purecov messages.
542
      break;
1 by brian
clean slate
543
  }
544
971.3.63 by Eric Day
Removed protocol field flags.
545
  /*
546
    Mark the end of meta-data result set, and store session->server_status,
547
    to show that there is no cursor.
548
    Send no warning information, as it will be sent at statement end.
549
  */
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
550
  writeEOFPacket(session->server_status, session->total_warn_count);
971.3.19 by Eric Day
Finished first pass at Protocol cleanup, still some things to remove but they are a bit more involved.
551
  return 0;
1 by brian
clean slate
552
553
err:
554
  my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES),
971.6.11 by Eric Day
Removed purecov messages.
555
             MYF(0));
556
  return 1;
1 by brian
clean slate
557
}
558
971.7.10 by Eric Day
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.
559
bool ClientDrizzleProtocol::store(Field *from)
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
560
{
561
  if (from->is_null())
562
    return store();
563
  char buff[MAX_FIELD_WIDTH];
564
  String str(buff,sizeof(buff), &my_charset_bin);
565
566
  from->val_str(&str);
567
568
  return netStoreData((const unsigned char *)str.ptr(), str.length());
1 by brian
clean slate
569
}
570
971.7.10 by Eric Day
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.
571
bool ClientDrizzleProtocol::store(void)
1 by brian
clean slate
572
{
573
  char buff[1];
574
  buff[0]= (char)251;
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
575
  return packet.append(buff, sizeof(buff), PACKET_BUFFER_EXTRA_ALLOC);
576
}
1 by brian
clean slate
577
971.7.10 by Eric Day
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.
578
bool ClientDrizzleProtocol::store(int32_t from)
971.3.17 by Eric Day
Cleaned up int/date related store functions.
579
{
580
  char buff[12];
581
  return netStoreData((unsigned char*) buff,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
582
                      (size_t) (internal::int10_to_str(from, buff, -10) - buff));
971.3.17 by Eric Day
Cleaned up int/date related store functions.
583
}
584
971.7.10 by Eric Day
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.
585
bool ClientDrizzleProtocol::store(uint32_t from)
971.3.17 by Eric Day
Cleaned up int/date related store functions.
586
{
587
  char buff[11];
588
  return netStoreData((unsigned char*) buff,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
589
                      (size_t) (internal::int10_to_str(from, buff, 10) - buff));
971.3.17 by Eric Day
Cleaned up int/date related store functions.
590
}
591
971.7.10 by Eric Day
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.
592
bool ClientDrizzleProtocol::store(int64_t from)
1 by brian
clean slate
593
{
594
  char buff[22];
971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
595
  return netStoreData((unsigned char*) buff,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
596
                      (size_t) (internal::int64_t10_to_str(from, buff, -10) - buff));
971.3.17 by Eric Day
Cleaned up int/date related store functions.
597
}
598
971.7.10 by Eric Day
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.
599
bool ClientDrizzleProtocol::store(uint64_t from)
971.3.17 by Eric Day
Cleaned up int/date related store functions.
600
{
601
  char buff[21];
602
  return netStoreData((unsigned char*) buff,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
603
                      (size_t) (internal::int64_t10_to_str(from, buff, 10) - buff));
1 by brian
clean slate
604
}
605
971.7.10 by Eric Day
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.
606
bool ClientDrizzleProtocol::store(double from, uint32_t decimals, String *buffer)
1 by brian
clean slate
607
{
520.1.22 by Brian Aker
Second pass of thd cleanup
608
  buffer->set_real(from, decimals, session->charset());
971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
609
  return netStoreData((unsigned char*) buffer->ptr(), buffer->length());
1 by brian
clean slate
610
}
611
971.7.10 by Eric Day
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.
612
bool ClientDrizzleProtocol::store(const char *from, size_t length)
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
613
{
614
  return netStoreData((const unsigned char *)from, length);
615
}
616
971.7.10 by Eric Day
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.
617
bool ClientDrizzleProtocol::wasAborted(void)
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
618
{
619
  return net.error && net.vio != 0;
620
}
621
971.7.10 by Eric Day
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.
622
bool ClientDrizzleProtocol::haveMoreData(void)
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
623
{
624
  return drizzleclient_net_more_data(&net);
625
}
626
971.7.10 by Eric Day
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.
627
bool ClientDrizzleProtocol::haveError(void)
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
628
{
629
  return net.error || net.vio == 0;
1 by brian
clean slate
630
}
631
971.7.10 by Eric Day
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.
632
bool ClientDrizzleProtocol::checkConnection(void)
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
633
{
634
  uint32_t pkt_len= 0;
635
  char *end;
636
637
  // TCP/IP connection
638
  {
639
    char ip[NI_MAXHOST];
971.7.8 by Eric Day
Moved port options into protocol plugin and added MySQL protocol support.
640
    uint16_t peer_port;
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
641
971.7.8 by Eric Day
Moved port options into protocol plugin and added MySQL protocol support.
642
    if (drizzleclient_net_peer_addr(&net, ip, &peer_port, NI_MAXHOST))
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
643
    {
1273.11.5 by Dennis Schoen
add getSecurityContext()
644
      my_error(ER_BAD_HOST_ERROR, MYF(0), session->getSecurityContext().getIp().c_str());
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
645
      return false;
646
    }
647
1273.11.5 by Dennis Schoen
add getSecurityContext()
648
    session->getSecurityContext().setIp(ip);
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
649
  }
971.3.8 by Eric Day
Moved NET to Protocol. libdrizzleclient is now completely isolated, need to start reworking Protocol now.
650
  drizzleclient_net_keepalive(&net, true);
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
651
652
  uint32_t server_capabilites;
653
  {
654
    /* buff[] needs to big enough to hold the server_version variable */
655
    char buff[SERVER_VERSION_LENGTH + SCRAMBLE_LENGTH + 64];
656
657
    server_capabilites= CLIENT_BASIC_FLAGS;
658
971.7.9 by Eric Day
Renamed mysql protocol variable from Jay's suggestion.
659
    if (using_mysql41_protocol)
971.7.8 by Eric Day
Moved port options into protocol plugin and added MySQL protocol support.
660
      server_capabilites|= CLIENT_PROTOCOL_MYSQL41;
661
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
662
#ifdef HAVE_COMPRESS
663
    server_capabilites|= CLIENT_COMPRESS;
664
#endif /* HAVE_COMPRESS */
665
1502.4.1 by Monty Taylor
Don't overwrite the pandora_vc_revinfo file if we don't have new
666
    end= buff + strlen(PANDORA_RELEASE_VERSION);
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
667
    if ((end - buff) >= SERVER_VERSION_LENGTH)
668
      end= buff + (SERVER_VERSION_LENGTH - 1);
1502.4.1 by Monty Taylor
Don't overwrite the pandora_vc_revinfo file if we don't have new
669
    memcpy(buff, PANDORA_RELEASE_VERSION, end - buff);
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
670
    *end= 0;
671
    end++;
672
971.3.66 by Eric Day
Fixed thread_id bug from session refactoring work.
673
    int4store((unsigned char*) end, global_thread_id);
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
674
    end+= 4;
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
675
676
    /* We don't use scramble anymore. */
677
    memset(end, 'X', SCRAMBLE_LENGTH_323);
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
678
    end+= SCRAMBLE_LENGTH_323;
679
    *end++= 0; /* an empty byte for some reason */
680
681
    int2store(end, server_capabilites);
682
    /* write server characteristics: up to 16 bytes allowed */
683
    end[2]=(char) default_charset_info->number;
684
    int2store(end+3, session->server_status);
685
    memset(end+5, 0, 13);
686
    end+= 18;
687
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
688
    /* Write scramble tail. */
689
    memset(end, 'X', SCRAMBLE_LENGTH - SCRAMBLE_LENGTH_323);
690
    end+= (SCRAMBLE_LENGTH - SCRAMBLE_LENGTH_323);
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
691
    *end++= 0; /* an empty byte for some reason */
692
693
    /* At this point we write connection message and read reply */
971.3.8 by Eric Day
Moved NET to Protocol. libdrizzleclient is now completely isolated, need to start reworking Protocol now.
694
    if (drizzleclient_net_write_command(&net
971.3.48 by Eric Day
New Listen interface about done, not quite compiling yet, but need a backup.
695
          , (unsigned char) PROTOCOL_VERSION
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
696
          , (unsigned char*) ""
697
          , 0
698
          , (unsigned char*) buff
699
          , (size_t) (end-buff)) 
971.3.17 by Eric Day
Cleaned up int/date related store functions.
700
        ||    (pkt_len= drizzleclient_net_read(&net)) == packet_error 
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
701
        || pkt_len < MIN_HANDSHAKE_SIZE)
702
    {
1273.11.5 by Dennis Schoen
add getSecurityContext()
703
      my_error(ER_HANDSHAKE_ERROR, MYF(0), session->getSecurityContext().getIp().c_str());
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
704
      return false;
705
    }
706
  }
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
707
  if (packet.alloc(buffer_length))
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
708
    return false; /* The error is set by alloc(). */
709
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
710
  client_capabilities= uint2korr(net.read_pos);
711
712
713
  client_capabilities|= ((uint32_t) uint2korr(net.read_pos + 2)) << 16;
971.3.8 by Eric Day
Moved NET to Protocol. libdrizzleclient is now completely isolated, need to start reworking Protocol now.
714
  session->max_client_packet_length= uint4korr(net.read_pos + 4);
715
  end= (char*) net.read_pos + 32;
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
716
717
  /*
718
    Disable those bits which are not supported by the server.
719
    This is a precautionary measure, if the client lies. See Bug#27944.
720
  */
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
721
  client_capabilities&= server_capabilites;
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
722
971.3.8 by Eric Day
Moved NET to Protocol. libdrizzleclient is now completely isolated, need to start reworking Protocol now.
723
  if (end >= (char*) net.read_pos + pkt_len + 2)
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
724
  {
1273.11.5 by Dennis Schoen
add getSecurityContext()
725
    my_error(ER_HANDSHAKE_ERROR, MYF(0), session->getSecurityContext().getIp().c_str());
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
726
    return false;
727
  }
728
971.3.8 by Eric Day
Moved NET to Protocol. libdrizzleclient is now completely isolated, need to start reworking Protocol now.
729
  net.return_status= &session->server_status;
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
730
731
  char *user= end;
732
  char *passwd= strchr(user, '\0')+1;
733
  uint32_t user_len= passwd - user - 1;
734
  char *l_db= passwd;
735
736
  /*
737
    Old clients send null-terminated string as password; new clients send
738
    the size (1 byte) + string (not null-terminated). Hence in case of empty
739
    password both send '\0'.
740
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
741
    This strlen() can't be easily deleted without changing client.
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
742
743
    Cast *passwd to an unsigned char, so that it doesn't extend the sign for
744
    *passwd > 127 and become 2**32-127+ after casting to uint.
745
  */
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
746
  uint32_t passwd_len= client_capabilities & CLIENT_SECURE_CONNECTION ?
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
747
    (unsigned char)(*passwd++) : strlen(passwd);
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
748
  l_db= client_capabilities & CLIENT_CONNECT_WITH_DB ? l_db + passwd_len + 1 : 0;
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
749
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
750
  /* strlen() can't be easily deleted without changing client */
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
751
  uint32_t db_len= l_db ? strlen(l_db) : 0;
752
971.3.8 by Eric Day
Moved NET to Protocol. libdrizzleclient is now completely isolated, need to start reworking Protocol now.
753
  if (passwd + passwd_len + db_len > (char *) net.read_pos + pkt_len)
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
754
  {
1273.11.5 by Dennis Schoen
add getSecurityContext()
755
    my_error(ER_HANDSHAKE_ERROR, MYF(0), session->getSecurityContext().getIp().c_str());
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
756
    return false;
757
  }
758
759
  /* If username starts and ends in "'", chop them off */
760
  if (user_len > 1 && user[0] == '\'' && user[user_len - 1] == '\'')
761
  {
762
    user[user_len-1]= 0;
763
    user++;
764
    user_len-= 2;
765
  }
766
1273.11.5 by Dennis Schoen
add getSecurityContext()
767
  session->getSecurityContext().setUser(user);
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
768
769
  return session->checkUser(passwd, passwd_len, l_db);
770
}
971.3.14 by Eric Day
Created Protocol plugin interface and changed libdrizzleclient to be a plugin.
771
971.7.10 by Eric Day
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.
772
bool ClientDrizzleProtocol::netStoreData(const unsigned char *from, size_t length)
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
773
{
774
  size_t packet_length= packet.length();
775
  /*
776
     The +9 comes from that strings of length longer than 16M require
777
     9 bytes to be stored (see drizzleclient_net_store_length).
778
  */
779
  if (packet_length+9+length > packet.alloced_length() &&
780
      packet.realloc(packet_length+9+length))
781
    return 1;
782
  unsigned char *to= drizzleclient_net_store_length((unsigned char*) packet.ptr()+packet_length, length);
783
  memcpy(to,from,length);
784
  packet.length((size_t) (to+length-(unsigned char*) packet.ptr()));
785
  return 0;
786
}
787
788
/**
789
  Format EOF packet according to the current client and
790
  write it to the network output buffer.
791
*/
792
971.7.10 by Eric Day
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.
793
void ClientDrizzleProtocol::writeEOFPacket(uint32_t server_status,
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
794
                                         uint32_t total_warn_count)
795
{
796
  unsigned char buff[5];
797
  /*
798
    Don't send warn count during SP execution, as the warn_list
799
    is cleared between substatements, and mysqltest gets confused
800
  */
801
  uint32_t tmp= min(total_warn_count, (uint32_t)65535);
802
  buff[0]= DRIZZLE_PROTOCOL_NO_MORE_DATA;
803
  int2store(buff+1, tmp);
804
  /*
805
    The following test should never be true, but it's better to do it
806
    because if 'is_fatal_error' is set the server is not going to execute
807
    other queries (see the if test in dispatch_command / COM_QUERY)
808
  */
809
  if (session->is_fatal_error)
810
    server_status&= ~SERVER_MORE_RESULTS_EXISTS;
811
  int2store(buff + 3, server_status);
812
  drizzleclient_net_write(&net, buff, 5);
813
}
814
971.7.10 by Eric Day
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.
815
static ListenDrizzleProtocol *listen_obj= NULL;
971.1.51 by Monty Taylor
New-style plugin registration now works.
816
1530.2.6 by Monty Taylor
Moved plugin::Context to module::Context.
817
static int init(module::Context &context)
971.3.14 by Eric Day
Created Protocol plugin interface and changed libdrizzleclient to be a plugin.
818
{
971.7.10 by Eric Day
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.
819
  listen_obj= new ListenDrizzleProtocol("drizzle_protocol", false);
1324.2.2 by Monty Taylor
Use the plugin::Context everywhere.
820
  context.add(listen_obj); 
971.3.16 by Eric Day
Cleaned up Protocol plugin interface (now a class factory) and moved libdrizzlclient to oldlibdrizzle to be clear.
821
  return 0;
822
}
823
971.7.8 by Eric Day
Moved port options into protocol plugin and added MySQL protocol support.
824
static DRIZZLE_SYSVAR_UINT(port, port, PLUGIN_VAR_RQCMDARG,
1192.3.40 by Monty Taylor
Removed port setting from configure. The situation is a bit different now than that code was designed for.
825
                           N_("Port number to use for connection or 0 for "
826
                              "default to, in order of "
827
                              "preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
828
                              "built-in default (4427)."),
971.7.8 by Eric Day
Moved port options into protocol plugin and added MySQL protocol support.
829
                           NULL, NULL, 0, 0, 65535, 0);
971.3.60 by Eric Day
Moved connect_timeout, net_*_timeout, and retry_count to plugin.
830
static DRIZZLE_SYSVAR_UINT(connect_timeout, connect_timeout,
831
                           PLUGIN_VAR_RQCMDARG, N_("Connect Timeout."),
832
                           NULL, NULL, 10, 1, 300, 0);
833
static DRIZZLE_SYSVAR_UINT(read_timeout, read_timeout, PLUGIN_VAR_RQCMDARG,
834
                           N_("Read Timeout."), NULL, NULL, 30, 1, 300, 0);
835
static DRIZZLE_SYSVAR_UINT(write_timeout, write_timeout, PLUGIN_VAR_RQCMDARG,
836
                           N_("Write Timeout."), NULL, NULL, 60, 1, 300, 0);
837
static DRIZZLE_SYSVAR_UINT(retry_count, retry_count, PLUGIN_VAR_RQCMDARG,
838
                           N_("Retry Count."), NULL, NULL, 10, 1, 100, 0);
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
839
static DRIZZLE_SYSVAR_UINT(buffer_length, buffer_length, PLUGIN_VAR_RQCMDARG,
840
                           N_("Buffer length."), NULL, NULL, 16384, 1024,
841
                           1024*1024, 0);
842
static DRIZZLE_SYSVAR_STR(bind_address, bind_address, PLUGIN_VAR_READONLY,
843
                          N_("Address to bind to."), NULL, NULL, NULL);
971.3.60 by Eric Day
Moved connect_timeout, net_*_timeout, and retry_count to plugin.
844
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
845
static drizzle_sys_var* sys_variables[]= {
971.7.8 by Eric Day
Moved port options into protocol plugin and added MySQL protocol support.
846
  DRIZZLE_SYSVAR(port),
971.3.60 by Eric Day
Moved connect_timeout, net_*_timeout, and retry_count to plugin.
847
  DRIZZLE_SYSVAR(connect_timeout),
848
  DRIZZLE_SYSVAR(read_timeout),
849
  DRIZZLE_SYSVAR(write_timeout),
850
  DRIZZLE_SYSVAR(retry_count),
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
851
  DRIZZLE_SYSVAR(buffer_length),
852
  DRIZZLE_SYSVAR(bind_address),
971.3.60 by Eric Day
Moved connect_timeout, net_*_timeout, and retry_count to plugin.
853
  NULL
854
};
855
1320.2.1 by Monty Taylor
Merged in drizzle_protocol namespace change.
856
} /* namespace drizzle_protocol */
1300.5.1 by Monty Taylor
Put drizzle_protocol plugin in to its own namespace so that symbols won't
857
1324.2.5 by Monty Taylor
Merged trunk.
858
DRIZZLE_PLUGIN(drizzle_protocol::init, drizzle_protocol::sys_variables);