Merge lp:~brianaker/drizzle/bug-fix-654219 into lp:~drizzle-trunk/drizzle/development

Proposed by Brian Aker
Status: Merged
Approved by: Brian Aker
Approved revision: not available
Merged at revision: 1822
Proposed branch: lp:~brianaker/drizzle/bug-fix-654219
Merge into: lp:~drizzle-trunk/drizzle/development
Diff against target: 3037 lines (+292/-2456) (has conflicts)
17 files modified
plugin/drizzle_protocol/drizzle_protocol.cc (+34/-883)
plugin/drizzle_protocol/drizzle_protocol.h (+15/-66)
plugin/drizzle_protocol/errmsg.cc (+1/-93)
plugin/drizzle_protocol/errmsg.h (+0/-80)
plugin/drizzle_protocol/net_serv.cc (+0/-896)
plugin/drizzle_protocol/net_serv.h (+0/-94)
plugin/drizzle_protocol/options.h (+0/-125)
plugin/drizzle_protocol/pack.cc (+0/-132)
plugin/drizzle_protocol/pack.h (+0/-34)
plugin/drizzle_protocol/plugin.ini (+10/-5)
plugin/drizzle_protocol/status_table.h (+13/-8)
plugin/information_schema_dictionary/key_column_usage.cc (+51/-2)
plugin/information_schema_dictionary/key_column_usage.h (+3/-0)
plugin/information_schema_dictionary/tests/r/key_column_usage.result (+36/-36)
tests/include.am (+2/-2)
tests/suite/regression/r/654219.result (+63/-0)
tests/suite/regression/t/654219.test (+64/-0)
Text conflict in plugin/drizzle_protocol/drizzle_protocol.cc
Contents conflict in plugin/drizzle_protocol/vio.cc
Contents conflict in plugin/drizzle_protocol/vio.h
Contents conflict in plugin/drizzle_protocol/viosocket.cc
To merge this branch: bzr merge lp:~brianaker/drizzle/bug-fix-654219
Reviewer Review Type Date Requested Status
Drizzle Merge Team Pending
Review via email: mp+37684@code.launchpad.net

Description of the change

This fixes bug 654219.

To post a comment you must log in.
Revision history for this message
Lee Bieber (kalebral-deactivatedaccount) wrote :

