26#ifndef MYSQLD_MOCK_STATEMENT_READER_INCLUDED
27#define MYSQLD_MOCK_STATEMENT_READER_INCLUDED
37#include <openssl/bio.h>
71 const std::vector<session_tracker_field> &trackers);
77 std::vector<classic_protocol::message::server::ColumnMeta>
columns;
78 std::vector<RowValueType>
rows;
110 ssl_ = std::move(rhs.ssl_);
135 template <
class CompletionToken>
142 auto write_ec = write_res.error();
148 [
this, compl_handler = std::move(
init.completion_handler)](
149 std::error_code ec)
mutable {
151 compl_handler(ec, {});
159 [compl_handler = std::move(
init.completion_handler),
160 ec = write_res.error()]() { compl_handler(ec, {}); });
166 [compl_handler = std::move(
init.completion_handler),
167 transferred = write_res.value()]() {
168 compl_handler({}, transferred);
172 return init.result.get();
175 template <
class CompletionToken>
178 async_send_tls(std::forward<CompletionToken>(token));
181 std::forward<CompletionToken>(token));
190 template <
class CompletionToken>
197 auto orig_size =
buf.size();
198 auto grow_size = 16 * 1024;
201 size_t transferred{};
202 auto read_res = read_ssl(
buf.data(orig_size, grow_size));
204 transferred = read_res.value();
207 buf.shrink(grow_size - transferred);
210 const auto read_ec = read_res.error();
212 client_socket_.async_wait(
215 [
this, compl_handler = std::move(
init.completion_handler)](
216 std::error_code ec)
mutable {
218 compl_handler(ec, {});
222 async_receive_tls(std::move(compl_handler));
229 client_socket_.get_executor(),
230 [compl_handler = std::move(
init.completion_handler),
231 ec = map_tls_error_code(read_ec)]() { compl_handler(ec, {}); });
236 [compl_handler = std::move(
init.completion_handler),
237 transferred]() { compl_handler({}, transferred); });
240 return init.result.get();
243 template <
class CompletionToken>
246 return async_receive_tls(std::forward<CompletionToken>(token));
249 std::forward<CompletionToken>(token));
253 template <
class CompletionToken>
258 auto res = tls_accept();
260 auto ec = res.error();
265 client_socket_.async_wait(
266 wt, [&, compl_handler = std::move(
init.completion_handler)](
267 std::error_code ec)
mutable {
274 async_tls_accept(std::move(compl_handler));
277 net::defer(client_socket_.get_executor().context(),
278 [ec, compl_handler = std::move(
init.completion_handler)]() {
283 net::defer(client_socket_.get_executor().context(),
284 [compl_handler = std::move(
init.completion_handler)]() {
289 return init.result.get();
292 const std::vector<uint8_t> &
send_buffer()
const {
return send_buffer_; }
301 auth_method_name_ = auth_method_name;
307 auth_method_data_ = auth_method_data;
312 static bool authenticate(
const std::string &auth_method_name,
313 const std::string &auth_method_data,
315 const std::vector<uint8_t> &auth_response);
321 const SSL *
ssl()
const {
return ssl_.get(); }
338 std::string username_{};
339 std::string auth_method_name_{};
340 std::string auth_method_data_{};
349 std::unique_ptr<SSL, SSL_Deleter>
ssl_;
362 bool cert_required{
false};
395 bool is_greeting) = 0;
static mysql_service_status_t init()
Component initialization.
Definition: audit_api_message_emit.cc:571
TLS Context for the server side.
Definition: tls_server_context.h:51
gtid changed.
Definition: classic_protocol_session_track.h:146
Definition: executor.h:72
Definition: socket.h:1090
io_context & context() const noexcept
Definition: io_context.h:1003
Definition: io_context.h:61
executor_type get_executor() noexcept
Definition: io_context.h:1081
TCP protocol.
Definition: internet.h:1155
basic_endpoint< tcp > endpoint
Definition: internet.h:1157
basic_stream_socket< tcp > socket
Definition: internet.h:1159
static constexpr wait_type wait_read
Definition: socket.h:168
static constexpr wait_type wait_write
Definition: socket.h:169
Definition: statement_reader.h:344
void operator()(SSL *v)
Definition: statement_reader.h:346
Definition: statement_reader.h:95
std::string username() const
Definition: statement_reader.h:298
virtual ~ProtocolBase()=default
net::steady_timer & exec_timer()
Definition: statement_reader.h:325
TlsServerContext & tls_ctx_
Definition: statement_reader.h:342
ProtocolBase(socket_type client_sock, endpoint_type client_ep, TlsServerContext &tls_ctx)
Definition: protocol_base.cc:36
stdx::expected< size_t, std::error_code > avail_ssl()
Definition: protocol_base.cc:73
const std::vector< uint8_t > & send_buffer() const
Definition: statement_reader.h:292
void async_send_tls(CompletionToken &&token)
Definition: statement_reader.h:136
socket_type client_socket_
Definition: statement_reader.h:334
const SSL * ssl() const
Definition: statement_reader.h:321
std::string auth_method_data() const
Definition: statement_reader.h:310
void auth_method_name(const std::string &auth_method_name)
Definition: statement_reader.h:300
ProtocolBase(ProtocolBase &&)=default
ProtocolBase & operator=(ProtocolBase &&rhs)
Definition: statement_reader.h:108
void async_tls_accept(CompletionToken &&token)
Definition: statement_reader.h:254
virtual void encode_resultset(const ResultsetResponse &response)=0
endpoint_type client_ep_
Definition: statement_reader.h:335
std::vector< uint8_t > recv_buffer_
Definition: statement_reader.h:351
const net::ip::tcp::socket & client_socket() const
Definition: statement_reader.h:294
void async_receive_tls(CompletionToken &&token)
Definition: statement_reader.h:191
void auth_method_data(const std::string &auth_method_data)
Definition: statement_reader.h:306
bool is_tls()
Definition: statement_reader.h:319
void async_receive(CompletionToken &&token)
Definition: statement_reader.h:244
typename protocol_type::endpoint endpoint_type
Definition: statement_reader.h:99
void async_send(CompletionToken &&token)
Definition: statement_reader.h:176
std::string auth_method_name() const
Definition: statement_reader.h:304
virtual void encode_error(const ErrorResponse &resp)=0
stdx::expected< size_t, std::error_code > read_ssl(const net::mutable_buffer &buf)
Definition: protocol_base.cc:59
static std::error_code map_tls_error_code(std::error_code ec)
Definition: statement_reader.h:186
void username(const std::string &username)
Definition: statement_reader.h:296
ProtocolBase & operator=(const ProtocolBase &)=delete
virtual void encode_ok(const OkResponse &resp)=0
typename protocol_type::socket socket_type
Definition: statement_reader.h:98
stdx::expected< size_t, std::error_code > write_ssl(const net::const_buffer &buf)
Definition: protocol_base.cc:48
std::vector< uint8_t > send_buffer_
Definition: statement_reader.h:352
net::io_context & io_context()
Definition: statement_reader.h:329
ProtocolBase(const ProtocolBase &)=delete
std::unique_ptr< SSL, SSL_Deleter > ssl_
Definition: statement_reader.h:349
Definition: statement_reader.h:355
StatementReaderBase & operator=(StatementReaderBase &&)=default
virtual std::vector< AsyncNotice > get_async_notices()=0
virtual stdx::expected< handshake_data, ErrorResponse > handshake(bool is_greeting)=0
StatementReaderBase(StatementReaderBase &&)=default
virtual ~StatementReaderBase()=default
virtual void set_session_ssl_info(const SSL *ssl)=0
virtual void handle_statement(const std::string &statement, ProtocolBase *protocol)=0
Returns the data about the next statement from the json file.
StatementReaderBase & operator=(const StatementReaderBase &)=default
StatementReaderBase()=default
StatementReaderBase(const StatementReaderBase &)=default
virtual std::chrono::microseconds get_default_exec_time()=0
Returns the default execution time in microseconds.
static char * password
Definition: mysql_secure_installation.cc:58
Definition: buf0block_hint.cc:30
constexpr value_type ssl
Definition: classic_protocol_constants.h:49
borrowable::message::server::Error< false > Error
Definition: classic_protocol_message.h:1411
borrowable::message::server::Greeting< false > Greeting
Definition: classic_protocol_message.h:1413
borrowable::message::server::Eof< false > Eof
Definition: classic_protocol_message.h:1412
borrowable::message::server::Ok< false > Ok
Definition: classic_protocol_message.h:1410
borrowable::session_track::TransactionCharacteristics< false > TransactionCharacteristics
Definition: classic_protocol_session_track.h:297
borrowable::session_track::TransactionState TransactionState
Definition: classic_protocol_session_track.h:298
borrowable::session_track::SystemVariable< false > SystemVariable
Definition: classic_protocol_session_track.h:299
borrowable::session_track::State State
Definition: classic_protocol_session_track.h:301
borrowable::session_track::Schema< false > Schema
Definition: classic_protocol_session_track.h:300
dynamic_vector_buffer< T, Allocator > dynamic_buffer(std::vector< T, Allocator > &vec) noexcept
Definition: buffer.h:661
auto defer(CompletionToken &&token)
Definition: executor.h:787
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
std::enable_if_t< is_dynamic_buffer< DynamicBuffer >::value, void > async_read(AsyncReadStream &stream, DynamicBuffer &&b, CompletionCondition completion_condition, CompletionToken &&token)
Definition: buffer.h:928
std::enable_if_t< is_const_buffer_sequence_v< ConstBufferSequence >, void > async_write(AsyncWriteStream &stream, const ConstBufferSequence &buffers, CompletionCondition cond, CompletionToken &&token)
Definition: buffer.h:1075
Definition: mock_server_component.h:36
std::variant< classic_protocol::session_track::TransactionCharacteristics, classic_protocol::session_track::TransactionState, classic_protocol::session_track::SystemVariable, classic_protocol::session_track::Schema, classic_protocol::session_track::State, classic_protocol::session_track::Gtid > session_tracker_field
Definition: statement_reader.h:68
classic_protocol::message::server::Ok OkResponse
Definition: statement_reader.h:83
std::vector< std::optional< std::string > > RowValueType
Vector for keeping has_value|string representation of the values of the single row (ordered by column...
Definition: statement_reader.h:60
classic_protocol::message::server::Error ErrorResponse
Definition: statement_reader.h:84
std::string encode_session_trackers(const std::vector< session_tracker_field > &trackers)
Definition: duktape_statement_reader.cc:91
Definition: statement_reader.h:86
std::chrono::milliseconds send_offset_ms
Definition: statement_reader.h:89
bool is_local
Definition: statement_reader.h:91
std::string payload
Definition: statement_reader.h:92
unsigned type
Definition: statement_reader.h:90
Keeps result data for single SQL statement that returns resultset.
Definition: statement_reader.h:76
std::vector< RowValueType > rows
Definition: statement_reader.h:78
classic_protocol::message::server::Eof end_of_rows
Definition: statement_reader.h:80
std::vector< classic_protocol::message::server::ColumnMeta > columns
Definition: statement_reader.h:77
Definition: statement_reader.h:357
std::optional< std::string > username
Definition: statement_reader.h:360
std::chrono::microseconds exec_time
Definition: statement_reader.h:366
classic_protocol::message::server::Greeting greeting
Definition: statement_reader.h:358
std::optional< std::string > cert_issuer
Definition: statement_reader.h:364
std::optional< std::string > password
Definition: statement_reader.h:361
std::optional< std::string > cert_subject
Definition: statement_reader.h:363
Definition: mysqlslap.cc:219