ClickHouse/src/Server/MySQLHandler.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
2.9 KiB
C++
Raw Normal View History

2019-03-16 02:08:21 +00:00
#pragma once
2019-03-16 02:08:21 +00:00
#include <Poco/Net/TCPServerConnection.h>
2021-10-02 07:13:14 +00:00
#include <base/getFQDNOrHostName.h>
#include <Common/CurrentMetrics.h>
2020-08-13 12:07:02 +00:00
#include <Core/MySQL/Authentication.h>
#include <Core/MySQL/PacketsGeneric.h>
#include <Core/MySQL/PacketsConnection.h>
#include <Core/MySQL/PacketsProtocolText.h>
2019-03-16 02:08:21 +00:00
#include "IServer.h"
#include "config.h"
#if USE_SSL
# include <Poco/Net/SecureStreamSocket.h>
#endif
2019-03-16 02:08:21 +00:00
#include <memory>
namespace CurrentMetrics
{
extern const Metric MySQLConnection;
}
2019-03-16 02:08:21 +00:00
namespace DB
{
class ReadBufferFromPocoSocket;
class TCPServer;
2019-03-16 02:08:21 +00:00
/// Handler for MySQL wire protocol connections. Allows to connect to ClickHouse using MySQL client.
2019-04-01 09:59:49 +00:00
class MySQLHandler : public Poco::Net::TCPServerConnection
{
2019-03-16 02:08:21 +00:00
public:
MySQLHandler(
IServer & server_,
TCPServer & tcp_server_,
const Poco::Net::StreamSocket & socket_,
bool ssl_enabled,
uint32_t connection_id_);
2019-03-16 02:08:21 +00:00
void run() final;
2021-07-16 10:10:56 +00:00
protected:
CurrentMetrics::Increment metric_increment{CurrentMetrics::MySQLConnection};
2019-04-29 06:05:30 +00:00
/// Enables SSL, if client requested.
2020-08-13 08:17:33 +00:00
void finishHandshake(MySQLProtocol::ConnectionPhase::HandshakeResponse &);
2019-04-29 06:05:30 +00:00
2019-07-14 22:13:56 +00:00
void comQuery(ReadBuffer & payload);
2019-03-16 02:08:21 +00:00
2019-07-14 22:13:56 +00:00
void comFieldList(ReadBuffer & payload);
2019-03-16 02:08:21 +00:00
void comPing();
2019-07-14 22:13:56 +00:00
void comInitDB(ReadBuffer & payload);
2019-04-01 09:59:49 +00:00
void authenticate(const String & user_name, const String & auth_plugin_name, const String & auth_response);
virtual void authPluginSSL();
2020-08-13 08:17:33 +00:00
virtual void finishHandshakeSSL(size_t packet_size, char * buf, size_t pos, std::function<void(size_t)> read_bytes, MySQLProtocol::ConnectionPhase::HandshakeResponse & packet);
2019-03-16 02:08:21 +00:00
IServer & server;
TCPServer & tcp_server;
2019-03-16 02:08:21 +00:00
Poco::Logger * log;
uint32_t connection_id = 0;
2021-07-16 10:10:56 +00:00
uint32_t server_capabilities = 0;
uint32_t client_capabilities = 0;
size_t max_packet_size = 0;
uint8_t sequence_id = 0;
2019-03-16 02:08:21 +00:00
2021-07-07 15:46:56 +00:00
MySQLProtocol::PacketEndpointPtr packet_endpoint;
2021-08-01 14:12:34 +00:00
std::unique_ptr<Session> session;
2019-03-16 02:08:21 +00:00
2021-07-16 10:10:56 +00:00
using ReplacementFn = std::function<String(const String & query)>;
using Replacements = std::unordered_map<std::string, ReplacementFn>;
Replacements replacements;
2019-03-16 02:08:21 +00:00
std::unique_ptr<MySQLProtocol::Authentication::IPlugin> auth_plugin;
std::shared_ptr<ReadBufferFromPocoSocket> in;
2019-04-29 06:05:30 +00:00
std::shared_ptr<WriteBuffer> out;
bool secure_connection = false;
2019-03-16 02:08:21 +00:00
};
#if USE_SSL
class MySQLHandlerSSL : public MySQLHandler
{
public:
MySQLHandlerSSL(
IServer & server_,
TCPServer & tcp_server_,
const Poco::Net::StreamSocket & socket_,
bool ssl_enabled,
uint32_t connection_id_,
RSA & public_key_,
RSA & private_key_);
private:
void authPluginSSL() override;
2020-08-13 08:17:33 +00:00
void finishHandshakeSSL(
size_t packet_size, char * buf, size_t pos,
std::function<void(size_t)> read_bytes, MySQLProtocol::ConnectionPhase::HandshakeResponse & packet) override;
RSA & public_key;
RSA & private_key;
std::shared_ptr<Poco::Net::SecureStreamSocket> ss;
};
2019-09-11 11:21:54 +00:00
#endif
}