Need to re-merge with trunk getting conflicts.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugin/drizzle_protocol/drizzle_protocol.cc'
2--- plugin/drizzle_protocol/drizzle_protocol.cc 2010-10-02 21:15:42 +0000
3+++ plugin/drizzle_protocol/drizzle_protocol.cc 2010-10-06 01:14:00 +0000
4@@ -1,6 +1,7 @@
5-/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
6+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
7 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
8 *
9+<<<<<<< TREE
10 * Copyright (C) 2008 Sun Microsystems
11 *
12 * This program is free software; you can redistribute it and/or modify
13@@ -15,8 +16,26 @@
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+=======
18+ * Copyright (C) 2010 Brian Aker
19+ *
20+ * This program is free software; you can redistribute it and/or modify
21+ * it under the terms of the GNU General Public License as published by
22+ * the Free Software Foundation; either version 2 of the License, or
23+ * (at your option) any later version.
24+ *
25+ * This program is distributed in the hope that it will be useful,
26+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
27+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28+ * GNU General Public License for more details.
29+ *
30+ * You should have received a copy of the GNU General Public License
31+ * along with this program; if not, write to the Free Software
32+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33+>>>>>>> MERGE-SOURCE
34 */
35
36+
37 #include "config.h"
38 #include <drizzled/gettext.h>
39 #include <drizzled/error.h>
40@@ -29,13 +48,8 @@
41 #include <iostream>
42 #include <boost/program_options.hpp>
43 #include <drizzled/module/option_map.h>
44-#include "pack.h"
45-#include "errmsg.h"
46 #include "drizzle_protocol.h"
47-#include "options.h"
48-#include "table_function.h"
49-
50-#define PROTOCOL_VERSION 10
51+#include "plugin/drizzle_protocol/status_table.h"
52
53 namespace po= boost::program_options;
54 using namespace drizzled;
55@@ -44,18 +58,15 @@
56 namespace drizzle_protocol
57 {
58
59-
60-static const uint32_t DRIZZLE_TCP_PORT= 4427;
61-static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024;
62 static uint32_t port;
63 static uint32_t connect_timeout;
64 static uint32_t read_timeout;
65 static uint32_t write_timeout;
66 static uint32_t retry_count;
67 static uint32_t buffer_length;
68-static char* bind_address= NULL;
69+static char* bind_address;
70
71-static plugin::TableFunction* drizzle_status_table_function_ptr= NULL;
72+static const uint32_t DRIZZLE_TCP_PORT= 4427;
73
74 ListenDrizzleProtocol::~ListenDrizzleProtocol()
75 {
76@@ -70,770 +81,11 @@
77
78 in_port_t ListenDrizzleProtocol::getPort(void) const
79 {
80- char *env;
81-
82- if (port == 0)
83- {
84- port= DRIZZLE_TCP_PORT;
85-
86- if ((env = getenv("DRIZZLE_TCP_PORT")))
87- port= (uint32_t) atoi(env);
88-
89- assert(port != 0);
90- }
91-
92 return (in_port_t) port;
93 }
94
95-plugin::Client *ListenDrizzleProtocol::getClient(int fd)
96-{
97- int new_fd;
98- new_fd= acceptTcp(fd);
99- if (new_fd == -1)
100- return NULL;
101-
102- return new (nothrow) ClientDrizzleProtocol(new_fd, using_mysql41_protocol);
103-}
104-
105-drizzled::atomic<uint64_t> ClientDrizzleProtocol::connectionCount;
106-drizzled::atomic<uint64_t> ClientDrizzleProtocol::failedConnections;
107-drizzled::atomic<uint64_t> ClientDrizzleProtocol::connected;
108-
109-ClientDrizzleProtocol::ClientDrizzleProtocol(int fd, bool using_mysql41_protocol_arg):
110- using_mysql41_protocol(using_mysql41_protocol_arg)
111-{
112- net.vio= 0;
113-
114- if (fd == -1)
115- return;
116-
117- if (drizzleclient_net_init_sock(&net, fd, 0, buffer_length))
118- throw bad_alloc();
119-
120- drizzleclient_net_set_read_timeout(&net, read_timeout);
121- drizzleclient_net_set_write_timeout(&net, write_timeout);
122- net.retry_count=retry_count;
123-}
124-
125-ClientDrizzleProtocol::~ClientDrizzleProtocol()
126-{
127- if (net.vio)
128- drizzleclient_vio_close(net.vio);
129-}
130-
131-int ClientDrizzleProtocol::getFileDescriptor(void)
132-{
133- return drizzleclient_net_get_sd(&net);
134-}
135-
136-bool ClientDrizzleProtocol::isConnected()
137-{
138- return net.vio != 0;
139-}
140-
141-bool ClientDrizzleProtocol::isReading(void)
142-{
143- return net.reading_or_writing == 1;
144-}
145-
146-bool ClientDrizzleProtocol::isWriting(void)
147-{
148- return net.reading_or_writing == 2;
149-}
150-
151-bool ClientDrizzleProtocol::flush()
152-{
153- if (net.vio == NULL)
154- return false;
155- bool ret= drizzleclient_net_write(&net, (unsigned char*) packet.ptr(),
156- packet.length());
157- packet.length(0);
158- return ret;
159-}
160-
161-void ClientDrizzleProtocol::close(void)
162-{
163- if (net.vio)
164- {
165- drizzleclient_net_close(&net);
166- drizzleclient_net_end(&net);
167- connected.decrement();
168- }
169-}
170-
171-bool ClientDrizzleProtocol::authenticate()
172-{
173- bool connection_is_valid;
174-
175- connectionCount.increment();
176- connected.increment();
177-
178- /* Use "connect_timeout" value during connection phase */
179- drizzleclient_net_set_read_timeout(&net, connect_timeout);
180- drizzleclient_net_set_write_timeout(&net, connect_timeout);
181-
182- connection_is_valid= checkConnection();
183-
184- if (connection_is_valid)
185- sendOK();
186- else
187- {
188- sendError(session->main_da.sql_errno(), session->main_da.message());
189- failedConnections.increment();
190- return false;
191- }
192-
193- /* Connect completed, set read/write timeouts back to default */
194- drizzleclient_net_set_read_timeout(&net, read_timeout);
195- drizzleclient_net_set_write_timeout(&net, write_timeout);
196- return true;
197-}
198-
199-bool ClientDrizzleProtocol::readCommand(char **l_packet, uint32_t *packet_length)
200-{
201- /*
202- This thread will do a blocking read from the client which
203- will be interrupted when the next command is received from
204- the client, the connection is closed or "net_wait_timeout"
205- number of seconds has passed
206- */
207-#ifdef NEVER
208- /* We can do this much more efficiently with poll timeouts or watcher thread,
209- disabling for now, which means net_wait_timeout == read_timeout. */
210- drizzleclient_net_set_read_timeout(&net,
211- session->variables.net_wait_timeout);
212-#endif
213-
214- net.pkt_nr=0;
215-
216- *packet_length= drizzleclient_net_read(&net);
217- if (*packet_length == packet_error)
218- {
219- /* Check if we can continue without closing the connection */
220-
221- if(net.last_errno== CR_NET_PACKET_TOO_LARGE)
222- my_error(ER_NET_PACKET_TOO_LARGE, MYF(0));
223- if (session->main_da.status() == Diagnostics_area::DA_ERROR)
224- sendError(session->main_da.sql_errno(), session->main_da.message());
225- else
226- sendOK();
227-
228- if (net.error != 3)
229- return false; // We have to close it.
230-
231- net.error= 0;
232- *packet_length= 0;
233- return true;
234- }
235-
236- *l_packet= (char*) net.read_pos;
237-
238- /*
239- 'packet_length' contains length of data, as it was stored in packet
240- header. In case of malformed header, drizzleclient_net_read returns zero.
241- If packet_length is not zero, drizzleclient_net_read ensures that the returned
242- number of bytes was actually read from network.
243- There is also an extra safety measure in drizzleclient_net_read:
244- it sets packet[packet_length]= 0, but only for non-zero packets.
245- */
246-
247- if (*packet_length == 0) /* safety */
248- {
249- /* Initialize with COM_SLEEP packet */
250- (*l_packet)[0]= (unsigned char) COM_SLEEP;
251- *packet_length= 1;
252- }
253- else if (using_mysql41_protocol)
254- {
255- /* Map from MySQL commands to Drizzle commands. */
256- switch ((int)(*l_packet)[0])
257- {
258- case 0: /* SLEEP */
259- case 1: /* QUIT */
260- case 2: /* INIT_DB */
261- case 3: /* QUERY */
262- break;
263-
264- case 8: /* SHUTDOWN */
265- (*l_packet)[0]= (unsigned char) COM_SHUTDOWN;
266- break;
267-
268- case 14: /* PING */
269- (*l_packet)[0]= (unsigned char) COM_SHUTDOWN;
270- break;
271-
272-
273- default:
274- /* Just drop connection for MySQL commands we don't support. */
275- (*l_packet)[0]= (unsigned char) COM_QUIT;
276- *packet_length= 1;
277- break;
278- }
279- }
280-
281- /* Do not rely on drizzleclient_net_read, extra safety against programming errors. */
282- (*l_packet)[*packet_length]= '\0'; /* safety */
283-
284-#ifdef NEVER
285- /* See comment above. */
286- /* Restore read timeout value */
287- drizzleclient_net_set_read_timeout(&net,
288- session->variables.net_read_timeout);
289-#endif
290-
291- return true;
292-}
293-
294-/**
295- Return ok to the client.
296-
297- The ok packet has the following structure:
298-
299- - 0 : Marker (1 byte)
300- - affected_rows : Stored in 1-9 bytes
301- - id : Stored in 1-9 bytes
302- - server_status : Copy of session->server_status; Can be used by client
303- to check if we are inside an transaction.
304- New in 4.0 client
305- - warning_count : Stored in 2 bytes; New in 4.1 client
306- - message : Stored as packed length (1-9 bytes) + message.
307- Is not stored if no message.
308-
309- @param session Thread handler
310- @param affected_rows Number of rows changed by statement
311- @param id Auto_increment id for first row (if used)
312- @param message Message to send to the client (Used by mysql_status)
313-*/
314-
315-void ClientDrizzleProtocol::sendOK()
316-{
317- unsigned char buff[DRIZZLE_ERRMSG_SIZE+10],*pos;
318- const char *message= NULL;
319- uint32_t tmp;
320-
321- if (!net.vio) // hack for re-parsing queries
322- {
323- return;
324- }
325-
326- buff[0]=0; // No fields
327- if (session->main_da.status() == Diagnostics_area::DA_OK)
328- {
329- if (client_capabilities & CLIENT_FOUND_ROWS && session->main_da.found_rows())
330- pos=drizzleclient_net_store_length(buff+1,session->main_da.found_rows());
331- else
332- pos=drizzleclient_net_store_length(buff+1,session->main_da.affected_rows());
333- pos=drizzleclient_net_store_length(pos, session->main_da.last_insert_id());
334- int2store(pos, session->main_da.server_status());
335- pos+=2;
336- tmp= min(session->main_da.total_warn_count(), (uint32_t)65535);
337- message= session->main_da.message();
338- }
339- else
340- {
341- pos=drizzleclient_net_store_length(buff+1,0);
342- pos=drizzleclient_net_store_length(pos, 0);
343- int2store(pos, session->server_status);
344- pos+=2;
345- tmp= min(session->total_warn_count, (uint32_t)65535);
346- }
347-
348- /* We can only return up to 65535 warnings in two bytes */
349- int2store(pos, tmp);
350- pos+= 2;
351-
352- session->main_da.can_overwrite_status= true;
353-
354- if (message && message[0])
355- {
356- size_t length= strlen(message);
357- pos=drizzleclient_net_store_length(pos,length);
358- memcpy(pos,(unsigned char*) message,length);
359- pos+=length;
360- }
361- drizzleclient_net_write(&net, buff, (size_t) (pos-buff));
362- drizzleclient_net_flush(&net);
363-
364- session->main_da.can_overwrite_status= false;
365-}
366-
367-/**
368- Send eof (= end of result set) to the client.
369-
370- The eof packet has the following structure:
371-
372- - 254 (DRIZZLE_PROTOCOL_NO_MORE_DATA) : Marker (1 byte)
373- - warning_count : Stored in 2 bytes; New in 4.1 client
374- - status_flag : Stored in 2 bytes;
375- For flags like SERVER_MORE_RESULTS_EXISTS.
376-
377- Note that the warning count will not be sent if 'no_flush' is set as
378- we don't want to report the warning count until all data is sent to the
379- client.
380-*/
381-
382-void ClientDrizzleProtocol::sendEOF()
383-{
384- /* Set to true if no active vio, to work well in case of --init-file */
385- if (net.vio != 0)
386- {
387- session->main_da.can_overwrite_status= true;
388- writeEOFPacket(session->main_da.server_status(),
389- session->main_da.total_warn_count());
390- drizzleclient_net_flush(&net);
391- session->main_da.can_overwrite_status= false;
392- }
393- packet.shrink(buffer_length);
394-}
395-
396-
397-void ClientDrizzleProtocol::sendError(uint32_t sql_errno, const char *err)
398-{
399- uint32_t length;
400- /*
401- buff[]: sql_errno:2 + ('#':1 + SQLSTATE_LENGTH:5) + DRIZZLE_ERRMSG_SIZE:512
402- */
403- unsigned char buff[2+1+SQLSTATE_LENGTH+DRIZZLE_ERRMSG_SIZE], *pos;
404-
405- assert(sql_errno);
406- assert(err && err[0]);
407-
408- /*
409- It's one case when we can push an error even though there
410- is an OK or EOF already.
411- */
412- session->main_da.can_overwrite_status= true;
413-
414- /* Abort multi-result sets */
415- session->server_status&= ~SERVER_MORE_RESULTS_EXISTS;
416-
417- /**
418- Send a error string to client.
419-
420- For SIGNAL/RESIGNAL and GET DIAGNOSTICS functionality it's
421- critical that every error that can be intercepted is issued in one
422- place only, my_message_sql.
423- */
424-
425- if (net.vio == 0)
426- {
427- return;
428- }
429-
430- int2store(buff,sql_errno);
431- pos= buff+2;
432-
433- /* The first # is to make the client backward compatible */
434- buff[2]= '#';
435- pos= (unsigned char*) strcpy((char*) buff+3, drizzle_errno_to_sqlstate(sql_errno));
436- pos+= strlen(drizzle_errno_to_sqlstate(sql_errno));
437-
438- char *tmp= strncpy((char*)pos, err, DRIZZLE_ERRMSG_SIZE-1);
439- tmp+= strlen((char*)pos);
440- tmp[0]= '\0';
441- length= (uint32_t)(tmp-(char*)buff);
442- err= (char*) buff;
443-
444- drizzleclient_net_write_command(&net,(unsigned char) 255, (unsigned char*) "", 0, (unsigned char*) err, length);
445-
446- session->main_da.can_overwrite_status= false;
447-}
448-
449-/**
450- Send name and type of result to client.
451-
452- Sum fields has table name empty and field_name.
453-
454- @param Session Thread data object
455- @param list List of items to send to client
456- @param flag Bit mask with the following functions:
457- - 1 send number of rows
458- - 2 send default values
459- - 4 don't write eof packet
460-
461- @retval
462- 0 ok
463- @retval
464- 1 Error (Note that in this case the error is not sent to the
465- client)
466-*/
467-bool ClientDrizzleProtocol::sendFields(List<Item> *list)
468-{
469- List_iterator_fast<Item> it(*list);
470- Item *item;
471- unsigned char buff[80];
472- String tmp((char*) buff,sizeof(buff),&my_charset_bin);
473-
474- unsigned char *row_pos= drizzleclient_net_store_length(buff, list->elements);
475- (void) drizzleclient_net_write(&net, buff, (size_t) (row_pos-buff));
476-
477- while ((item=it++))
478- {
479- char *pos;
480- SendField field;
481- item->make_field(&field);
482-
483- packet.length(0);
484-
485- if (store(STRING_WITH_LEN("def")) ||
486- store(field.db_name) ||
487- store(field.table_name) ||
488- store(field.org_table_name) ||
489- store(field.col_name) ||
490- store(field.org_col_name) ||
491- packet.realloc(packet.length()+12))
492- goto err;
493-
494- /* Store fixed length fields */
495- pos= (char*) packet.ptr()+packet.length();
496- *pos++= 12; // Length of packed fields
497- /* No conversion */
498- int2store(pos, field.charsetnr);
499- int4store(pos+2, field.length);
500-
501- if (using_mysql41_protocol)
502- {
503- /* Switch to MySQL field numbering. */
504- switch (field.type)
505- {
506- case DRIZZLE_TYPE_LONG:
507- pos[6]= 3;
508- break;
509-
510- case DRIZZLE_TYPE_DOUBLE:
511- pos[6]= 5;
512- break;
513-
514- case DRIZZLE_TYPE_NULL:
515- pos[6]= 6;
516- break;
517-
518- case DRIZZLE_TYPE_TIMESTAMP:
519- pos[6]= 7;
520- break;
521-
522- case DRIZZLE_TYPE_LONGLONG:
523- pos[6]= 8;
524- break;
525-
526- case DRIZZLE_TYPE_DATETIME:
527- pos[6]= 12;
528- break;
529-
530- case DRIZZLE_TYPE_DATE:
531- pos[6]= 14;
532- break;
533-
534- case DRIZZLE_TYPE_VARCHAR:
535- pos[6]= 15;
536- break;
537-
538- case DRIZZLE_TYPE_DECIMAL:
539- pos[6]= (char)246;
540- break;
541-
542- case DRIZZLE_TYPE_ENUM:
543- pos[6]= (char)247;
544- break;
545-
546- case DRIZZLE_TYPE_BLOB:
547- pos[6]= (char)252;
548- break;
549- }
550- }
551- else
552- {
553- /* Add one to compensate for tinyint removal from enum. */
554- pos[6]= field.type + 1;
555- }
556-
557- int2store(pos+7,field.flags);
558- pos[9]= (char) field.decimals;
559- pos[10]= 0; // For the future
560- pos[11]= 0; // For the future
561- pos+= 12;
562-
563- packet.length((uint32_t) (pos - packet.ptr()));
564- if (flush())
565- break;
566- }
567-
568- /*
569- Mark the end of meta-data result set, and store session->server_status,
570- to show that there is no cursor.
571- Send no warning information, as it will be sent at statement end.
572- */
573- writeEOFPacket(session->server_status, session->total_warn_count);
574- return 0;
575-
576-err:
577- my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES),
578- MYF(0));
579- return 1;
580-}
581-
582-bool ClientDrizzleProtocol::store(Field *from)
583-{
584- if (from->is_null())
585- return store();
586- char buff[MAX_FIELD_WIDTH];
587- String str(buff,sizeof(buff), &my_charset_bin);
588-
589- from->val_str(&str);
590-
591- return netStoreData((const unsigned char *)str.ptr(), str.length());
592-}
593-
594-bool ClientDrizzleProtocol::store(void)
595-{
596- char buff[1];
597- buff[0]= (char)251;
598- return packet.append(buff, sizeof(buff), PACKET_BUFFER_EXTRA_ALLOC);
599-}
600-
601-bool ClientDrizzleProtocol::store(int32_t from)
602-{
603- char buff[12];
604- return netStoreData((unsigned char*) buff,
605- (size_t) (internal::int10_to_str(from, buff, -10) - buff));
606-}
607-
608-bool ClientDrizzleProtocol::store(uint32_t from)
609-{
610- char buff[11];
611- return netStoreData((unsigned char*) buff,
612- (size_t) (internal::int10_to_str(from, buff, 10) - buff));
613-}
614-
615-bool ClientDrizzleProtocol::store(int64_t from)
616-{
617- char buff[22];
618- return netStoreData((unsigned char*) buff,
619- (size_t) (internal::int64_t10_to_str(from, buff, -10) - buff));
620-}
621-
622-bool ClientDrizzleProtocol::store(uint64_t from)
623-{
624- char buff[21];
625- return netStoreData((unsigned char*) buff,
626- (size_t) (internal::int64_t10_to_str(from, buff, 10) - buff));
627-}
628-
629-bool ClientDrizzleProtocol::store(double from, uint32_t decimals, String *buffer)
630-{
631- buffer->set_real(from, decimals, session->charset());
632- return netStoreData((unsigned char*) buffer->ptr(), buffer->length());
633-}
634-
635-bool ClientDrizzleProtocol::store(const char *from, size_t length)
636-{
637- return netStoreData((const unsigned char *)from, length);
638-}
639-
640-bool ClientDrizzleProtocol::wasAborted(void)
641-{
642- return net.error && net.vio != 0;
643-}
644-
645-bool ClientDrizzleProtocol::haveMoreData(void)
646-{
647- return drizzleclient_net_more_data(&net);
648-}
649-
650-bool ClientDrizzleProtocol::haveError(void)
651-{
652- return net.error || net.vio == 0;
653-}
654-
655-bool ClientDrizzleProtocol::checkConnection(void)
656-{
657- uint32_t pkt_len= 0;
658- char *end;
659-
660- // TCP/IP connection
661- {
662- char ip[NI_MAXHOST];
663- uint16_t peer_port;
664-
665- if (drizzleclient_net_peer_addr(&net, ip, &peer_port, NI_MAXHOST))
666- {
667- my_error(ER_BAD_HOST_ERROR, MYF(0), session->getSecurityContext().getIp().c_str());
668- return false;
669- }
670-
671- session->getSecurityContext().setIp(ip);
672- }
673- drizzleclient_net_keepalive(&net, true);
674-
675- uint32_t server_capabilites;
676- {
677- /* buff[] needs to big enough to hold the server_version variable */
678- char buff[SERVER_VERSION_LENGTH + SCRAMBLE_LENGTH + 64];
679-
680- server_capabilites= CLIENT_BASIC_FLAGS;
681-
682- if (using_mysql41_protocol)
683- server_capabilites|= CLIENT_PROTOCOL_MYSQL41;
684-
685-#ifdef HAVE_COMPRESS
686- server_capabilites|= CLIENT_COMPRESS;
687-#endif /* HAVE_COMPRESS */
688-
689- end= buff + strlen(PANDORA_RELEASE_VERSION);
690- if ((end - buff) >= SERVER_VERSION_LENGTH)
691- end= buff + (SERVER_VERSION_LENGTH - 1);
692- memcpy(buff, PANDORA_RELEASE_VERSION, end - buff);
693- *end= 0;
694- end++;
695-
696- int4store((unsigned char*) end, session->variables.pseudo_thread_id);
697- end+= 4;
698-
699- /* We don't use scramble anymore. */
700- memset(end, 'X', SCRAMBLE_LENGTH_323);
701- end+= SCRAMBLE_LENGTH_323;
702- *end++= 0; /* an empty byte for some reason */
703-
704- int2store(end, server_capabilites);
705- /* write server characteristics: up to 16 bytes allowed */
706- end[2]=(char) default_charset_info->number;
707- int2store(end+3, session->server_status);
708- memset(end+5, 0, 13);
709- end+= 18;
710-
711- /* Write scramble tail. */
712- memset(end, 'X', SCRAMBLE_LENGTH - SCRAMBLE_LENGTH_323);
713- end+= (SCRAMBLE_LENGTH - SCRAMBLE_LENGTH_323);
714- *end++= 0; /* an empty byte for some reason */
715-
716- /* At this point we write connection message and read reply */
717- if (drizzleclient_net_write_command(&net
718- , (unsigned char) PROTOCOL_VERSION
719- , (unsigned char*) ""
720- , 0
721- , (unsigned char*) buff
722- , (size_t) (end-buff))
723- || (pkt_len= drizzleclient_net_read(&net)) == packet_error
724- || pkt_len < MIN_HANDSHAKE_SIZE)
725- {
726- my_error(ER_HANDSHAKE_ERROR, MYF(0), session->getSecurityContext().getIp().c_str());
727- return false;
728- }
729- }
730- if (packet.alloc(buffer_length))
731- return false; /* The error is set by alloc(). */
732-
733- client_capabilities= uint2korr(net.read_pos);
734-
735-
736- client_capabilities|= ((uint32_t) uint2korr(net.read_pos + 2)) << 16;
737- session->max_client_packet_length= uint4korr(net.read_pos + 4);
738- end= (char*) net.read_pos + 32;
739-
740- /*
741- Disable those bits which are not supported by the server.
742- This is a precautionary measure, if the client lies. See Bug#27944.
743- */
744- client_capabilities&= server_capabilites;
745-
746- if (end >= (char*) net.read_pos + pkt_len + 2)
747- {
748- my_error(ER_HANDSHAKE_ERROR, MYF(0), session->getSecurityContext().getIp().c_str());
749- return false;
750- }
751-
752- net.return_status= &session->server_status;
753-
754- char *user= end;
755- char *passwd= strchr(user, '\0')+1;
756- uint32_t user_len= passwd - user - 1;
757- char *l_db= passwd;
758-
759- /*
760- Old clients send null-terminated string as password; new clients send
761- the size (1 byte) + string (not null-terminated). Hence in case of empty
762- password both send '\0'.
763-
764- This strlen() can't be easily deleted without changing client.
765-
766- Cast *passwd to an unsigned char, so that it doesn't extend the sign for
767- *passwd > 127 and become 2**32-127+ after casting to uint.
768- */
769- uint32_t passwd_len= client_capabilities & CLIENT_SECURE_CONNECTION ?
770- (unsigned char)(*passwd++) : strlen(passwd);
771- l_db= client_capabilities & CLIENT_CONNECT_WITH_DB ? l_db + passwd_len + 1 : 0;
772-
773- /* strlen() can't be easily deleted without changing client */
774- uint32_t db_len= l_db ? strlen(l_db) : 0;
775-
776- if (passwd + passwd_len + db_len > (char *) net.read_pos + pkt_len)
777- {
778- my_error(ER_HANDSHAKE_ERROR, MYF(0), session->getSecurityContext().getIp().c_str());
779- return false;
780- }
781-
782- /* If username starts and ends in "'", chop them off */
783- if (user_len > 1 && user[0] == '\'' && user[user_len - 1] == '\'')
784- {
785- user[user_len-1]= 0;
786- user++;
787- user_len-= 2;
788- }
789-
790- session->getSecurityContext().setUser(user);
791-
792- return session->checkUser(passwd, passwd_len, l_db);
793-}
794-
795-bool ClientDrizzleProtocol::netStoreData(const unsigned char *from, size_t length)
796-{
797- size_t packet_length= packet.length();
798- /*
799- The +9 comes from that strings of length longer than 16M require
800- 9 bytes to be stored (see drizzleclient_net_store_length).
801- */
802- if (packet_length+9+length > packet.alloced_length() &&
803- packet.realloc(packet_length+9+length))
804- return 1;
805- unsigned char *to= drizzleclient_net_store_length((unsigned char*) packet.ptr()+packet_length, length);
806- memcpy(to,from,length);
807- packet.length((size_t) (to+length-(unsigned char*) packet.ptr()));
808- return 0;
809-}
810-
811-/**
812- Format EOF packet according to the current client and
813- write it to the network output buffer.
814-*/
815-
816-void ClientDrizzleProtocol::writeEOFPacket(uint32_t server_status,
817- uint32_t total_warn_count)
818-{
819- unsigned char buff[5];
820- /*
821- Don't send warn count during SP execution, as the warn_list
822- is cleared between substatements, and mysqltest gets confused
823- */
824- uint32_t tmp= min(total_warn_count, (uint32_t)65535);
825- buff[0]= DRIZZLE_PROTOCOL_NO_MORE_DATA;
826- int2store(buff+1, tmp);
827- /*
828- The following test should never be true, but it's better to do it
829- because if 'is_fatal_error' is set the server is not going to execute
830- other queries (see the if test in dispatch_command / COM_QUERY)
831- */
832- if (session->is_fatal_error)
833- server_status&= ~SERVER_MORE_RESULTS_EXISTS;
834- int2store(buff + 3, server_status);
835- drizzleclient_net_write(&net, buff, 5);
836-}
837-
838-static int init(module::Context &context)
839-{
840- drizzle_status_table_function_ptr= new DrizzleProtocolStatus;
841-
842- context.add(drizzle_status_table_function_ptr);
843-
844+static int init(drizzled::module::Context &context)
845+{
846 const module::option_map &vm= context.getOptions();
847 if (vm.count("port"))
848 {
849@@ -875,7 +127,7 @@
850 {
851 if (retry_count < 1 || retry_count > 100)
852 {
853- errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for retry_count\n"));
854+ errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for retry_count"));
855 exit(-1);
856 }
857 }
858@@ -898,17 +150,16 @@
859 {
860 bind_address= NULL;
861 }
862-
863- context.add(new ListenDrizzleProtocol("drizzle_protocol", false));
864+
865+ context.add(new StatusTable);
866+ context.add(new ListenDrizzleProtocol("drizzle_protocol", true));
867+
868 return 0;
869 }
870
871 static DRIZZLE_SYSVAR_UINT(port, port, PLUGIN_VAR_RQCMDARG,
872- N_("Port number to use for connection or 0 for "
873- "default to, in order of "
874- "preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
875- "built-in default (4427)."),
876- NULL, NULL, 0, 0, 65535, 0);
877+ N_("Port number to use for connection or 0 for default to with Drizzle/MySQL protocol."),
878+ NULL, NULL, DRIZZLE_TCP_PORT, 0, 65535, 0);
879 static DRIZZLE_SYSVAR_UINT(connect_timeout, connect_timeout,
880 PLUGIN_VAR_RQCMDARG, N_("Connect Timeout."),
881 NULL, NULL, 10, 1, 300, 0);
882@@ -927,11 +178,8 @@
883 static void init_options(drizzled::module::option_context &context)
884 {
885 context("port",
886- po::value<uint32_t>(&port)->default_value(0),
887- N_("Port number to use for connection or 0 for "
888- "default to, in order of "
889- "preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
890- "built-in default (4427)."));
891+ po::value<uint32_t>(&port)->default_value(DRIZZLE_TCP_PORT),
892+ N_("Port number to use for connection or 0 for default to with Drizzle/MySQL protocol."));
893 context("connect-timeout",
894 po::value<uint32_t>(&connect_timeout)->default_value(10),
895 N_("Connect Timeout."));
896@@ -963,103 +211,6 @@
897 NULL
898 };
899
900-static int drizzle_protocol_connection_count_func(drizzle_show_var *var, char *buff)
901-{
902- var->type= SHOW_LONGLONG;
903- var->value= buff;
904- *((uint64_t *)buff)= ClientDrizzleProtocol::connectionCount;
905- return 0;
906-}
907-
908-static int drizzle_protocol_connected_count_func(drizzle_show_var *var, char *buff)
909-{
910- var->type= SHOW_LONGLONG;
911- var->value= buff;
912- *((uint64_t *)buff)= ClientDrizzleProtocol::connected;
913- return 0;
914-}
915-
916-static int drizzle_protocol_failed_count_func(drizzle_show_var *var, char *buff)
917-{
918- var->type= SHOW_LONGLONG;
919- var->value= buff;
920- *((uint64_t *)buff)= ClientDrizzleProtocol::failedConnections;
921- return 0;
922-}
923-
924-static st_show_var_func_container drizzle_protocol_connection_count=
925- { &drizzle_protocol_connection_count_func };
926-
927-static st_show_var_func_container drizzle_protocol_connected_count=
928- { &drizzle_protocol_connected_count_func };
929-
930-static st_show_var_func_container drizzle_protocol_failed_count=
931- { &drizzle_protocol_failed_count_func };
932-
933-static drizzle_show_var drizzle_protocol_status_variables[]= {
934- {"Connections",
935- (char*) &drizzle_protocol_connection_count, SHOW_FUNC},
936- {"Connected",
937- (char*) &drizzle_protocol_connected_count, SHOW_FUNC},
938- {"Failed_connections",
939- (char*) &drizzle_protocol_failed_count, SHOW_FUNC},
940- {NULL, NULL, SHOW_LONGLONG}
941-};
942-
943-DrizzleProtocolStatus::Generator::Generator(drizzled::Field **fields) :
944- plugin::TableFunction::Generator(fields)
945-{
946- status_var_ptr= drizzle_protocol_status_variables;
947-}
948-
949-bool DrizzleProtocolStatus::Generator::populate()
950-{
951- MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
952- char * const buff= (char *) &buff_data;
953- drizzle_show_var tmp;
954-
955- if (status_var_ptr->name)
956- {
957- std::ostringstream oss;
958- string return_value;
959- const char *value;
960- int type;
961-
962- push(status_var_ptr->name);
963-
964- if (status_var_ptr->type == SHOW_FUNC)
965- {
966- ((mysql_show_var_func)((st_show_var_func_container *)status_var_ptr->value)->func)(&tmp, buff);
967- value= buff;
968- type= tmp.type;
969- }
970- else
971- {
972- value= status_var_ptr->value;
973- type= status_var_ptr->type;
974- }
975-
976- switch(type)
977- {
978- case SHOW_LONGLONG:
979- oss << *(uint64_t*) value;
980- return_value= oss.str();
981- break;
982- default:
983- assert(0);
984- }
985- if (return_value.length())
986- push(return_value);
987- else
988- push(" ");
989-
990- status_var_ptr++;
991-
992- return true;
993- }
994- return false;
995-}
996-
997 } /* namespace drizzle_protocol */
998
999 DRIZZLE_PLUGIN(drizzle_protocol::init, drizzle_protocol::sys_variables, drizzle_protocol::init_options);
1000
1001=== modified file 'plugin/drizzle_protocol/drizzle_protocol.h'
1002--- plugin/drizzle_protocol/drizzle_protocol.h 2010-09-01 19:17:03 +0000
1003+++ plugin/drizzle_protocol/drizzle_protocol.h 2010-10-06 01:14:00 +0000
1004@@ -1,11 +1,12 @@
1005-/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1006+/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1007 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1008 *
1009- * Copyright (C) 2008 Sun Microsystems
1010+ * Copyright (C) 2010 Brian Aker
1011 *
1012 * This program is free software; you can redistribute it and/or modify
1013 * it under the terms of the GNU General Public License as published by
1014- * the Free Software Foundation; version 2 of the License.
1015+ * the Free Software Foundation; either version 2 of the License, or
1016+ * (at your option) any later version.
1017 *
1018 * This program is distributed in the hope that it will be useful,
1019 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1020@@ -17,6 +18,7 @@
1021 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1022 */
1023
1024+
1025 #ifndef PLUGIN_DRIZZLE_PROTOCOL_DRIZZLE_PROTOCOL_H
1026 #define PLUGIN_DRIZZLE_PROTOCOL_DRIZZLE_PROTOCOL_H
1027
1028@@ -25,77 +27,24 @@
1029 #include <drizzled/atomics.h>
1030 #include "drizzled/plugin/table_function.h"
1031
1032-#include "net_serv.h"
1033+#include "plugin/mysql_protocol/mysql_protocol.h"
1034
1035 namespace drizzle_protocol
1036 {
1037
1038-class ListenDrizzleProtocol: public drizzled::plugin::ListenTcp
1039+class ListenDrizzleProtocol: public ListenMySQLProtocol
1040 {
1041-private:
1042- bool using_mysql41_protocol;
1043-
1044 public:
1045 ListenDrizzleProtocol(std::string name_arg, bool using_mysql41_protocol_arg):
1046- drizzled::plugin::ListenTcp(name_arg),
1047- using_mysql41_protocol(using_mysql41_protocol_arg)
1048+ ListenMySQLProtocol(name_arg, using_mysql41_protocol_arg)
1049 { }
1050- virtual ~ListenDrizzleProtocol();
1051- virtual const char* getHost(void) const;
1052- virtual in_port_t getPort(void) const;
1053- virtual drizzled::plugin::Client *getClient(int fd);
1054-};
1055-
1056-class ClientDrizzleProtocol: public drizzled::plugin::Client
1057-{
1058-private:
1059- NET net;
1060- drizzled::String packet;
1061- uint32_t client_capabilities;
1062- bool using_mysql41_protocol;
1063-
1064- bool checkConnection(void);
1065- bool netStoreData(const unsigned char *from, size_t length);
1066- void writeEOFPacket(uint32_t server_status, uint32_t total_warn_count);
1067-
1068-public:
1069- ClientDrizzleProtocol(int fd, bool using_mysql41_protocol_arg);
1070- virtual ~ClientDrizzleProtocol();
1071-
1072- static drizzled::atomic<uint64_t> connectionCount;
1073- static drizzled::atomic<uint64_t> failedConnections;
1074- static drizzled::atomic<uint64_t> connected;
1075-
1076- virtual int getFileDescriptor(void);
1077- virtual bool isConnected();
1078- virtual bool isReading(void);
1079- virtual bool isWriting(void);
1080- virtual bool flush(void);
1081- virtual void close(void);
1082-
1083- virtual bool authenticate(void);
1084- virtual bool readCommand(char **packet, uint32_t *packet_length);
1085-
1086- virtual void sendOK(void);
1087- virtual void sendEOF(void);
1088- virtual void sendError(uint32_t sql_errno, const char *err);
1089-
1090- virtual bool sendFields(drizzled::List<drizzled::Item> *list);
1091-
1092- using Client::store;
1093- virtual bool store(drizzled::Field *from);
1094- virtual bool store(void);
1095- virtual bool store(int32_t from);
1096- virtual bool store(uint32_t from);
1097- virtual bool store(int64_t from);
1098- virtual bool store(uint64_t from);
1099- virtual bool store(double from, uint32_t decimals, drizzled::String *buffer);
1100- virtual bool store(const char *from, size_t length);
1101-
1102- virtual bool haveError(void);
1103- virtual bool haveMoreData(void);
1104- virtual bool wasAborted(void);
1105-};
1106+
1107+ ~ListenDrizzleProtocol();
1108+
1109+ const char* getHost(void) const;
1110+ in_port_t getPort(void) const;
1111+};
1112+
1113
1114 } /* namespace drizzle_protocol */
1115
1116
1117=== modified file 'plugin/drizzle_protocol/errmsg.cc'
1118--- plugin/drizzle_protocol/errmsg.cc 2010-03-04 18:06:27 +0000
1119+++ plugin/drizzle_protocol/errmsg.cc 2010-10-06 01:14:00 +0000
1120@@ -17,7 +17,7 @@
1121 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1122 */
1123
1124-/* Error messages for MySQL clients */
1125+/* Stub file for error messages */
1126
1127 #include "config.h"
1128 #include <drizzled/gettext.h>
1129@@ -25,96 +25,4 @@
1130
1131 namespace drizzle_protocol
1132 {
1133-
1134-static const char *client_errors[]=
1135-{
1136- N_("Unknown Drizzle error"),
1137- N_("Can't create UNIX socket (%d)"),
1138- N_("Can't connect to local Drizzle server through socket '%-.100s' (%d)"),
1139- N_("Can't connect to Drizzle server on '%-.100s:%lu' (%d)"),
1140- N_("Can't create TCP/IP socket (%d)"),
1141- N_("Unknown Drizzle server host '%-.100s' (%d)"),
1142- N_("Drizzle server has gone away"),
1143- N_("Protocol mismatch; server version = %d, client version = %d"),
1144- N_("Drizzle client ran out of memory"),
1145- N_("Wrong host info"),
1146- N_("Localhost via UNIX socket"),
1147- N_("%-.100s via TCP/IP"),
1148- N_("Error in server handshake"),
1149- N_("Lost connection to Drizzle server during query"),
1150- N_("Commands out of sync; you can't run this command now"),
1151- N_("Named pipe: %-.32s"),
1152- N_("Can't wait for named pipe to host: %-.64s pipe: %-.32s (%lu)"),
1153- N_("Can't open named pipe to host: %-.64s pipe: %-.32s (%lu)"),
1154- N_("Can't set state of named pipe to host: %-.64s pipe: %-.32s (%lu)"),
1155- N_("Can't initialize character set %-.32s (path: %-.100s)"),
1156- N_("Got packet bigger than 'max_allowed_packet' bytes"),
1157- N_("Embedded server"),
1158- N_("Error on SHOW SLAVE STATUS:"),
1159- N_("Error on SHOW SLAVE HOSTS:"),
1160- N_("Error connecting to slave:"),
1161- N_("Error connecting to master:"),
1162- N_("SSL connection error"),
1163- N_("Malformed packet"),
1164- N_("(unused error message)"),
1165- N_("Invalid use of null pointer"),
1166- N_("Statement not prepared"),
1167- N_("No data supplied for parameters in prepared statement"),
1168- N_("Data truncated"),
1169- N_("No parameters exist in the statement"),
1170- N_("Invalid parameter number"),
1171- N_("Can't send long data for non-string/non-binary data types "
1172- "(parameter: %d)"),
1173- N_("Using unsupported buffer type: %d (parameter: %d)"),
1174- N_("Shared memory: %-.100s"),
1175- N_("(unused error message)"),
1176- N_("(unused error message)"),
1177- N_("(unused error message)"),
1178- N_("(unused error message)"),
1179- N_("(unused error message)"),
1180- N_("(unused error message)"),
1181- N_("(unused error message)"),
1182- N_("(unused error message)"),
1183- N_("(unused error message)"),
1184- N_("Wrong or unknown protocol"),
1185- N_("Invalid connection handle"),
1186- N_("Connection using old (pre-4.1.1) authentication protocol refused "
1187- "(client option 'secure_auth' enabled)"),
1188- N_("Row retrieval was canceled by drizzle_stmt_close() call"),
1189- N_("Attempt to read column without prior row fetch"),
1190- N_("Prepared statement contains no metadata"),
1191- N_("Attempt to read a row while there is no result set associated with "
1192- "the statement"),
1193- N_("This feature is not implemented yet"),
1194- N_("Lost connection to Drizzle server while waiting for initial "
1195- "communication packet, system error: %d"),
1196- N_("Lost connection to Drizzle server while reading initial communication "
1197- "packet, system error: %d"),
1198- N_("Lost connection to Drizzle server while sending authentication "
1199- "information, system error: %d"),
1200- N_("Lost connection to Drizzle server while reading authorization "
1201- "information, system error: %d"),
1202- N_("Lost connection to Drizzle server while setting initial database, "
1203- "system error: %d"),
1204- N_("Statement closed indirectly because of a preceding %s() call"),
1205-/* CR_NET_UNCOMPRESS_ERROR 08S01 */
1206- N_("Couldn't uncompress communication packet"),
1207-/* CR_NET_READ_ERROR 08S01 */
1208- N_("Got an error reading communication packets"),
1209-/* CR_NET_READ_INTERRUPTED 08S01 */
1210- N_("Got timeout reading communication packets"),
1211-/* CR_NET_ERROR_ON_WRITE 08S01 */
1212- N_("Got an error writing communication packets"),
1213-/* CR_NET_WRITE_INTERRUPTED 08S01 */
1214- N_("Got timeout writing communication packets"),
1215- ""
1216-};
1217-
1218-
1219-const char *
1220-drizzleclient_get_client_error(unsigned int err_index)
1221-{
1222- return _(client_errors[err_index]);
1223-}
1224-
1225 } /* namespace drizzle_protocol */
1226
1227=== modified file 'plugin/drizzle_protocol/errmsg.h'
1228--- plugin/drizzle_protocol/errmsg.h 2010-03-04 18:06:27 +0000
1229+++ plugin/drizzle_protocol/errmsg.h 2010-10-06 01:14:00 +0000
1230@@ -23,86 +23,6 @@
1231 namespace drizzle_protocol
1232 {
1233
1234-/* Error messages for MySQL clients */
1235-/* (Error messages for the daemon are in sql/share/errmsg.txt) */
1236-
1237-const char * drizzleclient_get_client_error(unsigned int err_index);
1238-
1239-#define CR_MIN_ERROR 2000 /* For easier client code */
1240-#define CR_MAX_ERROR 2999
1241-#if !defined(ER)
1242-#define ER(X) drizzleclient_get_client_error((X)-CR_MIN_ERROR)
1243-#endif
1244-#define CLIENT_ERRMAP 2 /* Errormap used by my_error() */
1245-
1246-/* Do not add error numbers before CR_ERROR_FIRST. */
1247-/* If necessary to add lower numbers, change CR_ERROR_FIRST accordingly. */
1248-enum CR_CLIENT_ERRORS {
1249- CR_ERROR_FIRST =2000, /*Copy first error nr.*/
1250- CR_UNKNOWN_ERROR =2000,
1251- CR_SOCKET_CREATE_ERROR =2001,
1252- CR_CONNECTION_ERROR =2002,
1253- CR_CONN_HOST_ERROR =2003,
1254- CR_IPSOCK_ERROR =2004,
1255- CR_UNKNOWN_HOST =2005,
1256- CR_SERVER_GONE_ERROR =2006,
1257- CR_VERSION_ERROR =2007,
1258- CR_OUT_OF_MEMORY =2008,
1259- CR_WRONG_HOST_INFO =2009,
1260- CR_LOCALHOST_CONNECTION =2010,
1261- CR_TCP_CONNECTION =2011,
1262- CR_SERVER_HANDSHAKE_ERR =2012,
1263- CR_SERVER_LOST =2013,
1264- CR_COMMANDS_OUT_OF_SYNC =2014,
1265- CR_NAMEDPIPE_CONNECTION =2015,
1266- CR_NAMEDPIPEWAIT_ERROR =2016,
1267- CR_NAMEDPIPEOPEN_ERROR =2017,
1268- CR_NAMEDPIPESETSTATE_ERROR =2018,
1269- CR_CANT_READ_CHARSET =2019,
1270- CR_NET_PACKET_TOO_LARGE =2020,
1271- CR_EMBEDDED_CONNECTION =2021,
1272- CR_PROBE_SLAVE_STATUS =2022,
1273- CR_PROBE_SLAVE_HOSTS =2023,
1274- CR_PROBE_SLAVE_CONNECT =2024,
1275- CR_PROBE_MASTER_CONNECT =2025,
1276- CR_SSL_CONNECTION_ERROR =2026,
1277- CR_MALFORMED_PACKET =2027,
1278-
1279- CR_NULL_POINTER =2029,
1280- CR_NO_PREPARE_STMT =2030,
1281- CR_PARAMS_NOT_BOUND =2031,
1282- CR_DATA_TRUNCATED =2032,
1283- CR_NO_PARAMETERS_EXISTS =2033,
1284- CR_INVALID_PARAMETER_NO =2034,
1285- CR_INVALID_BUFFER_USE =2035,
1286- CR_UNSUPPORTED_PARAM_TYPE =2036,
1287-
1288- CR_CONN_UNKNOW_PROTOCOL =2047,
1289- CR_INVALID_CONN_HANDLE =2048,
1290- CR_SECURE_AUTH =2049,
1291- CR_FETCH_CANCELED =2050,
1292- CR_NO_DATA =2051,
1293- CR_NO_STMT_METADATA =2052,
1294- CR_NO_RESULT_SET =2053,
1295- CR_NOT_IMPLEMENTED =2054,
1296- CR_SERVER_LOST_INITIAL_COMM_WAIT =2055,
1297- CR_SERVER_LOST_INITIAL_COMM_READ =2056,
1298- CR_SERVER_LOST_SEND_AUTH =2057,
1299- CR_SERVER_LOST_READ_AUTH =2058,
1300- CR_SERVER_LOST_SETTING_DB =2059,
1301-
1302- CR_STMT_CLOSED =2060,
1303-
1304- CR_NET_UNCOMPRESS_ERROR= 2061,
1305- CR_NET_READ_ERROR= 2062,
1306- CR_NET_READ_INTERRUPTED= 2063,
1307- CR_NET_ERROR_ON_WRITE= 2064,
1308- CR_NET_WRITE_INTERRUPTED= 2065,
1309-
1310- /* Add error numbers before CR_ERROR_LAST and change it accordingly. */
1311- CR_ERROR_LAST =2065 /*Copy last error nr:*/
1312-};
1313-
1314 } /* namespace drizzle_protocol */
1315
1316 #endif /* PLUGIN_DRIZZLE_PROTOCOL_ERRMSG_H */
1317
1318=== removed file 'plugin/drizzle_protocol/net_serv.cc'
1319--- plugin/drizzle_protocol/net_serv.cc 2010-05-19 01:22:29 +0000
1320+++ plugin/drizzle_protocol/net_serv.cc 1970-01-01 00:00:00 +0000
1321@@ -1,896 +0,0 @@
1322-/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1323- * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1324- *
1325- * Copyright (C) 2008 Sun Microsystems, Inc.
1326- *
1327- * This program is free software; you can redistribute it and/or modify
1328- * it under the terms of the GNU General Public License as published by
1329- * the Free Software Foundation; either version 2 of the License, or
1330- * (at your option) any later version.
1331- *
1332- * This program is distributed in the hope that it will be useful,
1333- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1334- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1335- * GNU General Public License for more details.
1336- *
1337- * You should have received a copy of the GNU General Public License
1338- * along with this program; if not, write to the Free Software
1339- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1340- */
1341-
1342-#include "config.h"
1343-#include <drizzled/session.h>
1344-
1345-#include <assert.h>
1346-#include <stdio.h>
1347-#include <stdlib.h>
1348-#include <string.h>
1349-#include <signal.h>
1350-#include <errno.h>
1351-#include <sys/socket.h>
1352-#include <sys/poll.h>
1353-#include <zlib.h>
1354-#include <algorithm>
1355-
1356-#include "errmsg.h"
1357-#include "vio.h"
1358-#include "net_serv.h"
1359-
1360-using namespace std;
1361-
1362-namespace drizzle_protocol
1363-{
1364-
1365-/*
1366- The following handles the differences when this is linked between the
1367- client and the server.
1368-
1369- This gives an error if a too big packet is found
1370- The server can change this with the -O switch, but because the client
1371- can't normally do this the client should have a bigger max_allowed_packet.
1372-*/
1373-
1374- /* Constants when using compression */
1375-#define NET_HEADER_SIZE 4 /* standard header size */
1376-#define COMP_HEADER_SIZE 3 /* compression header extra size */
1377-
1378-#define MAX_PACKET_LENGTH (256L*256L*256L-1)
1379-const char *not_error_sqlstate= "00000";
1380-
1381-static bool net_write_buff(NET *net, const unsigned char *packet, uint32_t len);
1382-static int drizzleclient_net_real_write(NET *net, const unsigned char *packet, size_t len);
1383-
1384-/** Init with packet info. */
1385-
1386-bool drizzleclient_net_init(NET *net, Vio* vio, uint32_t buffer_length)
1387-{
1388- net->vio = vio;
1389- net->max_packet= (uint32_t) buffer_length;
1390- net->max_packet_size= max(buffer_length,
1391- drizzled::global_system_variables.max_allowed_packet);
1392-
1393- if (!(net->buff=(unsigned char*) malloc((size_t) net->max_packet+
1394- NET_HEADER_SIZE + COMP_HEADER_SIZE)))
1395- return(1);
1396- net->buff_end=net->buff+net->max_packet;
1397- net->error=0; net->return_status=0;
1398- net->pkt_nr=net->compress_pkt_nr=0;
1399- net->write_pos=net->read_pos = net->buff;
1400- net->last_error[0]=0;
1401- net->compress=0; net->reading_or_writing=0;
1402- net->where_b = net->remain_in_buf=0;
1403- net->last_errno=0;
1404- net->unused= 0;
1405-
1406- if (vio != 0) /* If real connection */
1407- {
1408- net->fd = drizzleclient_vio_fd(vio); /* For perl DBI/DBD */
1409- drizzleclient_vio_fastsend(vio);
1410- }
1411- return(0);
1412-}
1413-
1414-bool drizzleclient_net_init_sock(NET * net, int sock, int flags,
1415- uint32_t buffer_length)
1416-{
1417-
1418- Vio *drizzleclient_vio_tmp= drizzleclient_vio_new(sock, VIO_TYPE_TCPIP, flags);
1419- if (drizzleclient_vio_tmp == NULL)
1420- return true;
1421- else
1422- if (drizzleclient_net_init(net, drizzleclient_vio_tmp, buffer_length))
1423- {
1424- /* Only delete the temporary vio if we didn't already attach it to the
1425- * NET object.
1426- */
1427- if (drizzleclient_vio_tmp && (net->vio != drizzleclient_vio_tmp))
1428- drizzleclient_vio_delete(drizzleclient_vio_tmp);
1429- else
1430- {
1431- (void) shutdown(sock, SHUT_RDWR);
1432- (void) close(sock);
1433- }
1434- return true;
1435- }
1436- return false;
1437-}
1438-
1439-void drizzleclient_net_end(NET *net)
1440-{
1441- if (net->buff != NULL)
1442- free(net->buff);
1443- net->buff= NULL;
1444- return;
1445-}
1446-
1447-void drizzleclient_net_close(NET *net)
1448-{
1449- if (net->vio != NULL)
1450- {
1451- drizzleclient_vio_delete(net->vio);
1452- net->vio= 0;
1453- }
1454-}
1455-
1456-bool drizzleclient_net_peer_addr(NET *net, char *buf, uint16_t *port, size_t buflen)
1457-{
1458- return drizzleclient_vio_peer_addr(net->vio, buf, port, buflen);
1459-}
1460-
1461-void drizzleclient_net_keepalive(NET *net, bool flag)
1462-{
1463- drizzleclient_vio_keepalive(net->vio, flag);
1464-}
1465-
1466-int drizzleclient_net_get_sd(NET *net)
1467-{
1468- return net->vio->sd;
1469-}
1470-
1471-bool drizzleclient_net_more_data(NET *net)
1472-{
1473- return (net->vio == 0 || net->vio->read_pos < net->vio->read_end);
1474-}
1475-
1476-/** Realloc the packet buffer. */
1477-
1478-static bool drizzleclient_net_realloc(NET *net, size_t length)
1479-{
1480- unsigned char *buff;
1481- size_t pkt_length;
1482-
1483- if (length >= net->max_packet_size)
1484- {
1485- /* @todo: 1 and 2 codes are identical. */
1486- net->error= 1;
1487- net->last_errno= CR_NET_PACKET_TOO_LARGE;
1488- return(1);
1489- }
1490- pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1);
1491- /*
1492- We must allocate some extra bytes for the end 0 and to be able to
1493- read big compressed blocks
1494- */
1495- if (!(buff= (unsigned char*) realloc((char*) net->buff, pkt_length +
1496- NET_HEADER_SIZE + COMP_HEADER_SIZE)))
1497- {
1498- /* @todo: 1 and 2 codes are identical. */
1499- net->error= 1;
1500- net->last_errno= CR_OUT_OF_MEMORY;
1501- /* In the server the error is reported by MY_WME flag. */
1502- return(1);
1503- }
1504- net->buff=net->write_pos=buff;
1505- net->buff_end=buff+(net->max_packet= (uint32_t) pkt_length);
1506- return(0);
1507-}
1508-
1509-
1510-/**
1511- Check if there is any data to be read from the socket.
1512-
1513- @param sd socket descriptor
1514-
1515- @retval
1516- 0 No data to read
1517- @retval
1518- 1 Data or EOF to read
1519- @retval
1520- -1 Don't know if data is ready or not
1521-*/
1522-
1523-static bool net_data_is_ready(int sd)
1524-{
1525- struct pollfd ufds;
1526- int res;
1527-
1528- ufds.fd= sd;
1529- ufds.events= POLLIN | POLLPRI;
1530- if (!(res= poll(&ufds, 1, 0)))
1531- return 0;
1532- if (res < 0 || !(ufds.revents & (POLLIN | POLLPRI)))
1533- return 0;
1534- return 1;
1535-}
1536-
1537-/**
1538- Remove unwanted characters from connection
1539- and check if disconnected.
1540-
1541- Read from socket until there is nothing more to read. Discard
1542- what is read.
1543-
1544- If there is anything when to read 'drizzleclient_net_clear' is called this
1545- normally indicates an error in the protocol.
1546-
1547- When connection is properly closed (for TCP it means with
1548- a FIN packet), then select() considers a socket "ready to read",
1549- in the sense that there's EOF to read, but read() returns 0.
1550-
1551- @param net NET handler
1552- @param clear_buffer if <> 0, then clear all data from comm buff
1553-*/
1554-
1555-void drizzleclient_net_clear(NET *net, bool clear_buffer)
1556-{
1557- if (clear_buffer)
1558- {
1559- while (net_data_is_ready(net->vio->sd) > 0)
1560- {
1561- /* The socket is ready */
1562- if (drizzleclient_vio_read(net->vio, net->buff,
1563- (size_t) net->max_packet) <= 0)
1564- {
1565- net->error= 2;
1566- break;
1567- }
1568- }
1569- }
1570- net->pkt_nr=net->compress_pkt_nr=0; /* Ready for new command */
1571- net->write_pos=net->buff;
1572- return;
1573-}
1574-
1575-
1576-/** Flush write_buffer if not empty. */
1577-
1578-bool drizzleclient_net_flush(NET *net)
1579-{
1580- bool error= 0;
1581- if (net->buff != net->write_pos)
1582- {
1583- error=drizzleclient_net_real_write(net, net->buff,
1584- (size_t) (net->write_pos - net->buff)) ? 1 : 0;
1585- net->write_pos=net->buff;
1586- }
1587- /* Sync packet number if using compression */
1588- if (net->compress)
1589- net->pkt_nr=net->compress_pkt_nr;
1590- return(error);
1591-}
1592-
1593-
1594-/*****************************************************************************
1595- ** Write something to server/client buffer
1596- *****************************************************************************/
1597-
1598-/**
1599- Write a logical packet with packet header.
1600-
1601- Format: Packet length (3 bytes), packet number(1 byte)
1602- When compression is used a 3 byte compression length is added
1603-
1604- @note
1605- If compression is used the original package is modified!
1606-*/
1607-
1608-bool
1609-drizzleclient_net_write(NET *net,const unsigned char *packet,size_t len)
1610-{
1611- unsigned char buff[NET_HEADER_SIZE];
1612- if (unlikely(!net->vio)) /* nowhere to write */
1613- return 0;
1614- /*
1615- Big packets are handled by splitting them in packets of MAX_PACKET_LENGTH
1616- length. The last packet is always a packet that is < MAX_PACKET_LENGTH.
1617- (The last packet may even have a length of 0)
1618- */
1619- while (len >= MAX_PACKET_LENGTH)
1620- {
1621- const uint32_t z_size = MAX_PACKET_LENGTH;
1622- int3store(buff, z_size);
1623- buff[3]= (unsigned char) net->pkt_nr++;
1624- if (net_write_buff(net, buff, NET_HEADER_SIZE) ||
1625- net_write_buff(net, packet, z_size))
1626- return 1;
1627- packet += z_size;
1628- len-= z_size;
1629- }
1630- /* Write last packet */
1631- int3store(buff,len);
1632- buff[3]= (unsigned char) net->pkt_nr++;
1633- if (net_write_buff(net, buff, NET_HEADER_SIZE))
1634- return 1;
1635- return net_write_buff(net,packet,len) ? 1 : 0;
1636-}
1637-
1638-/**
1639- Send a command to the server.
1640-
1641- The reason for having both header and packet is so that libdrizzle
1642- can easy add a header to a special command (like prepared statements)
1643- without having to re-alloc the string.
1644-
1645- As the command is part of the first data packet, we have to do some data
1646- juggling to put the command in there, without having to create a new
1647- packet.
1648-
1649- This function will split big packets into sub-packets if needed.
1650- (Each sub packet can only be 2^24 bytes)
1651-
1652- @param net NET handler
1653- @param command Command in MySQL server (enum enum_server_command)
1654- @param header Header to write after command
1655- @param head_len Length of header
1656- @param packet Query or parameter to query
1657- @param len Length of packet
1658-
1659- @retval
1660- 0 ok
1661- @retval
1662- 1 error
1663-*/
1664-
1665-bool
1666-drizzleclient_net_write_command(NET *net,unsigned char command,
1667- const unsigned char *header, size_t head_len,
1668- const unsigned char *packet, size_t len)
1669-{
1670- uint32_t length=len+1+head_len; /* 1 extra byte for command */
1671- unsigned char buff[NET_HEADER_SIZE+1];
1672- uint32_t header_size=NET_HEADER_SIZE+1;
1673-
1674- buff[4]=command; /* For first packet */
1675-
1676- if (length >= MAX_PACKET_LENGTH)
1677- {
1678- /* Take into account that we have the command in the first header */
1679- len= MAX_PACKET_LENGTH - 1 - head_len;
1680- do
1681- {
1682- int3store(buff, MAX_PACKET_LENGTH);
1683- buff[3]= (unsigned char) net->pkt_nr++;
1684- if (net_write_buff(net, buff, header_size) ||
1685- net_write_buff(net, header, head_len) ||
1686- net_write_buff(net, packet, len))
1687- return(1);
1688- packet+= len;
1689- length-= MAX_PACKET_LENGTH;
1690- len= MAX_PACKET_LENGTH;
1691- head_len= 0;
1692- header_size= NET_HEADER_SIZE;
1693- } while (length >= MAX_PACKET_LENGTH);
1694- len=length; /* Data left to be written */
1695- }
1696- int3store(buff,length);
1697- buff[3]= (unsigned char) net->pkt_nr++;
1698- return((net_write_buff(net, buff, header_size) ||
1699- (head_len && net_write_buff(net, header, head_len)) ||
1700- net_write_buff(net, packet, len) || drizzleclient_net_flush(net)) ? 1 : 0 );
1701-}
1702-
1703-/**
1704- Caching the data in a local buffer before sending it.
1705-
1706- Fill up net->buffer and send it to the client when full.
1707-
1708- If the rest of the to-be-sent-packet is bigger than buffer,
1709- send it in one big block (to avoid copying to internal buffer).
1710- If not, copy the rest of the data to the buffer and return without
1711- sending data.
1712-
1713- @param net Network handler
1714- @param packet Packet to send
1715- @param len Length of packet
1716-
1717- @note
1718- The cached buffer can be sent as it is with 'drizzleclient_net_flush()'.
1719- In this code we have to be careful to not send a packet longer than
1720- MAX_PACKET_LENGTH to drizzleclient_net_real_write() if we are using the compressed
1721- protocol as we store the length of the compressed packet in 3 bytes.
1722-
1723- @retval
1724- 0 ok
1725- @retval
1726- 1
1727-*/
1728-
1729-static bool
1730-net_write_buff(NET *net, const unsigned char *packet, uint32_t len)
1731-{
1732- uint32_t left_length;
1733- if (net->compress && net->max_packet > MAX_PACKET_LENGTH)
1734- left_length= MAX_PACKET_LENGTH - (net->write_pos - net->buff);
1735- else
1736- left_length= (uint32_t) (net->buff_end - net->write_pos);
1737-
1738- if (len > left_length)
1739- {
1740- if (net->write_pos != net->buff)
1741- {
1742- /* Fill up already used packet and write it */
1743- memcpy(net->write_pos,packet,left_length);
1744- if (drizzleclient_net_real_write(net, net->buff,
1745- (size_t) (net->write_pos - net->buff) + left_length))
1746- return 1;
1747- net->write_pos= net->buff;
1748- packet+= left_length;
1749- len-= left_length;
1750- }
1751- if (net->compress)
1752- {
1753- /*
1754- We can't have bigger packets than 16M with compression
1755- Because the uncompressed length is stored in 3 bytes
1756- */
1757- left_length= MAX_PACKET_LENGTH;
1758- while (len > left_length)
1759- {
1760- if (drizzleclient_net_real_write(net, packet, left_length))
1761- return 1;
1762- packet+= left_length;
1763- len-= left_length;
1764- }
1765- }
1766- if (len > net->max_packet)
1767- return drizzleclient_net_real_write(net, packet, len) ? 1 : 0;
1768- /* Send out rest of the blocks as full sized blocks */
1769- }
1770- memcpy(net->write_pos,packet,len);
1771- net->write_pos+= len;
1772- return 0;
1773-}
1774-
1775-
1776-/**
1777- Read and write one packet using timeouts.
1778- If needed, the packet is compressed before sending.
1779-
1780- @todo
1781- - TODO is it needed to set this variable if we have no socket
1782-*/
1783-
1784-/*
1785- TODO: rewrite this in a manner to do non-block writes. If a write can not be made, and we are
1786- in the server, yield to another process and come back later.
1787-*/
1788-static int
1789-drizzleclient_net_real_write(NET *net, const unsigned char *packet, size_t len)
1790-{
1791- size_t length;
1792- const unsigned char *pos, *end;
1793- uint32_t retry_count= 0;
1794-
1795- /* Backup of the original SO_RCVTIMEO timeout */
1796-
1797- if (net->error == 2)
1798- return(-1); /* socket can't be used */
1799-
1800- net->reading_or_writing=2;
1801- if (net->compress)
1802- {
1803- size_t complen;
1804- unsigned char *b;
1805- const uint32_t header_length=NET_HEADER_SIZE+COMP_HEADER_SIZE;
1806- if (!(b= (unsigned char*) malloc(len + NET_HEADER_SIZE +
1807- COMP_HEADER_SIZE)))
1808- {
1809- net->error= 2;
1810- net->last_errno= CR_OUT_OF_MEMORY;
1811- /* In the server, the error is reported by MY_WME flag. */
1812- net->reading_or_writing= 0;
1813- return(1);
1814- }
1815- memcpy(b+header_length,packet,len);
1816-
1817- complen= len * 120 / 100 + 12;
1818- unsigned char * compbuf= (unsigned char *) malloc(complen);
1819- if (compbuf != NULL)
1820- {
1821- uLongf tmp_complen= complen;
1822- int res= compress((Bytef*) compbuf, &tmp_complen,
1823- (Bytef*) (b+header_length),
1824- len);
1825- complen= tmp_complen;
1826-
1827- free(compbuf);
1828-
1829- if ((res != Z_OK) || (complen >= len))
1830- complen= 0;
1831- else
1832- {
1833- size_t tmplen= complen;
1834- complen= len;
1835- len= tmplen;
1836- }
1837- }
1838- else
1839- {
1840- complen=0;
1841- }
1842- int3store(&b[NET_HEADER_SIZE],complen);
1843- int3store(b,len);
1844- b[3]=(unsigned char) (net->compress_pkt_nr++);
1845- len+= header_length;
1846- packet= b;
1847- }
1848-
1849- pos= packet;
1850- end=pos+len;
1851- /* Loop until we have read everything */
1852- while (pos != end)
1853- {
1854- assert(pos);
1855- if ((long) (length= drizzleclient_vio_write(net->vio, pos, (size_t) (end-pos))) <= 0)
1856- {
1857- /*
1858- * We could end up here with net->vio == NULL
1859- * See LP bug#436685
1860- * If that is the case, we exit the while loop
1861- */
1862- if (net->vio == NULL)
1863- break;
1864-
1865- const bool interrupted= drizzleclient_vio_should_retry(net->vio);
1866- /*
1867- If we read 0, or we were interrupted this means that
1868- we need to switch to blocking mode and wait until the timeout
1869- on the socket kicks in.
1870- */
1871- if ((interrupted || length == 0))
1872- {
1873- bool old_mode;
1874-
1875- while (drizzleclient_vio_blocking(net->vio, true, &old_mode) < 0)
1876- {
1877- if (drizzleclient_vio_should_retry(net->vio) && retry_count++ < net->retry_count)
1878- continue;
1879- net->error= 2; /* Close socket */
1880- net->last_errno= CR_NET_PACKET_TOO_LARGE;
1881- goto end;
1882- }
1883- retry_count=0;
1884- continue;
1885- }
1886- else
1887- {
1888- if (retry_count++ < net->retry_count)
1889- continue;
1890- }
1891-
1892- if (drizzleclient_vio_errno(net->vio) == EINTR)
1893- {
1894- continue;
1895- }
1896- net->error= 2; /* Close socket */
1897- net->last_errno= (interrupted ? CR_NET_WRITE_INTERRUPTED :
1898- CR_NET_ERROR_ON_WRITE);
1899- break;
1900- }
1901- pos+=length;
1902- current_session->status_var.bytes_sent+= length;
1903- }
1904-end:
1905- if ((net->compress) && (packet != NULL))
1906- free((char*) packet);
1907- net->reading_or_writing=0;
1908-
1909- return(((int) (pos != end)));
1910-}
1911-
1912-
1913-/**
1914- Reads one packet to net->buff + net->where_b.
1915- Long packets are handled by drizzleclient_net_read().
1916- This function reallocates the net->buff buffer if necessary.
1917-
1918- @return
1919- Returns length of packet.
1920-*/
1921-
1922-static uint32_t
1923-my_real_read(NET *net, size_t *complen)
1924-{
1925- unsigned char *pos;
1926- size_t length;
1927- uint32_t i,retry_count=0;
1928- size_t len=packet_error;
1929- uint32_t remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE :
1930- NET_HEADER_SIZE);
1931-
1932- *complen = 0;
1933-
1934- net->reading_or_writing= 1;
1935- /* Read timeout is set in drizzleclient_net_set_read_timeout */
1936-
1937- pos = net->buff + net->where_b; /* net->packet -4 */
1938-
1939- for (i= 0; i < 2 ; i++)
1940- {
1941- while (remain > 0)
1942- {
1943- /* First read is done with non blocking mode */
1944- if ((long) (length= drizzleclient_vio_read(net->vio, pos, remain)) <= 0L)
1945- {
1946- if (net->vio == NULL)
1947- goto end;
1948-
1949- const bool interrupted = drizzleclient_vio_should_retry(net->vio);
1950-
1951- if (interrupted)
1952- { /* Probably in MIT threads */
1953- if (retry_count++ < net->retry_count)
1954- continue;
1955- }
1956- if (drizzleclient_vio_errno(net->vio) == EINTR)
1957- {
1958- continue;
1959- }
1960- len= packet_error;
1961- net->error= 2; /* Close socket */
1962- net->last_errno= (drizzleclient_vio_was_interrupted(net->vio) ?
1963- CR_NET_READ_INTERRUPTED :
1964- CR_NET_READ_ERROR);
1965- ER(net->last_errno);
1966- goto end;
1967- }
1968- remain -= (uint32_t) length;
1969- pos+= length;
1970- current_session->status_var.bytes_received+= length;
1971- }
1972- if (i == 0)
1973- { /* First parts is packet length */
1974- uint32_t helping;
1975-
1976- if (net->buff[net->where_b + 3] != (unsigned char) net->pkt_nr)
1977- {
1978- len= packet_error;
1979- /* Not a NET error on the client. XXX: why? */
1980- goto end;
1981- }
1982- net->compress_pkt_nr= ++net->pkt_nr;
1983- if (net->compress)
1984- {
1985- /*
1986- If the packet is compressed then complen > 0 and contains the
1987- number of bytes in the uncompressed packet
1988- */
1989- *complen=uint3korr(&(net->buff[net->where_b + NET_HEADER_SIZE]));
1990- }
1991-
1992- len=uint3korr(net->buff+net->where_b);
1993- if (!len) /* End of big multi-packet */
1994- goto end;
1995- helping = max(len,*complen) + net->where_b;
1996- /* The necessary size of net->buff */
1997- if (helping >= net->max_packet)
1998- {
1999- if (drizzleclient_net_realloc(net,helping))
2000- {
2001- len= packet_error; /* Return error and close connection */
2002- goto end;
2003- }
2004- }
2005- pos=net->buff + net->where_b;
2006- remain = (uint32_t) len;
2007- }
2008- }
2009-
2010-end:
2011- net->reading_or_writing= 0;
2012-
2013- return(len);
2014-}
2015-
2016-
2017-/**
2018- Read a packet from the client/server and return it without the internal
2019- package header.
2020-
2021- If the packet is the first packet of a multi-packet packet
2022- (which is indicated by the length of the packet = 0xffffff) then
2023- all sub packets are read and concatenated.
2024-
2025- If the packet was compressed, its uncompressed and the length of the
2026- uncompressed packet is returned.
2027-
2028- @return
2029- The function returns the length of the found packet or packet_error.
2030- net->read_pos points to the read data.
2031-*/
2032-
2033-uint32_t
2034-drizzleclient_net_read(NET *net)
2035-{
2036- size_t len, complen;
2037-
2038- if (!net->compress)
2039- {
2040- len = my_real_read(net,&complen);
2041- if (len == MAX_PACKET_LENGTH)
2042- {
2043- /* First packet of a multi-packet. Concatenate the packets */
2044- uint32_t save_pos = net->where_b;
2045- size_t total_length= 0;
2046- do
2047- {
2048- net->where_b += len;
2049- total_length += len;
2050- len = my_real_read(net,&complen);
2051- } while (len == MAX_PACKET_LENGTH);
2052- if (len != packet_error)
2053- len+= total_length;
2054- net->where_b = save_pos;
2055- }
2056- net->read_pos = net->buff + net->where_b;
2057- if (len != packet_error)
2058- net->read_pos[len]=0; /* Safeguard for drizzleclient_use_result */
2059- return len;
2060- }
2061- else
2062- {
2063- /* We are using the compressed protocol */
2064-
2065- uint32_t buf_length;
2066- uint32_t start_of_packet;
2067- uint32_t first_packet_offset;
2068- uint32_t read_length, multi_byte_packet=0;
2069-
2070- if (net->remain_in_buf)
2071- {
2072- buf_length= net->buf_length; /* Data left in old packet */
2073- first_packet_offset= start_of_packet= (net->buf_length -
2074- net->remain_in_buf);
2075- /* Restore the character that was overwritten by the end 0 */
2076- net->buff[start_of_packet]= net->save_char;
2077- }
2078- else
2079- {
2080- /* reuse buffer, as there is nothing in it that we need */
2081- buf_length= start_of_packet= first_packet_offset= 0;
2082- }
2083- for (;;)
2084- {
2085- uint32_t packet_len;
2086-
2087- if (buf_length - start_of_packet >= NET_HEADER_SIZE)
2088- {
2089- read_length = uint3korr(net->buff+start_of_packet);
2090- if (!read_length)
2091- {
2092- /* End of multi-byte packet */
2093- start_of_packet += NET_HEADER_SIZE;
2094- break;
2095- }
2096- if (read_length + NET_HEADER_SIZE <= buf_length - start_of_packet)
2097- {
2098- if (multi_byte_packet)
2099- {
2100- /* Remove packet header for second packet */
2101- memmove(net->buff + first_packet_offset + start_of_packet,
2102- net->buff + first_packet_offset + start_of_packet +
2103- NET_HEADER_SIZE,
2104- buf_length - start_of_packet);
2105- start_of_packet += read_length;
2106- buf_length -= NET_HEADER_SIZE;
2107- }
2108- else
2109- start_of_packet+= read_length + NET_HEADER_SIZE;
2110-
2111- if (read_length != MAX_PACKET_LENGTH) /* last package */
2112- {
2113- multi_byte_packet= 0; /* No last zero len packet */
2114- break;
2115- }
2116- multi_byte_packet= NET_HEADER_SIZE;
2117- /* Move data down to read next data packet after current one */
2118- if (first_packet_offset)
2119- {
2120- memmove(net->buff,net->buff+first_packet_offset,
2121- buf_length-first_packet_offset);
2122- buf_length-=first_packet_offset;
2123- start_of_packet -= first_packet_offset;
2124- first_packet_offset=0;
2125- }
2126- continue;
2127- }
2128- }
2129- /* Move data down to read next data packet after current one */
2130- if (first_packet_offset)
2131- {
2132- memmove(net->buff,net->buff+first_packet_offset,
2133- buf_length-first_packet_offset);
2134- buf_length-=first_packet_offset;
2135- start_of_packet -= first_packet_offset;
2136- first_packet_offset=0;
2137- }
2138-
2139- net->where_b=buf_length;
2140- if ((packet_len = my_real_read(net,&complen)) == packet_error)
2141- return packet_error;
2142-
2143- if (complen)
2144- {
2145- unsigned char * compbuf= (unsigned char *) malloc(complen);
2146- if (compbuf != NULL)
2147- {
2148- uLongf tmp_complen= complen;
2149- int error= uncompress((Bytef*) compbuf, &tmp_complen,
2150- (Bytef*) (net->buff + net->where_b),
2151- (uLong)packet_len);
2152- complen= tmp_complen;
2153-
2154- if (error != Z_OK)
2155- {
2156- net->error= 2; /* caller will close socket */
2157- net->last_errno= CR_NET_UNCOMPRESS_ERROR;
2158- }
2159- else
2160- {
2161- memcpy((net->buff + net->where_b), compbuf, complen);
2162- }
2163- free(compbuf);
2164- }
2165- }
2166- else
2167- complen= packet_len;
2168-
2169- }
2170- buf_length+= complen;
2171-
2172- net->read_pos= net->buff+ first_packet_offset + NET_HEADER_SIZE;
2173- net->buf_length= buf_length;
2174- net->remain_in_buf= (uint32_t) (buf_length - start_of_packet);
2175- len = ((uint32_t) (start_of_packet - first_packet_offset) - NET_HEADER_SIZE -
2176- multi_byte_packet);
2177- net->save_char= net->read_pos[len]; /* Must be saved */
2178- net->read_pos[len]=0; /* Safeguard for drizzleclient_use_result */
2179- }
2180- return len;
2181- }
2182-
2183-
2184-void drizzleclient_net_set_read_timeout(NET *net, uint32_t timeout)
2185-{
2186- net->read_timeout= timeout;
2187-#ifndef __sun
2188- if (net->vio)
2189- drizzleclient_vio_timeout(net->vio, 0, timeout);
2190-#endif
2191- return;
2192-}
2193-
2194-
2195-void drizzleclient_net_set_write_timeout(NET *net, uint32_t timeout)
2196-{
2197- net->write_timeout= timeout;
2198-#ifndef __sun
2199- if (net->vio)
2200- drizzleclient_vio_timeout(net->vio, 1, timeout);
2201-#endif
2202- return;
2203-}
2204-/**
2205- Clear possible error state of struct NET
2206-
2207- @param net clear the state of the argument
2208-*/
2209-
2210-void drizzleclient_drizzleclient_net_clear_error(NET *net)
2211-{
2212- net->last_errno= 0;
2213- net->last_error[0]= '\0';
2214- strcpy(net->sqlstate, not_error_sqlstate);
2215-}
2216-
2217-} /* namespace drizzle_protocol */
2218
2219=== removed file 'plugin/drizzle_protocol/net_serv.h'
2220--- plugin/drizzle_protocol/net_serv.h 2010-03-04 18:06:27 +0000
2221+++ plugin/drizzle_protocol/net_serv.h 1970-01-01 00:00:00 +0000
2222@@ -1,94 +0,0 @@
2223-/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2224- * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2225- *
2226- * Copyright (C) 2008 Sun Microsystems, Inc.
2227- *
2228- * This program is free software; you can redistribute it and/or modify
2229- * it under the terms of the GNU General Public License as published by
2230- * the Free Software Foundation; version 2 of the License.
2231- *
2232- * This program is distributed in the hope that it will be useful,
2233- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2234- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2235- * GNU General Public License for more details.
2236- *
2237- * You should have received a copy of the GNU General Public License
2238- * along with this program; if not, write to the Free Software
2239- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2240- */
2241-
2242-
2243-#ifndef PLUGIN_DRIZZLE_PROTOCOL_NET_SERV_H
2244-#define PLUGIN_DRIZZLE_PROTOCOL_NET_SERV_H
2245-
2246-#include "vio.h"
2247-
2248-#include <stdint.h>
2249-
2250-namespace drizzle_protocol
2251-{
2252-
2253-#define LIBDRIZZLE_ERRMSG_SIZE 512
2254-#define LIBDRIZZLE_SQLSTATE_LENGTH 5
2255-
2256-typedef struct st_net {
2257- Vio *vio;
2258- unsigned char *buff,*buff_end,*write_pos,*read_pos;
2259- int fd; /* For Perl DBI/dbd */
2260- /*
2261- The following variable is set if we are doing several queries in one
2262- command ( as in LOAD TABLE ... FROM MASTER ),
2263- and do not want to confuse the client with OK at the wrong time
2264- */
2265- unsigned long remain_in_buf,length, buf_length, where_b;
2266- unsigned long max_packet,max_packet_size;
2267- unsigned int pkt_nr,compress_pkt_nr;
2268- unsigned int write_timeout;
2269- unsigned int read_timeout;
2270- unsigned int retry_count;
2271- int fcntl;
2272- unsigned int *return_status;
2273- unsigned char reading_or_writing;
2274- char save_char;
2275- bool compress;
2276- /*
2277- Pointer to query object in query cache, do not equal NULL (0) for
2278- queries in cache that have not stored its results yet
2279- */
2280- /*
2281- Unused, please remove with the next incompatible ABI change.
2282- */
2283- unsigned char *unused;
2284- unsigned int last_errno;
2285- unsigned char error;
2286- /** Client library error message buffer. Actually belongs to struct MYSQL. */
2287- char last_error[LIBDRIZZLE_ERRMSG_SIZE];
2288- /** Client library sqlstate buffer. Set along with the error message. */
2289- char sqlstate[LIBDRIZZLE_SQLSTATE_LENGTH+1];
2290- void *extension;
2291-} NET;
2292-
2293-bool drizzleclient_net_init(NET *net, Vio* vio, uint32_t buffer_length);
2294-void drizzleclient_net_end(NET *net);
2295-void drizzleclient_net_clear(NET *net, bool clear_buffer);
2296-bool drizzleclient_net_flush(NET *net);
2297-bool drizzleclient_net_write(NET *net,const unsigned char *packet, size_t len);
2298-bool drizzleclient_net_write_command(NET *net,unsigned char command,
2299- const unsigned char *header, size_t head_len,
2300- const unsigned char *packet, size_t len);
2301-uint32_t drizzleclient_net_read(NET *net);
2302-void drizzleclient_net_close(NET *net);
2303-bool drizzleclient_net_init_sock(NET * net, int sock, int flags,
2304- uint32_t buffer_length);
2305-bool drizzleclient_net_peer_addr(NET *net, char *buf, uint16_t *port, size_t buflen);
2306-void drizzleclient_net_keepalive(NET *net, bool flag);
2307-int drizzleclient_net_get_sd(NET *net);
2308-bool drizzleclient_net_more_data(NET *net);
2309-
2310-void drizzleclient_net_set_write_timeout(NET *net, uint32_t timeout);
2311-void drizzleclient_net_set_read_timeout(NET *net, uint32_t timeout);
2312-void drizzleclient_drizzleclient_net_clear_error(NET *net);
2313-
2314-} /* namespace drizzle_protocol */
2315-
2316-#endif /* PLUGIN_DRIZZLE_PROTOCOL_NET_SERV_H */
2317
2318=== removed file 'plugin/drizzle_protocol/options.h'
2319--- plugin/drizzle_protocol/options.h 2010-03-04 18:06:27 +0000
2320+++ plugin/drizzle_protocol/options.h 1970-01-01 00:00:00 +0000
2321@@ -1,125 +0,0 @@
2322-/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2323- * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2324- *
2325- * Copyright (C) 2008 Sun Microsystems, Inc.
2326- *
2327- * This program is free software; you can redistribute it and/or modify
2328- * it under the terms of the GNU General Public License as published by
2329- * the Free Software Foundation; version 2 of the License.
2330- *
2331- * This program is distributed in the hope that it will be useful,
2332- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2333- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2334- * GNU General Public License for more details.
2335- *
2336- * You should have received a copy of the GNU General Public License
2337- * along with this program; if not, write to the Free Software
2338- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2339- */
2340-
2341-#ifndef PLUGIN_DRIZZLE_PROTOCOL_OPTIONS_H
2342-#define PLUGIN_DRIZZLE_PROTOCOL_OPTIONS_H
2343-
2344-namespace drizzle_protocol
2345-{
2346-
2347-enum drizzle_option
2348-{
2349- DRIZZLE_OPT_CONNECT_TIMEOUT, DRIZZLE_OPT_COMPRESS, DRIZZLE_OPT_NAMED_PIPE,
2350- DRIZZLE_INIT_COMMAND, DRIZZLE_READ_DEFAULT_FILE, DRIZZLE_READ_DEFAULT_GROUP,
2351- DRIZZLE_OPT_PROTOCOL, DRIZZLE_SHARED_MEMORY_BASE_NAME, DRIZZLE_OPT_READ_TIMEOUT,
2352- DRIZZLE_OPT_WRITE_TIMEOUT, DRIZZLE_OPT_USE_RESULT,
2353- DRIZZLE_OPT_USE_REMOTE_CONNECTION,
2354- DRIZZLE_OPT_GUESS_CONNECTION, DRIZZLE_SET_CLIENT_IP, DRIZZLE_SECURE_AUTH,
2355- DRIZZLE_REPORT_DATA_TRUNCATION, DRIZZLE_OPT_RECONNECT,
2356- DRIZZLE_OPT_SSL_VERIFY_SERVER_CERT
2357-};
2358-
2359-struct st_drizzleclient_options {
2360- unsigned int connect_timeout, read_timeout, write_timeout;
2361- unsigned int port;
2362- unsigned long client_flag;
2363- char *host,*user,*password,*db;
2364- char *my_cnf_file,*my_cnf_group;
2365- char *ssl_key; /* PEM key file */
2366- char *ssl_cert; /* PEM cert file */
2367- char *ssl_ca; /* PEM CA file */
2368- char *ssl_capath; /* PEM directory of CA-s? */
2369- char *ssl_cipher; /* cipher to use */
2370- char *shared_memory_base_name;
2371- unsigned long max_allowed_packet;
2372- bool use_ssl; /* if to use SSL or not */
2373- bool compress,named_pipe;
2374- bool unused1;
2375- bool unused2;
2376- bool unused3;
2377- bool unused4;
2378- enum drizzle_option methods_to_use;
2379- char *client_ip;
2380- /* Refuse client connecting to server if it uses old (pre-4.1.1) protocol */
2381- bool secure_auth;
2382- /* 0 - never report, 1 - always report (default) */
2383- bool report_data_truncation;
2384-
2385- /* function pointers for local infile support */
2386- int (*local_infile_init)(void **, const char *, void *);
2387- int (*local_infile_read)(void *, char *, unsigned int);
2388- void (*local_infile_end)(void *);
2389- int (*local_infile_error)(void *, char *, unsigned int);
2390- void *local_infile_userdata;
2391- void *extension;
2392-};
2393-
2394-
2395-#define CLIENT_NET_READ_TIMEOUT 365*24*3600 /* Timeout on read */
2396-#define CLIENT_NET_WRITE_TIMEOUT 365*24*3600 /* Timeout on write */
2397-
2398-#define CLIENT_LONG_PASSWORD 1 /* new more secure passwords */
2399-#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */
2400-#define CLIENT_LONG_FLAG 4 /* Get all column flags */
2401-#define CLIENT_CONNECT_WITH_DB 8 /* One can specify db on connect */
2402-#define CLIENT_NO_SCHEMA 16 /* Don't allow database.table.column */
2403-#define CLIENT_COMPRESS 32 /* Can use compression protocol */
2404-#define CLIENT_ODBC 64 /* Odbc client */
2405-#define CLIENT_IGNORE_SPACE 256 /* Ignore spaces before '(' */
2406-#define CLIENT_PROTOCOL_MYSQL41 512 /* New 4.1 protocol */
2407-#define CLIENT_SSL 2048 /* Switch to SSL after handshake */
2408-#define CLIENT_IGNORE_SIGPIPE 4096 /* IGNORE sigpipes */
2409-#define CLIENT_RESERVED 16384 /* Old flag for 4.1 protocol */
2410-#define CLIENT_SECURE_CONNECTION 32768 /* New 4.1 authentication */
2411-#define CLIENT_MULTI_STATEMENTS (1UL << 16) /* Enable/disable multi-stmt support */
2412-#define CLIENT_MULTI_RESULTS (1UL << 17) /* Enable/disable multi-results */
2413-
2414-#define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30)
2415-#define CLIENT_REMEMBER_OPTIONS (1UL << 31)
2416-
2417-/* Gather all possible capabilites (flags) supported by the server */
2418-#define CLIENT_ALL_FLAGS (CLIENT_LONG_PASSWORD | \
2419- CLIENT_FOUND_ROWS | \
2420- CLIENT_LONG_FLAG | \
2421- CLIENT_CONNECT_WITH_DB | \
2422- CLIENT_NO_SCHEMA | \
2423- CLIENT_COMPRESS | \
2424- CLIENT_ODBC | \
2425- CLIENT_IGNORE_SPACE | \
2426- CLIENT_SSL | \
2427- CLIENT_IGNORE_SIGPIPE | \
2428- CLIENT_RESERVED | \
2429- CLIENT_SECURE_CONNECTION | \
2430- CLIENT_MULTI_STATEMENTS | \
2431- CLIENT_MULTI_RESULTS | \
2432- CLIENT_SSL_VERIFY_SERVER_CERT | \
2433- CLIENT_REMEMBER_OPTIONS)
2434-
2435-/*
2436- Switch off the flags that are optional and depending on build flags
2437- If any of the optional flags is supported by the build it will be switched
2438- on before sending to the client during the connection handshake.
2439-*/
2440-#define CLIENT_BASIC_FLAGS (((CLIENT_ALL_FLAGS & ~CLIENT_SSL) \
2441- & ~CLIENT_COMPRESS) \
2442- & ~CLIENT_SSL_VERIFY_SERVER_CERT)
2443-
2444-} /* namespace drizzle_protocol */
2445-
2446-#endif /* PLUGIN_DRIZZLE_PROTOCOL_OPTIONS_H */
2447
2448=== removed file 'plugin/drizzle_protocol/pack.cc'
2449--- plugin/drizzle_protocol/pack.cc 2010-03-04 18:06:27 +0000
2450+++ plugin/drizzle_protocol/pack.cc 1970-01-01 00:00:00 +0000
2451@@ -1,132 +0,0 @@
2452-/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2453- * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2454- *
2455- * Copyright (C) 2008 Sun Microsystems, Inc.
2456- *
2457- * This program is free software; you can redistribute it and/or modify
2458- * it under the terms of the GNU General Public License as published by
2459- * the Free Software Foundation; version 2 of the License.
2460- *
2461- * This program is distributed in the hope that it will be useful,
2462- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2463- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2464- * GNU General Public License for more details.
2465- *
2466- * You should have received a copy of the GNU General Public License
2467- * along with this program; if not, write to the Free Software
2468- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2469- */
2470-
2471-#include "config.h"
2472-#include <drizzled/korr.h>
2473-
2474-#include <stdint.h>
2475-
2476-#include "pack.h"
2477-
2478-namespace drizzle_protocol
2479-{
2480-
2481-/* Get the length of next field. Change parameter to point at fieldstart */
2482-uint32_t drizzleclient_net_field_length(unsigned char **packet)
2483-{
2484- register unsigned char *pos= (unsigned char *)*packet;
2485- if (*pos < 251)
2486- {
2487- (*packet)++;
2488- return (uint32_t) *pos;
2489- }
2490- if (*pos == 251)
2491- {
2492- (*packet)++;
2493- return NULL_LENGTH;
2494- }
2495- if (*pos == 252)
2496- {
2497- (*packet)+=3;
2498- return (uint32_t) uint2korr(pos+1);
2499- }
2500- if (*pos == 253)
2501- {
2502- (*packet)+=4;
2503- return (uint32_t) uint3korr(pos+1);
2504- }
2505- (*packet)+=9; /* Must be 254 when here */
2506- return (uint32_t) uint4korr(pos+1);
2507-}
2508-
2509-/* The same as above but returns int64_t */
2510-uint64_t drizzleclient_drizzleclient_net_field_length_ll(unsigned char **packet)
2511-{
2512- register unsigned char *pos= *packet;
2513- if (*pos < 251)
2514- {
2515- (*packet)++;
2516- return (uint64_t) *pos;
2517- }
2518- if (*pos == 251)
2519- {
2520- (*packet)++;
2521- return (uint64_t) NULL_LENGTH;
2522- }
2523- if (*pos == 252)
2524- {
2525- (*packet)+=3;
2526- return (uint64_t) uint2korr(pos+1);
2527- }
2528- if (*pos == 253)
2529- {
2530- (*packet)+=4;
2531- return (uint64_t) uint3korr(pos+1);
2532- }
2533- (*packet)+=9; /* Must be 254 when here */
2534-#ifdef NO_CLIENT_LONGLONG
2535- return (uint64_t) uint4korr(pos+1);
2536-#else
2537- return (uint64_t) uint8korr(pos+1);
2538-#endif
2539-}
2540-
2541-/*
2542- Store an integer with simple packing into a output package
2543-
2544- SYNOPSIS
2545- drizzleclient_net_store_length()
2546- pkg Store the packed integer here
2547- length integers to store
2548-
2549- NOTES
2550- This is mostly used to store lengths of strings.
2551- We have to cast the result for the LL() becasue of a bug in Forte CC
2552- compiler.
2553-
2554- RETURN
2555- Position in 'pkg' after the packed length
2556-*/
2557-
2558-unsigned char *drizzleclient_net_store_length(unsigned char *packet, uint64_t length)
2559-{
2560- if (length < (uint64_t) 251LL)
2561- {
2562- *packet=(unsigned char) length;
2563- return packet+1;
2564- }
2565- /* 251 is reserved for NULL */
2566- if (length < (uint64_t) 65536LL)
2567- {
2568- *packet++=252;
2569- int2store(packet,(uint32_t) length);
2570- return packet+2;
2571- }
2572- if (length < (uint64_t) 16777216LL)
2573- {
2574- *packet++=253;
2575- int3store(packet,(uint32_t) length);
2576- return packet+3;
2577- }
2578- *packet++=254;
2579- int8store(packet,length);
2580- return packet+8;
2581-}
2582-
2583-} /* namespace drizzle_protocol */
2584
2585=== removed file 'plugin/drizzle_protocol/pack.h'
2586--- plugin/drizzle_protocol/pack.h 2010-03-04 18:06:27 +0000
2587+++ plugin/drizzle_protocol/pack.h 1970-01-01 00:00:00 +0000
2588@@ -1,34 +0,0 @@
2589-/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2590- * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2591- *
2592- * Copyright (C) 2008 Sun Microsystems
2593- *
2594- * This program is free software; you can redistribute it and/or modify
2595- * it under the terms of the GNU General Public License as published by
2596- * the Free Software Foundation; version 2 of the License.
2597- *
2598- * This program is distributed in the hope that it will be useful,
2599- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2600- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2601- * GNU General Public License for more details.
2602- *
2603- * You should have received a copy of the GNU General Public License
2604- * along with this program; if not, write to the Free Software
2605- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2606- */
2607-
2608-#ifndef PLUGIN_DRIZZLE_PROTOCOL_PACK_H
2609-#define PLUGIN_DRIZZLE_PROTOCOL_PACK_H
2610-
2611-namespace drizzle_protocol
2612-{
2613-
2614-#define NULL_LENGTH UINT32_MAX
2615-
2616-uint32_t drizzleclient_net_field_length(unsigned char **packet);
2617-uint64_t drizzleclient_drizzleclient_net_field_length_ll(unsigned char **packet);
2618-unsigned char *drizzleclient_net_store_length(unsigned char *pkg, uint64_t length);
2619-
2620-} /* namespace drizzle_protocol */
2621-
2622-#endif /* PLUGIN_DRIZZLE_PROTOCOL_PACK_H */
2623
2624=== modified file 'plugin/drizzle_protocol/plugin.ini'
2625--- plugin/drizzle_protocol/plugin.ini 2010-09-01 19:17:03 +0000
2626+++ plugin/drizzle_protocol/plugin.ini 2010-10-06 01:14:00 +0000
2627@@ -1,12 +1,17 @@
2628 [plugin]
2629 title=Drizzle Protocol Module
2630-description=Drizzle protocol module that uses the old libdrizzle library (previously libmysql).
2631-version=0.2
2632-author=Eric Day
2633+description=Drizzle protocol module.
2634+version=0.3
2635+author=Brian Aker
2636 license=PLUGIN_LICENSE_GPL
2637 libs=drizzled/algorithm/libhash.la
2638 load_by_default=yes
2639 ldlfags=$(LIBZ)
2640-headers=drizzle_protocol.h errmsg.h net_serv.h options.h pack.h vio.h table_function.h
2641-sources=drizzle_protocol.cc errmsg.cc net_serv.cc pack.cc vio.cc viosocket.cc
2642+headers=
2643+ drizzle_protocol.h
2644+ errmsg.h
2645+ status_table.h
2646+sources=
2647+ drizzle_protocol.cc
2648+ errmsg.h
2649 static=yes
2650
2651=== renamed file 'plugin/drizzle_protocol/table_function.h' => 'plugin/drizzle_protocol/status_table.h'
2652--- plugin/drizzle_protocol/table_function.h 2010-09-08 22:20:35 +0000
2653+++ plugin/drizzle_protocol/status_table.h 2010-10-06 01:14:00 +0000
2654@@ -18,18 +18,18 @@
2655 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2656 */
2657
2658-#ifndef PLUGIN_DRIZZLE_PROTOCOL_TABLE_FUNCTION_H
2659-#define PLUGIN_DRIZZLE_PROTOCOL_TABLE_FUNCTION_H
2660+#ifndef PLUGIN_DRIZZLE_PROTOCOL_STATUS_TABLE_H
2661+#define PLUGIN_DRIZZLE_PROTOCOL_STATUS_TABLE_H
2662
2663 #include "drizzled/plugin/table_function.h"
2664 namespace drizzle_protocol
2665 {
2666
2667
2668-class DrizzleProtocolStatus : public drizzled::plugin::TableFunction
2669+class StatusTable : public drizzled::plugin::TableFunction
2670 {
2671 public:
2672- DrizzleProtocolStatus() :
2673+ StatusTable() :
2674 drizzled::plugin::TableFunction("DATA_DICTIONARY","DRIZZLE_PROTOCOL_STATUS")
2675 {
2676 add_field("VARIABLE_NAME");
2677@@ -38,12 +38,17 @@
2678
2679 class Generator : public drizzled::plugin::TableFunction::Generator
2680 {
2681- drizzled::drizzle_show_var *status_var_ptr;
2682
2683 public:
2684- Generator(drizzled::Field **fields);
2685+ Generator(drizzled::Field **fields) :
2686+ drizzled::plugin::TableFunction::Generator(fields)
2687+ {
2688+ }
2689
2690- bool populate();
2691+ bool populate()
2692+ {
2693+ return false;
2694+ }
2695 };
2696
2697 Generator *generator(drizzled::Field **arg)
2698@@ -54,4 +59,4 @@
2699
2700 }
2701
2702-#endif /* PLUGIN_DRIZZLE_PROTOCOL_TABLE_FUNCTION_H */
2703+#endif /* PLUGIN_DRIZZLE_PROTOCOL_STATUS_TABLE_H */
2704
2705=== renamed file 'plugin/drizzle_protocol/vio.cc' => 'plugin/drizzle_protocol/vio.cc.THIS'
2706=== renamed file 'plugin/drizzle_protocol/vio.h' => 'plugin/drizzle_protocol/vio.h.THIS'
2707=== renamed file 'plugin/drizzle_protocol/viosocket.cc' => 'plugin/drizzle_protocol/viosocket.cc.THIS'
2708=== modified file 'plugin/information_schema_dictionary/key_column_usage.cc'
2709--- plugin/information_schema_dictionary/key_column_usage.cc 2010-07-11 15:57:03 +0000
2710+++ plugin/information_schema_dictionary/key_column_usage.cc 2010-10-06 01:14:00 +0000
2711@@ -41,7 +41,9 @@
2712 InformationSchema::Generator(arg),
2713 generator(getSession()),
2714 index_iterator(0),
2715- index_part_iterator(0)
2716+ index_part_iterator(0),
2717+ fk_constraint_iterator(0),
2718+ fk_constraint_column_name_iterator(0)
2719 {
2720 while (not (table_message= generator))
2721 { };
2722@@ -84,7 +86,7 @@
2723 push(table_message->field(fieldnr).name());
2724
2725 /* ORDINAL_POSITION */
2726- push(static_cast<int64_t>(index_part_iterator));
2727+ push(static_cast<int64_t>((index_part_iterator +1)));
2728
2729 if (index_part_iterator == index.index_part_size() -1)
2730 {
2731@@ -100,9 +102,56 @@
2732 }
2733 }
2734
2735+ if (fk_constraint_iterator != table_message->fk_constraint_size())
2736+ {
2737+ drizzled::message::Table::ForeignKeyConstraint foreign_key= table_message->fk_constraint(fk_constraint_iterator);
2738+
2739+ {
2740+ /* Constraints live in the same catalog.schema as the table they refer too. */
2741+ /* CONSTRAINT_CATALOG */
2742+ push(table_message->catalog());
2743+
2744+ /* CONSTRAINT_SCHEMA */
2745+ push(table_message->schema());
2746+
2747+ /* CONSTRAINT_NAME */
2748+ push(foreign_key.name());
2749+
2750+ /* TABLE_CATALOG */
2751+ push(table_message->catalog());
2752+
2753+ /* TABLE_SCHEMA */
2754+ push(table_message->schema());
2755+
2756+ /* TABLE_NAME */
2757+ push(table_message->name());
2758+
2759+ /* COLUMN_NAME */
2760+ push(foreign_key.column_names(fk_constraint_column_name_iterator));
2761+
2762+ /* ORDINAL_POSITION */
2763+ push(static_cast<int64_t>((fk_constraint_column_name_iterator + 1)));
2764+
2765+ if (fk_constraint_column_name_iterator == foreign_key.column_names_size() -1)
2766+ {
2767+ fk_constraint_iterator++;
2768+ fk_constraint_column_name_iterator= 0;
2769+ }
2770+ else
2771+ {
2772+ fk_constraint_column_name_iterator++;
2773+ }
2774+
2775+ return true;
2776+ }
2777+ }
2778+
2779 index_iterator= 0;
2780 index_part_iterator= 0;
2781
2782+ fk_constraint_iterator= 0;
2783+ fk_constraint_column_name_iterator= 0;
2784+
2785 } while ((table_message= generator));
2786
2787 return false;
2788
2789=== modified file 'plugin/information_schema_dictionary/key_column_usage.h'
2790--- plugin/information_schema_dictionary/key_column_usage.h 2010-07-09 21:52:18 +0000
2791+++ plugin/information_schema_dictionary/key_column_usage.h 2010-10-06 01:14:00 +0000
2792@@ -34,6 +34,9 @@
2793 int32_t index_iterator;
2794 int32_t index_part_iterator;
2795
2796+ int32_t fk_constraint_iterator;
2797+ int32_t fk_constraint_column_name_iterator;
2798+
2799 public:
2800 Generator(drizzled::Field **arg);
2801
2802
2803=== modified file 'plugin/information_schema_dictionary/tests/r/key_column_usage.result'
2804--- plugin/information_schema_dictionary/tests/r/key_column_usage.result 2010-07-09 21:52:18 +0000
2805+++ plugin/information_schema_dictionary/tests/r/key_column_usage.result 2010-10-06 01:14:00 +0000
2806@@ -336,40 +336,40 @@
2807 ) ;
2808 select * from information_schema.key_column_usage WHERE table_schema="everything" ORDER BY TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME;
2809 CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION
2810- everything PRIMARY everything branch branch_id 0
2811- everything PRIMARY everything container container_id 0
2812- everything PRIMARY everything document document_id 0
2813- everything PRIMARY everything genstats_attributes genstats_attributes_id 0
2814- everything PRIMARY everything htmlcode htmlcode_id 0
2815- everything PRIMARY everything htmlpage htmlpage_id 0
2816- everything PRIMARY everything image image_id 0
2817- everything PRIMARY everything javascript javascript_id 0
2818- everything PRIMARY everything knowledge_item knowledge_item_id 0
2819- everything PRIMARY everything links from_node 0
2820- everything PRIMARY everything links linktype 2
2821- everything PRIMARY everything links to_node 1
2822- everything PRIMARY everything mail mail_id 0
2823- everything PRIMARY everything node node_id 0
2824- everything PRIMARY everything nodegroup nodegroup_id 0
2825- everything PRIMARY everything nodegroup rank 1
2826- everything PRIMARY everything nodelet nodelet_id 0
2827- everything PRIMARY everything nodemethod nodemethod_id 0
2828- everything PRIMARY everything nodetype nodetype_id 0
2829- everything PRIMARY everything project project_id 0
2830- everything PRIMARY everything project_document project_document_id 0
2831- everything PRIMARY everything question question_id 0
2832- everything PRIMARY everything question rank 1
2833- everything PRIMARY everything redirects redirects_id 0
2834- everything PRIMARY everything releases releases_id 0
2835- everything PRIMARY everything revision inside_workspace 1
2836- everything PRIMARY everything revision node_id 0
2837- everything PRIMARY everything revision revision_id 2
2838- everything PRIMARY everything setting setting_id 0
2839- everything PRIMARY everything symlink symlink_id 0
2840- everything PRIMARY everything themesetting themesetting_id 0
2841- everything PRIMARY everything typeversion typeversion_id 0
2842- everything PRIMARY everything user user_id 0
2843- everything PRIMARY everything version version_id 0
2844- everything PRIMARY everything weblog entry_id 0
2845- everything PRIMARY everything workspace workspace_id 0
2846+ everything PRIMARY everything branch branch_id 1
2847+ everything PRIMARY everything container container_id 1
2848+ everything PRIMARY everything document document_id 1
2849+ everything PRIMARY everything genstats_attributes genstats_attributes_id 1
2850+ everything PRIMARY everything htmlcode htmlcode_id 1
2851+ everything PRIMARY everything htmlpage htmlpage_id 1
2852+ everything PRIMARY everything image image_id 1
2853+ everything PRIMARY everything javascript javascript_id 1
2854+ everything PRIMARY everything knowledge_item knowledge_item_id 1
2855+ everything PRIMARY everything links from_node 1
2856+ everything PRIMARY everything links linktype 3
2857+ everything PRIMARY everything links to_node 2
2858+ everything PRIMARY everything mail mail_id 1
2859+ everything PRIMARY everything node node_id 1
2860+ everything PRIMARY everything nodegroup nodegroup_id 1
2861+ everything PRIMARY everything nodegroup rank 2
2862+ everything PRIMARY everything nodelet nodelet_id 1
2863+ everything PRIMARY everything nodemethod nodemethod_id 1
2864+ everything PRIMARY everything nodetype nodetype_id 1
2865+ everything PRIMARY everything project project_id 1
2866+ everything PRIMARY everything project_document project_document_id 1
2867+ everything PRIMARY everything question question_id 1
2868+ everything PRIMARY everything question rank 2
2869+ everything PRIMARY everything redirects redirects_id 1
2870+ everything PRIMARY everything releases releases_id 1
2871+ everything PRIMARY everything revision inside_workspace 2
2872+ everything PRIMARY everything revision node_id 1
2873+ everything PRIMARY everything revision revision_id 3
2874+ everything PRIMARY everything setting setting_id 1
2875+ everything PRIMARY everything symlink symlink_id 1
2876+ everything PRIMARY everything themesetting themesetting_id 1
2877+ everything PRIMARY everything typeversion typeversion_id 1
2878+ everything PRIMARY everything user user_id 1
2879+ everything PRIMARY everything version version_id 1
2880+ everything PRIMARY everything weblog entry_id 1
2881+ everything PRIMARY everything workspace workspace_id 1
2882 drop schema everything;
2883
2884=== modified file 'tests/include.am'
2885--- tests/include.am 2010-10-02 21:15:42 +0000
2886+++ tests/include.am 2010-10-06 01:14:00 +0000
2887@@ -22,8 +22,8 @@
2888 GENSCRIPTS = tests/dtr tests/mtr tests/test-run
2889 PRESCRIPTS = tests/test-run.pl tests/stress-test.pl
2890 PLUGIN_TESTS = $(pandora_plugin_test_list)
2891-NORMAL_TESTS = main,jp,tamil,$(PLUGIN_TESTS)
2892-ALL_TESTS = main,big,jp,tamil,$(PLUGIN_TESTS)
2893+NORMAL_TESTS = main,jp,tamil,regression,$(PLUGIN_TESTS)
2894+ALL_TESTS = main,big,jp,tamil,regression,$(PLUGIN_TESTS)
2895 noinst_SCRIPTS = $(GENSCRIPTS) $(PRESCRIPTS)
2896 CLEANFILES += $(GENSCRIPTS) tests/mtr
2897
2898
2899=== added directory 'tests/suite/regression'
2900=== added directory 'tests/suite/regression/r'
2901=== added file 'tests/suite/regression/r/654219.result'
2902--- tests/suite/regression/r/654219.result 1970-01-01 00:00:00 +0000
2903+++ tests/suite/regression/r/654219.result 2010-10-06 01:14:00 +0000
2904@@ -0,0 +1,63 @@
2905+CREATE TABLE `prim_key` (
2906+`id` INT NOT NULL,
2907+`val` VARCHAR(20) COLLATE utf8_general_ci DEFAULT NULL,
2908+PRIMARY KEY (`id`)
2909+);
2910+CREATE TABLE `fore_key0` (
2911+`id` INT NOT NULL,
2912+`id_ref0` INT DEFAULT NULL,
2913+PRIMARY KEY (`id`),
2914+KEY `id_ref0` (`id_ref0`),
2915+CONSTRAINT `fore_key0_ibfk_1` FOREIGN KEY (`id_ref0`) REFERENCES
2916+`prim_key` (`id`)
2917+);
2918+CREATE TABLE `fore_key1` (
2919+`id` INT NOT NULL,
2920+`id_ref1` INT DEFAULT NULL,
2921+PRIMARY KEY (`id`),
2922+KEY `id_ref1` (`id_ref1`),
2923+CONSTRAINT `fore_key1_ibfk_1` FOREIGN KEY (`id_ref1`) REFERENCES
2924+`prim_key` (`id`) ON UPDATE CASCADE
2925+);
2926+SELECT CONSTRAINT_NAME,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE;
2927+CONSTRAINT_NAME TABLE_NAME COLUMN_NAME ORDINAL_POSITION
2928+PRIMARY prim_key id 1
2929+PRIMARY fore_key1 id 1
2930+fore_key1_ibfk_1 fore_key1 id_ref1 1
2931+PRIMARY fore_key0 id 1
2932+fore_key0_ibfk_1 fore_key0 id_ref0 1
2933+DROP TABLE fore_key1;
2934+DROP TABLE fore_key0;
2935+DROP TABLE prim_key;
2936+CREATE TABLE t1
2937+(
2938+s1 INT,
2939+s2 INT,
2940+s3 INT,
2941+PRIMARY KEY(s3)
2942+);
2943+CREATE TABLE t3
2944+(
2945+s1 INT,
2946+s2 INT,
2947+s3 INT,
2948+KEY(s1),
2949+CONSTRAINT CO FOREIGN KEY (s2)
2950+REFERENCES t1(s3)
2951+);
2952+SELECT CONSTRAINT_NAME,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE;
2953+CONSTRAINT_NAME TABLE_NAME COLUMN_NAME ORDINAL_POSITION
2954+CO t3 s2 1
2955+PRIMARY t1 s3 1
2956+DROP TABLE t3;
2957+DROP TABLE t1;
2958+CREATE TABLE t1 (c1 INT NOT NULL, c2 INT NOT NULL, c3 CHAR(5), c4 INT, c5 INT, constraint pk_t1 PRIMARY KEY (c5,c4));
2959+CREATE TABLE T2 (tc1 INT NOT NULL, c1 INT NOT NULL, c2 INT NOT NULL, c5 CHAR(5), constraint fk_t2 FOREIGN KEY (c1,c2) REFERENCES t1 (c5,c4));
2960+SELECT CONSTRAINT_NAME, TABLE_NAME, COLUMN_NAME, ORDINAL_POSITION FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME IN ('t1', 't2');
2961+CONSTRAINT_NAME TABLE_NAME COLUMN_NAME ORDINAL_POSITION
2962+PRIMARY t1 c5 1
2963+PRIMARY t1 c4 2
2964+fk_t2 t2 c1 1
2965+fk_t2 t2 c2 2
2966+DROP TABLE t2;
2967+DROP TABLE t1;
2968
2969=== added directory 'tests/suite/regression/t'
2970=== added file 'tests/suite/regression/t/654219.test'
2971--- tests/suite/regression/t/654219.test 1970-01-01 00:00:00 +0000
2972+++ tests/suite/regression/t/654219.test 2010-10-06 01:14:00 +0000
2973@@ -0,0 +1,64 @@
2974+CREATE TABLE `prim_key` (
2975+ `id` INT NOT NULL,
2976+ `val` VARCHAR(20) COLLATE utf8_general_ci DEFAULT NULL,
2977+ PRIMARY KEY (`id`)
2978+);
2979+
2980+CREATE TABLE `fore_key0` (
2981+ `id` INT NOT NULL,
2982+ `id_ref0` INT DEFAULT NULL,
2983+ PRIMARY KEY (`id`),
2984+ KEY `id_ref0` (`id_ref0`),
2985+ CONSTRAINT `fore_key0_ibfk_1` FOREIGN KEY (`id_ref0`) REFERENCES
2986+ `prim_key` (`id`)
2987+);
2988+
2989+CREATE TABLE `fore_key1` (
2990+ `id` INT NOT NULL,
2991+ `id_ref1` INT DEFAULT NULL,
2992+ PRIMARY KEY (`id`),
2993+ KEY `id_ref1` (`id_ref1`),
2994+ CONSTRAINT `fore_key1_ibfk_1` FOREIGN KEY (`id_ref1`) REFERENCES
2995+ `prim_key` (`id`) ON UPDATE CASCADE
2996+);
2997+
2998+SELECT CONSTRAINT_NAME,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE;
2999+
3000+DROP TABLE fore_key1;
3001+DROP TABLE fore_key0;
3002+DROP TABLE prim_key;
3003+
3004+# Taken from MySQL example
3005+CREATE TABLE t1
3006+(
3007+ s1 INT,
3008+ s2 INT,
3009+ s3 INT,
3010+ PRIMARY KEY(s3)
3011+);
3012+
3013+CREATE TABLE t3
3014+(
3015+ s1 INT,
3016+ s2 INT,
3017+ s3 INT,
3018+ KEY(s1),
3019+ CONSTRAINT CO FOREIGN KEY (s2)
3020+ REFERENCES t1(s3)
3021+);
3022+
3023+SELECT CONSTRAINT_NAME,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE;
3024+
3025+DROP TABLE t3;
3026+DROP TABLE t1;
3027+
3028+# Taken from SQL Server example
3029+CREATE TABLE t1 (c1 INT NOT NULL, c2 INT NOT NULL, c3 CHAR(5), c4 INT, c5 INT, constraint pk_t1 PRIMARY KEY (c5,c4));
3030+
3031+CREATE TABLE T2 (tc1 INT NOT NULL, c1 INT NOT NULL, c2 INT NOT NULL, c5 CHAR(5), constraint fk_t2 FOREIGN KEY (c1,c2) REFERENCES t1 (c5,c4));
3032+
3033+SELECT CONSTRAINT_NAME, TABLE_NAME, COLUMN_NAME, ORDINAL_POSITION FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME IN ('t1', 't2');
3034+
3035+DROP TABLE t2;
3036+DROP TABLE t1;
3037+