Drizzled Public API Documentation

mysql_protocol.h
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #pragma once
00021 
00022 #include <drizzled/plugin/listen_tcp.h>
00023 #include <drizzled/plugin/client.h>
00024 #include <drizzled/atomics.h>
00025 #include <drizzled/plugin/table_function.h>
00026 
00027 #include "net_serv.h"
00028 
00029 namespace drizzle_plugin
00030 {
00031 void compose_ip_addresses(std::vector<std::string> options);
00032 
00033 class ProtocolCounters
00034 {
00035   public:
00036     ProtocolCounters():
00037       max_connections(1000)
00038     { }
00039     drizzled::atomic<uint64_t> connectionCount;
00040     drizzled::atomic<uint64_t> adminConnectionCount;
00041     drizzled::atomic<uint64_t> failedConnections;
00042     drizzled::atomic<uint64_t> connected;
00043     drizzled::atomic<uint64_t> adminConnected;
00044     uint32_t max_connections;
00045 };
00046 
00047 typedef drizzled::constrained_check<uint32_t, 300, 1> timeout_constraint;
00048 typedef drizzled::constrained_check<uint32_t, 300, 1> retry_constraint;
00049 typedef drizzled::constrained_check<uint32_t, 1048576, 1024, 1024> buffer_constraint;
00050 
00051 class ListenMySQLProtocol: public drizzled::plugin::ListenTcp
00052 {
00053 protected:
00054   const std::string _hostname;
00055   bool _using_mysql41_protocol;
00056 
00057 public:
00058   ListenMySQLProtocol(std::string name,
00059                       const std::string &hostname,
00060                       bool using_mysql41_protocol):
00061    drizzled::plugin::ListenTcp(name),
00062    _hostname(hostname),
00063    _using_mysql41_protocol(using_mysql41_protocol)
00064   { }
00065   virtual ~ListenMySQLProtocol();
00066   virtual const std::string getHost(void) const;
00067   virtual in_port_t getPort(void) const;
00068   virtual drizzled::plugin::Client *getClient(int fd);
00069   static ProtocolCounters *mysql_counters;
00070   virtual ProtocolCounters *getCounters(void) const { return mysql_counters; }
00071   void addCountersToTable(void);
00072 };
00073 
00074 class ClientMySQLProtocol: public drizzled::plugin::Client
00075 {
00076 protected:
00077   NET net;
00078   drizzled::String packet;
00079   uint32_t client_capabilities;
00080   bool is_admin_connection;
00081   bool _using_mysql41_protocol;
00082   bool _is_interactive;
00083 
00084   bool checkConnection(void);
00085   bool netStoreData(const unsigned char *from, size_t length);
00086   void writeEOFPacket(uint32_t server_status, uint32_t total_warn_count);
00087   unsigned char *storeLength(unsigned char *packet, uint64_t length);
00088   void makeScramble(char *scramble);
00089 
00090 public:
00091   ClientMySQLProtocol(int fd, bool _using_mysql41_protocol, ProtocolCounters *set_counters);
00092   virtual ~ClientMySQLProtocol();
00093 
00094   bool isInteractive() const
00095   {
00096     return _is_interactive;
00097   }
00098 
00099   bool isAdmin() const
00100   {
00101     return is_admin_connection;
00102   }
00103 
00104   ProtocolCounters *counters;
00105 
00106   virtual int getFileDescriptor(void);
00107   virtual bool isConnected();
00108   virtual bool isReading(void);
00109   virtual bool isWriting(void);
00110   virtual bool flush(void);
00111   virtual void close(void);
00112 
00113   virtual bool authenticate(void);
00114   virtual bool readCommand(char **packet, uint32_t *packet_length);
00115 
00116   virtual void sendOK(void);
00117   virtual void sendEOF(void);
00118   virtual void sendError(const drizzled::error_t sql_errno, const char *err);
00119 
00120   virtual bool sendFields(drizzled::List<drizzled::Item> *list);
00121 
00122   using Client::store;
00123   virtual bool store(drizzled::Field *from);
00124   virtual bool store(void);
00125   virtual bool store(int32_t from);
00126   virtual bool store(uint32_t from);
00127   virtual bool store(int64_t from);
00128   virtual bool store(uint64_t from);
00129   virtual bool store(double from, uint32_t decimals, drizzled::String *buffer);
00130   virtual bool store(const char *from, size_t length);
00131 
00132   virtual bool haveError(void);
00133   virtual bool haveMoreData(void);
00134   virtual bool wasAborted(void);
00135   virtual bool isAdminAllowed(void);
00136   static std::vector<std::string> mysql_admin_ip_addresses;
00137   static void mysql_compose_ip_addresses(std::vector<std::string> options);
00138 };
00139 
00140 } /* namespace drizzle_plugin */
00141