23#ifndef BINLOG_OSTREAM_INCLUDED
24#define BINLOG_OSTREAM_INCLUDED
26#include <openssl/evp.h>
47template <
class ISTREAM,
class OSTREAM>
49 bool *ostream_error =
nullptr) {
50 unsigned char *
buffer =
nullptr;
54 while (!ret &&
length > 0) {
56 if (ostream_error !=
nullptr) *ostream_error =
true;
96 bool seek(
my_off_t offset [[maybe_unused]])
override {
return true; }
136 bool flush()
override {
return false; }
137 bool sync()
override {
return false; }
256 bool open(std::unique_ptr<Truncatable_ostream> down_ostream);
269 bool open(std::unique_ptr<Truncatable_ostream> down_ostream,
270 std::unique_ptr<Rpl_encryption_header> header);
281 std::pair<bool, std::string>
reencrypt();
287 bool flush()
override;
288 bool sync()
override;
bool stream_copy(ISTREAM *istream, OSTREAM *ostream, bool *ostream_error=nullptr)
Copy data from an input stream to an output stream.
Definition: binlog_ostream.h:48
bool binlog_cache_is_reset
Definition: binlog_ostream.cc:37
The abstract class for basic output streams which provides write operation.
Definition: basic_ostream.h:34
virtual bool write(const unsigned char *buffer, my_off_t length)=0
Write some bytes into the output stream.
Byte container that provides a storage for serializing session binlog events.
Definition: binlog_ostream.h:172
bool truncate(my_off_t offset)
Truncates some data at the end of the binlog cache.
Definition: binlog_ostream.h:190
~Binlog_cache_storage() override
Definition: binlog_ostream.cc:266
my_off_t length() const
Returns data length.
Definition: binlog_ostream.h:227
IO_CACHE_binlog_cache_storage m_file
Definition: binlog_ostream.h:235
bool is_empty() const
Returns true if binlog cache is empty.
Definition: binlog_ostream.h:231
Truncatable_ostream * m_pipeline_head
Definition: binlog_ostream.h:234
bool open(my_off_t cache_size, my_off_t max_cache_size)
Definition: binlog_ostream.cc:252
bool reset()
Reset status and drop all data.
Definition: binlog_ostream.h:196
size_t disk_writes() const
Returns the count of disk writes.
Definition: binlog_ostream.h:200
const char * tmp_file_name() const
Returns the name of the temporary file.
Definition: binlog_ostream.h:204
bool copy_to(Basic_ostream *ostream, bool *ostream_error=nullptr)
Copy all data to a output stream.
Definition: binlog_ostream.h:220
bool write(const unsigned char *buffer, my_off_t length) override
Write some bytes into the output stream.
Definition: binlog_ostream.h:179
void close()
Definition: binlog_ostream.cc:261
It is an Truncatable_ostream which provides encryption feature.
Definition: binlog_ostream.h:243
int get_header_size()
Return the encrypted file header size.
Definition: binlog_ostream.cc:410
bool open(std::unique_ptr< Truncatable_ostream > down_ostream)
Initialize the context used in the encryption stream and write encryption header into down stream.
Definition: binlog_ostream.cc:279
std::unique_ptr< Rpl_encryption_header > m_header
Definition: binlog_ostream.h:298
std::unique_ptr< Truncatable_ostream > m_down_ostream
Definition: binlog_ostream.h:297
std::unique_ptr< Stream_cipher > m_encryptor
Definition: binlog_ostream.h:299
void close()
Definition: binlog_ostream.cc:362
std::pair< bool, std::string > reencrypt()
Re-encrypt the encrypted binary/relay log file header by replacing its binlog encryption key id with ...
Definition: binlog_ostream.cc:315
bool write(const unsigned char *buffer, my_off_t length) override
Write some bytes into the output stream.
Definition: binlog_ostream.cc:368
bool sync() override
Sync.
Definition: binlog_ostream.cc:408
~Binlog_encryption_ostream() override
Definition: binlog_ostream.cc:268
bool flush() override
Flush data.
Definition: binlog_ostream.cc:406
bool truncate(my_off_t offset) override
Truncate some data at the end of the output stream.
Definition: binlog_ostream.cc:400
bool seek(my_off_t offset) override
Put the write position to a given offset.
Definition: binlog_ostream.cc:395
A binlog cache implementation based on IO_CACHE.
Definition: binlog_ostream.h:68
void disable_encryption()
Disable IO Cache temporary file encryption.
Definition: binlog_ostream.cc:222
bool seek(my_off_t offset) override
Put the write position to a given offset.
Definition: binlog_ostream.h:96
const char * tmp_file_name() const
Returns the file name if a temporary file is opened, otherwise nullptr is returned.
Definition: binlog_ostream.cc:146
my_off_t m_max_cache_size
Definition: binlog_ostream.h:141
IO_CACHE_binlog_cache_storage(const IO_CACHE_binlog_cache_storage &)=delete
bool sync() override
Sync.
Definition: binlog_ostream.h:137
bool begin(unsigned char **buffer, my_off_t *length)
Initializes binlog cache for reading and returns the data at the begin.
Definition: binlog_ostream.cc:150
IO_CACHE_binlog_cache_storage & operator=(const IO_CACHE_binlog_cache_storage &)=delete
bool flush() override
Flush data.
Definition: binlog_ostream.h:136
bool reset()
Reset status and drop all data.
Definition: binlog_ostream.cc:107
bool truncate(my_off_t offset) override
Truncate some data at the end of the output stream.
Definition: binlog_ostream.cc:92
IO_CACHE_binlog_cache_storage()
bool setup_ciphers_password()
Generate a new password for the temporary file encryption.
Definition: binlog_ostream.cc:233
size_t disk_writes() const
Returns the count of calling temporary file's write()
Definition: binlog_ostream.cc:142
bool open(const char *dir, const char *prefix, my_off_t cache_size, my_off_t max_cache_size)
Opens the binlog cache.
Definition: binlog_ostream.cc:43
my_off_t length() const
Definition: binlog_ostream.cc:195
bool enable_encryption()
Enable IO Cache temporary file encryption.
Definition: binlog_ostream.cc:200
void close()
Definition: binlog_ostream.cc:58
IO_CACHE m_io_cache
Definition: binlog_ostream.h:140
~IO_CACHE_binlog_cache_storage() override
Definition: binlog_ostream.cc:41
bool write(const unsigned char *buffer, my_off_t length) override
Write some bytes into the output stream.
Definition: binlog_ostream.cc:60
bool next(unsigned char **buffer, my_off_t *length)
Returns next piece of data.
Definition: binlog_ostream.cc:183
Truncatable_ostream abstract class provides seek() and truncate() interfaces to all truncatable outpu...
Definition: basic_ostream.h:55
virtual bool truncate(my_off_t offset)=0
Truncate some data at the end of the output stream.
ulonglong my_off_t
Definition: my_inttypes.h:71
std::string dir
Double write files location.
Definition: buf0dblwr.cc:76
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:419
This file includes the major components for encrypting/decrypting binary log files.
static uint64_t cache_size
Definition: xcom_cache.cc:361