MySQL  8.0.19
Source Code Documentation
mysql_harness Namespace Reference

Namespaces

 detail
 
 logging
 
 utility
 

Classes

class  bad_option
 Exception thrown for option problems. More...
 
class  bad_section
 Exception thrown for section problems. More...
 
class  BuiltinPlugins
 Singleton class implementing registry of the built-in MySQLRouter plugins. More...
 
class  Config
 Configuration. More...
 
class  ConfigOption
 
class  ConfigSection
 Configuration section. More...
 
class  decryption_error
 
class  DIM
 
class  Directory
 Class representing a directory in a file system. More...
 
class  DynamicState
 DynamicState represents a MySQLRouter dynamic state object. More...
 
class  FakeRandomGenerator
 
class  invalid_master_keyfile
 
class  IPAddress
 IPAddress for both v4 and v6. More...
 
class  IPv4Address
 IPv4Address for IP version 4 addresses. More...
 
class  IPv6Address
 IPv6Address for IP version 6 addresses. More...
 
class  Keyring
 Keyring interface. More...
 
class  KeyringFile
 KeyringFile class. More...
 
class  KeyringMemory
 KeyringMemory class. More...
 
class  Loader
 
class  LoaderConfig
 Configuration file handler for the loader. More...
 
class  LogReopenThread
 
class  MasterKeyFile
 
class  MPMCQueueMS2Lock
 a unbounded multi-producer multi-consumer queue. More...
 
class  MPSCQueueDV
 a unbounded multi-producer single-consumer queue. More...
 
struct  mysql_router_thread_handle
 
class  MySQLRouterThread
 MySQLRouterThread provides higher level interface to managing threads. More...
 
class  Path
 Class representing a path in a file system. More...
 
class  PluginFuncEnv
 PluginFuncEnv object. More...
 
class  PluginThreads
 
class  ProcessLauncher
 
class  RandomGenerator
 
class  RandomGeneratorInterface
 
class  Range
 Convenience class for handling iterator range. More...
 
class  Resolver
 
class  SocketOperations
 This class provides a "real" (not mock) implementation. More...
 
class  SocketOperationsBase
 Base class to allow multiple SocketOperations implementations (at least one "real" and one mock for testing purposes) More...
 
class  SpawnedProcess
 an alive, spawned process More...
 
class  syntax_error
 Exception thrown for syntax errors. More...
 
class  TCPAddress
 Defines an IP address with port number
More...
 
class  UniquePtr
 
class  WaitingQueueAdaptor
 provide waiting pop and push operator to thread-safe queues. More...
 

Typedefs

using JsonAllocator = rapidjson::CrtAllocator
 
using JsonValue = rapidjson::GenericValue< rapidjson::UTF8<>, JsonAllocator >
 
using perm_mode = mode_t
 
template<typename T >
using MPMCQueue = MPMCQueueMS2Lock< T >
 
template<typename T >
using WaitingMPMCQueue = WaitingQueueAdaptor< MPMCQueue< T > >
 
template<typename T >
using MPSCQueue = MPSCQueueDV< T >
 
template<typename T >
using WaitingMPSCQueue = WaitingQueueAdaptor< MPSCQueue< T > >
 
typedef pthread_t mysql_router_thread_t
 
typedef pthread_attr_t mysql_router_thread_attr_t
 
typedef void *(* my_start_routine) (void *)
 
using socket_t = int
 

Enumerations

enum  option_errc { option_errc::empty = 1, option_errc::not_found }
 

Functions

std::string HARNESS_EXPORT get_strerror (int err)
 Wrapper for thread safe function returning error string. More...
 
void HARNESS_EXPORT rename_thread (const char thread_name[16])
 Rename a thread (useful for debugging purposes). More...
 
const HARNESS_EXPORT std::string & truncate_string (const std::string &input, size_t max_len=80)
 Return a truncated version of input string (fast version) More...
 
HARNESS_EXPORT std::string truncate_string_r (const std::string &input, size_t max_len=80)
 Return a truncated version of input string (reentrant version) More...
 
template<class InputIt >
void serial_comma (std::ostream &out, InputIt start, InputIt finish, const std::string &delim="and")
 Emit a range of elements using the serial comma. More...
 
template<class InputIt >
std::string serial_comma (InputIt start, InputIt finish, const std::string &delim="and")
 Returns string containing list of the elements using the serial comma. More...
 
template<class InputIt >
std::string list_elements (InputIt start, InputIt finish, const std::string &delim=",")
 Returns string containing list of the elements separated by selected delimiter. More...
 
template<class Collection >
std::string list_elements (Collection collection, const std::string &delim=",")
 Returns string containing list of the elements separated by selected delimiter. More...
 
bool HARNESS_EXPORT is_valid_hostname (const char *hostname)
 A simple hostname validator. More...
 
HARNESS_EXPORT bool init_keyring (const std::string &keyring_file_path, const std::string &master_key_path, bool create_if_needed)
 Initialize an instance of a keyring to be used in the application from the contents of a file, using the given master key file. More...
 
HARNESS_EXPORT bool init_keyring_with_key (const std::string &keyring_file_path, const std::string &master_key, bool create_if_needed)
 Initialize an instance of a keyring to be used in the application from the contents of a file, using the given master key. More...
 
HARNESS_EXPORT void flush_keyring ()
 Saves the keyring contents to disk. More...
 
HARNESS_EXPORT Keyringget_keyring () noexcept
 Gets a previously initialized singleton instance of the keyring. More...
 
HARNESS_EXPORT void reset_keyring () noexcept
 Clears the keyring singleton. More...
 
const std::error_category & option_category () noexcept
 
std::error_code make_error_code (option_errc e) noexcept
 
HARNESS_EXPORT int delete_dir (const std::string &dir) noexcept
 Removes a directory. More...
 
HARNESS_EXPORT int delete_file (const std::string &path) noexcept
 Removes a file. More...
 
HARNESS_EXPORT int delete_dir_recursive (const std::string &dir) noexcept
 Removes directory and all its contents. More...
 
HARNESS_EXPORT std::string get_tmp_dir (const std::string &name="router")
 Creates a temporary directory with partially-random name and returns its path. More...
 
HARNESS_EXPORT std::string get_plugin_dir (const std::string &runtime_dir)
 
HARNESS_EXPORT std::string get_tests_data_dir (const std::string &runtime_dir)
 
HARNESS_EXPORT int mkdir (const std::string &dir, perm_mode mode, bool recursive=false)
 Creates a directory *. More...
 
void HARNESS_EXPORT make_file_public (const std::string &file_name)
 Changes file access permissions to be fully accessible by all users. More...
 
void HARNESS_EXPORT make_file_private (const std::string &file_name, const bool read_only_for_local_service=true)
 Changes file access permissions to be accessible only by a limited set of users. More...
 
void HARNESS_EXPORT check_file_access_rights (const std::string &file_name)
 Verifies access permissions of a file. More...
 
HARNESS_EXPORT std::vector< std::string > split_string (const std::string &data, const char delimiter, bool allow_empty=true)
 Splits a string using a delimiter. More...
 
HARNESS_EXPORT void left_trim (std::string &str)
 Removes leading whitespaces from the string. More...
 
HARNESS_EXPORT void right_trim (std::string &str)
 Removes trailing whitespaces from the string. More...
 
HARNESS_EXPORT void trim (std::string &str)
 Removes both leading and trailing whitespaces from the string. More...
 
template<class Container >
std::string join (Container cont, const std::string &delim)
 join elements of an container into a string seperated by a delimiter. More...
 
static const std::string & truncate_string_backend (const std::string &input, std::string &output, size_t max_len)
 
static bool isident (const char ch)
 
static void inplace_lower (std::string *str)
 
static std::string lower (std::string str)
 
static void check_option (const std::string &str)
 
int mkdir_wrapper (const std::string &dir, perm_mode mode)
 
std::unique_ptr< SECURITY_DESCRIPTOR, decltype(&free)> get_security_descriptor (const std::string &file_name)
 
std::ostream & operator<< (std::ostream &out, Path::FileType type)
 
int mkdir_recursive (const Path &path, perm_mode mode)
 
static void throwing_chmod (const std::string &file_name, mode_t mask)
 Sets access permissions for a file. More...
 
static void verify_file_permissions (const std::string &file_name)
 
static std::pair< std::string, std::string > get_master_key (MasterKeyFile &mkf, const std::string &keyring_file_path, bool create_if_needed)
 Gets the master_key for the specified keyring_file from the master key store. More...
 
const AppInfo * get_app_info (const PluginFuncEnv *env) noexcept
 
const ConfigSectionget_config_section (const PluginFuncEnv *env) noexcept
 
bool is_running (const PluginFuncEnv *env) noexcept
 
bool wait_for_stop (const PluginFuncEnv *env, uint32_t milliseconds) noexcept
 
void clear_running (PluginFuncEnv *env) noexcept
 
void set_error (PluginFuncEnv *env, ErrorType error_type, const char *fmt,...) noexcept
 
template<class T >
value_or (T a, T b)
 If a isn't set, return b. More...
 
static void call_plugin_function (PluginFuncEnv *env, std::exception_ptr &eptr, void(*fptr)(PluginFuncEnv *), const char *fnc_name, const char *plugin_name, const char *plugin_key=nullptr) noexcept
 
static int mysql_router_thread_attr_init (mysql_router_thread_attr_t *attr)
 
static int mysql_router_thread_attr_setstacksize (mysql_router_thread_attr_t *attr, size_t stacksize)
 
static int mysql_router_thread_attr_setdetachstate (mysql_router_thread_attr_t *attr, int detachstate)
 
static bool mysql_router_thread_started (const mysql_router_thread_handle *thread)
 checks if thread pointed by thread was started More...
 
static bool mysql_router_thread_joinable (const mysql_router_thread_attr_t *attr)
 checks if thread pointed by attr is joinable More...
 
int mysql_router_thread_create (mysql_router_thread_handle *thread, const mysql_router_thread_attr_t *attr, my_start_routine func, void *arg)
 
int mysql_router_thread_join (mysql_router_thread_handle *thread, void **value_ptr)
 
bool operator== (const IPAddress &a, const IPAddress &b)
 
static std::error_code last_error_code () noexcept
 
std::vector< string > split_string (const string &data, const char delimiter, bool allow_empty)
 
void left_trim (string &str)
 
void right_trim (string &str)
 
void trim (string &str)
 

Variables

static const int kMaxKeyringKeyLength = 255
 
const HARNESS_EXPORT perm_mode kStrictDirectoryPerm = S_IRWXU
 
static const size_t kDefaultStackSizeInKiloBytes = 1024
 
constexpr socket_t kInvalidSocket = -1
 
static std::unique_ptr< KeyringFileg_keyring
 
static std::string g_keyring_file_path
 
static std::string g_keyring_key
 
static const unsigned kKeyLength = 32
 
static const std::array< char, 5 > kMasterKeyFileSignature
 
constexpr auto kAesMode = my_aes_256_cbc
 
static constexpr unsigned char kAesIv []
 
constexpr auto kWaitPidCheckInterval = std::chrono::milliseconds(10)
 
constexpr auto kTerminateWaitInterval = std::chrono::seconds(10)
 

Typedef Documentation

◆ JsonAllocator

using mysql_harness::JsonAllocator = typedef rapidjson::CrtAllocator

◆ JsonValue

using mysql_harness::JsonValue = typedef rapidjson::GenericValue<rapidjson::UTF8<>, JsonAllocator>

◆ MPMCQueue

template<typename T >
using mysql_harness::MPMCQueue = typedef MPMCQueueMS2Lock<T>

◆ MPSCQueue

template<typename T >
using mysql_harness::MPSCQueue = typedef MPSCQueueDV<T>

◆ my_start_routine

typedef void*(* mysql_harness::my_start_routine) (void *)

◆ mysql_router_thread_attr_t

◆ mysql_router_thread_t

◆ perm_mode

using mysql_harness::perm_mode = typedef mode_t

◆ socket_t

using mysql_harness::socket_t = typedef int

◆ WaitingMPMCQueue

template<typename T >
using mysql_harness::WaitingMPMCQueue = typedef WaitingQueueAdaptor<MPMCQueue<T> >

◆ WaitingMPSCQueue

template<typename T >
using mysql_harness::WaitingMPSCQueue = typedef WaitingQueueAdaptor<MPSCQueue<T> >

Enumeration Type Documentation

◆ option_errc

Enumerator
empty 
not_found 

Function Documentation

◆ call_plugin_function()

static void mysql_harness::call_plugin_function ( PluginFuncEnv env,
std::exception_ptr &  eptr,
void(*)(PluginFuncEnv *)  fptr,
const char *  fnc_name,
const char *  plugin_name,
const char *  plugin_key = nullptr 
)
staticnoexcept

◆ check_file_access_rights()

void mysql_harness::check_file_access_rights ( const std::string &  file_name)

Verifies access permissions of a file.

On Unix systems it throws if file's permissions differ from 600. On Windows it throws if file can be accessed by Everyone group.

Parameters
[in]file_nameFile to be verified.
Exceptions
std::exceptionFile access rights are too permissive or an error occurred.
std::system_errorOS and/or filesystem doesn't support file permissions.

◆ check_option()

static void mysql_harness::check_option ( const std::string &  str)
static

◆ clear_running()

void mysql_harness::clear_running ( PluginFuncEnv env)
noexcept

◆ flush_keyring()

void mysql_harness::flush_keyring ( )

Saves the keyring contents to disk.

◆ get_app_info()

const AppInfo* mysql_harness::get_app_info ( const PluginFuncEnv env)
noexcept

◆ get_config_section()

const ConfigSection* mysql_harness::get_config_section ( const PluginFuncEnv env)
noexcept

◆ get_keyring()

Keyring * mysql_harness::get_keyring ( )
noexcept

Gets a previously initialized singleton instance of the keyring.

◆ get_master_key()

static std::pair<std::string, std::string> mysql_harness::get_master_key ( MasterKeyFile mkf,
const std::string &  keyring_file_path,
bool  create_if_needed 
)
static

Gets the master_key for the specified keyring_file from the master key store.

If the master key store file does not exist, it will be created along with a new master_key, which will be stored and also returned. If the master key store already exists, but does not have an entry for the master key, it will be generated and then stored.

Returns the master_key and the scramble for the master_key

◆ get_plugin_dir()

std::string mysql_harness::get_plugin_dir ( const std::string &  runtime_dir)

◆ get_security_descriptor()

std::unique_ptr<SECURITY_DESCRIPTOR, decltype(&free)> mysql_harness::get_security_descriptor ( const std::string &  file_name)

◆ get_strerror()

std::string mysql_harness::get_strerror ( int  err)

Wrapper for thread safe function returning error string.

Parameters
errerror number
Returns
string describing the error

◆ get_tests_data_dir()

HARNESS_EXPORT std::string mysql_harness::get_tests_data_dir ( const std::string &  runtime_dir)

◆ init_keyring()

bool mysql_harness::init_keyring ( const std::string &  keyring_file_path,
const std::string &  master_key_path,
bool  create_if_needed 
)

Initialize an instance of a keyring to be used in the application from the contents of a file, using the given master key file.

Parameters
keyring_file_pathpath to the file where keyring is stored
master_key_pathpath to the file keyring master keys are stored
create_if_neededcreates the keyring if it doesn't exist yet
Returns
false if the keyring had to be created

◆ init_keyring_with_key()

bool mysql_harness::init_keyring_with_key ( const std::string &  keyring_file_path,
const std::string &  master_key,
bool  create_if_needed 
)

Initialize an instance of a keyring to be used in the application from the contents of a file, using the given master key.

Parameters
keyring_file_pathpath to the file where keyring is stored
master_keymaster key for the keyring
create_if_neededcreates the keyring if it doesn't exist yet
Returns
false if the keyring had to be created

◆ inplace_lower()

static void mysql_harness::inplace_lower ( std::string *  str)
static

◆ is_running()

bool mysql_harness::is_running ( const PluginFuncEnv env)
noexcept

◆ is_valid_hostname()

bool mysql_harness::is_valid_hostname ( const char *  hostname)

A simple hostname validator.

WARNING! This is a very simple validator, it does not handle all cornercases correctly.

This validator was quickly written, meant as a quick filter for obvious ill-formed hostnames. We chose to err on the side of being too permissive rather than too strict, therefore it can produce false positives, but hopefully will not produce false negatives.

Parameters
hostnameHostname or IP of a host
Returns
false if hostname is invalid, true if it's (possibly) valid

◆ isident()

static bool mysql_harness::isident ( const char  ch)
static

◆ join()

template<class Container >
std::string mysql_harness::join ( Container  cont,
const std::string &  delim 
)

join elements of an container into a string seperated by a delimiter.

Container MUST:

  • have .begin() and end()
  • iterator must be ForwardIterator + InputIterator
  • value_type must be appendable to std::string

should work with:

  • std::vector<const char *|stdstring>
  • std::array<const char *|stdstring, N>
  • std::list<const char *|stdstring>
Parameters
conta container
delimdelimiter
Returns
string of elements of container seperated by delim

◆ last_error_code()

static std::error_code mysql_harness::last_error_code ( )
staticnoexcept

◆ left_trim() [1/2]

HARNESS_EXPORT void mysql_harness::left_trim ( std::string &  str)

Removes leading whitespaces from the string.

Parameters
strthe string to be trimmed

◆ left_trim() [2/2]

void mysql_harness::left_trim ( string &  str)

◆ list_elements() [1/2]

template<class Collection >
std::string mysql_harness::list_elements ( Collection  collection,
const std::string &  delim = "," 
)

Returns string containing list of the elements separated by selected delimiter.

To return a list of the first five prime numbers as "The first five prime numbers are 2, 3, 5, 7, 11":

std::vector<int> primes{2, 3, 5, 7, 11};
std::cout << "The first five prime numbers are "
<< list_elements(primes) << std::endl;
Parameters
collectionCollection of the elements to output.
delimDelimiter to use. Defaults to ",".
Returns
string containing list of the elements

◆ list_elements() [2/2]

template<class InputIt >
std::string mysql_harness::list_elements ( InputIt  start,
InputIt  finish,
const std::string &  delim = "," 
)

Returns string containing list of the elements separated by selected delimiter.

To return a list of the first five prime numbers as "The first five prime numbers are 2, 3, 5, 7, 11":

std::vector<int> primes{2, 3, 5, 7, 11};
std::cout << "The first five prime numbers are "
<< list_elements(primes.begin(), primes.end()) << std::endl;
Parameters
startInput iterator to start of range.
finishInput iterator to one-after-end of range.
delimDelimiter to use. Defaults to ",".
Returns
string containing list of the elements

◆ lower()

static std::string mysql_harness::lower ( std::string  str)
static

◆ make_error_code()

std::error_code mysql_harness::make_error_code ( option_errc  e)
inlinenoexcept

◆ make_file_private()

void mysql_harness::make_file_private ( const std::string &  file_name,
const bool  read_only_for_local_service = true 
)

Changes file access permissions to be accessible only by a limited set of users.

On Unix, the function sets file permission mask to 600. On Windows, all permissions to this file are removed for Everyone group, LocalService account gets read (and optionally write) access.

Parameters
[in]file_nameFile name.
[in]read_only_for_local_serviceWeather the LocalService user on Windows should get only the read access (if false will grant write access too). Not used on non-Windows.
Exceptions
std::exceptionFailed to change file permissions.

◆ make_file_public()

void mysql_harness::make_file_public ( const std::string &  file_name)

Changes file access permissions to be fully accessible by all users.

On Unix, the function sets file permission mask to 777. On Windows, Everyone group is granted full access to the file.

Parameters
[in]file_nameFile name.
Exceptions
std::exceptionFailed to change file permissions.

◆ mkdir()

int mysql_harness::mkdir ( const std::string &  dir,
perm_mode  mode,
bool  recursive = false 
)

Creates a directory *.

Parameters
dirname (or path) of the directory to create
modepermission mode for the created directory
recursiveif true then immitated unix mkdir -p recursively creating parent directories if needed
Return values
0operation succeeded
-1operation failed because of wrong parameters
>0 errno for failure to mkdir() system call

◆ mkdir_recursive()

int mysql_harness::mkdir_recursive ( const Path path,
perm_mode  mode 
)

◆ mkdir_wrapper()

int mysql_harness::mkdir_wrapper ( const std::string &  dir,
perm_mode  mode 
)

◆ mysql_router_thread_attr_init()

static int mysql_harness::mysql_router_thread_attr_init ( mysql_router_thread_attr_t attr)
inlinestatic

◆ mysql_router_thread_attr_setdetachstate()

static int mysql_harness::mysql_router_thread_attr_setdetachstate ( mysql_router_thread_attr_t attr,
int  detachstate 
)
inlinestatic

◆ mysql_router_thread_attr_setstacksize()

static int mysql_harness::mysql_router_thread_attr_setstacksize ( mysql_router_thread_attr_t attr,
size_t  stacksize 
)
inlinestatic

◆ mysql_router_thread_create()

int mysql_harness::mysql_router_thread_create ( mysql_router_thread_handle thread,
const mysql_router_thread_attr_t attr,
my_start_routine  func,
void *  arg 
)

◆ mysql_router_thread_join()

int mysql_harness::mysql_router_thread_join ( mysql_router_thread_handle thread,
void **  value_ptr 
)

◆ mysql_router_thread_joinable()

static bool mysql_harness::mysql_router_thread_joinable ( const mysql_router_thread_attr_t attr)
inlinestatic

checks if thread pointed by attr is joinable

Exceptions
std::runtime_errorif cannot check if thread is joinable

◆ mysql_router_thread_started()

static bool mysql_harness::mysql_router_thread_started ( const mysql_router_thread_handle thread)
inlinestatic

checks if thread pointed by thread was started

◆ operator<<()

std::ostream& mysql_harness::operator<< ( std::ostream &  out,
Path::FileType  type 
)

◆ operator==()

bool mysql_harness::operator== ( const IPAddress a,
const IPAddress b 
)
Returns
true if IP addresses are equal

◆ option_category()

const std::error_category& mysql_harness::option_category ( )
inlinenoexcept

◆ rename_thread()

void mysql_harness::rename_thread ( const char  thread_name[16])

Rename a thread (useful for debugging purposes).

Parameters
thread_namethread name, 15 chars max

◆ reset_keyring()

void mysql_harness::reset_keyring ( )
noexcept

Clears the keyring singleton.

◆ right_trim() [1/2]

HARNESS_EXPORT void mysql_harness::right_trim ( std::string &  str)

Removes trailing whitespaces from the string.

Parameters
strthe string to be trimmed

◆ right_trim() [2/2]

void mysql_harness::right_trim ( string &  str)

◆ serial_comma() [1/2]

template<class InputIt >
std::string mysql_harness::serial_comma ( InputIt  start,
InputIt  finish,
const std::string &  delim = "and" 
)

Returns string containing list of the elements using the serial comma.

This function can be used to output a range of elements using a serial comma (also known as the Oxford comma). To return a list of the first five prime numbers as "The first five prime numbers are 2, 3, 5, 7, and 11":

std::vector<int> primes{2, 3, 5, 7, 11};
std::cout << "The first five prime numbers are "
<< serial_comma(primes.begin(), primes.end()) << std::endl;
Parameters
startInput iterator to start of range.
finishInput iterator to one-after-end of range.
delimDelimiter to use. Defaults to "and".
Returns
string containing list of the elements

◆ serial_comma() [2/2]

template<class InputIt >
void mysql_harness::serial_comma ( std::ostream &  out,
InputIt  start,
InputIt  finish,
const std::string &  delim = "and" 
)

Emit a range of elements using the serial comma.

This function can be used to output a range of elements using a serial comma (also known as the Oxford comma). To emit a list of the first five prime numbers as "The first five prime numbers are 2, 3, 5, 7, and 11":

std::vector<int> primes{2, 3, 5, 7, 11};
std::cout << "The first five prime numbers are ";
serial_comma(std::cout, primes.begin(), primes.end());
std::cout << std::endl;
Parameters
outOutput stream
startInput iterator to start of range.
finishInput iterator to one-after-end of range.
delimDelimiter to use. Defaults to "and".

◆ set_error()

void mysql_harness::set_error ( PluginFuncEnv env,
ErrorType  error_type,
const char *  fmt,
  ... 
)
noexcept

◆ split_string() [1/2]

HARNESS_EXPORT std::vector<std::string> mysql_harness::split_string ( const std::string &  data,
const char  delimiter,
bool  allow_empty = true 
)

Splits a string using a delimiter.

Splits a string using the given delimiter. When allow_empty is true (default), tokens can be empty, and will be included as empty in the result.

Parameters
dataa string to split
delimitera char used as delimiter
allow_emptywhether to allow empty tokens or not (default true)
Returns
std::vector<string> containing tokens

◆ split_string() [2/2]

std::vector<string> mysql_harness::split_string ( const string &  data,
const char  delimiter,
bool  allow_empty 
)

◆ throwing_chmod()

static void mysql_harness::throwing_chmod ( const std::string &  file_name,
mode_t  mask 
)
static

Sets access permissions for a file.

Parameters
[in]file_nameFile name.
[in]maskAccess permission mask.
Exceptions
std::exceptionFailed to change file permissions.

◆ trim() [1/2]

HARNESS_EXPORT void mysql_harness::trim ( std::string &  str)

Removes both leading and trailing whitespaces from the string.

Parameters
strthe string to be trimmed

◆ trim() [2/2]

void mysql_harness::trim ( string &  str)

◆ truncate_string()

const std::string & mysql_harness::truncate_string ( const std::string &  input,
size_t  max_len = 80 
)

Return a truncated version of input string (fast version)

WARNING! This function is optimised for speed, but see note below for use restrictions. If these are a problem, use truncate_string_r() instead.

This function returns a refernce to the input string if input.size() <= max_len, otherwise it returns a reference to a truncated copy of input string.

Parameters
inputinput text
max_lenmaximum length after truncation
Returns
const reference to truncated string
Note
This function may return a reference to a string allocated on thread-local storage. Therefore, the resulting string reference is only valid until another call to this function is made from caller's thread (other threads calling this function have no impact), and by the same token, dereferencing it outside of the caller's thread may lead to a race. If your use case violates these limitations, you should use truncate_string_r() instead to ensure safety.

◆ truncate_string_backend()

static const std::string& mysql_harness::truncate_string_backend ( const std::string &  input,
std::string &  output,
size_t  max_len 
)
inlinestatic

◆ truncate_string_r()

std::string mysql_harness::truncate_string_r ( const std::string &  input,
size_t  max_len = 80 
)

Return a truncated version of input string (reentrant version)

This is a safe version of truncate_string(), which lifts its use restrictions by always returning a copy of result string. Please see documentation of truncate_string() for more information.

◆ value_or()

template<class T >
T mysql_harness::value_or ( a,
b 
)

If a isn't set, return b.

like ?:, but ensures that b is always evaluated first.

◆ verify_file_permissions()

static void mysql_harness::verify_file_permissions ( const std::string &  file_name)
static

◆ wait_for_stop()

bool mysql_harness::wait_for_stop ( const PluginFuncEnv env,
uint32_t  milliseconds 
)
noexcept

Variable Documentation

◆ g_keyring

std::unique_ptr<KeyringFile> mysql_harness::g_keyring
static

◆ g_keyring_file_path

std::string mysql_harness::g_keyring_file_path
static

◆ g_keyring_key

std::string mysql_harness::g_keyring_key
static

◆ kAesIv

constexpr unsigned char mysql_harness::kAesIv[]
staticconstexpr
Initial value:
= {0x39, 0x62, 0x9f, 0x52, 0x7f, 0x76,
0x9a, 0xae, 0xcd, 0xca, 0xf7, 0x04,
0x65, 0x8e, 0x5d, 0x88}

◆ kAesMode

constexpr auto mysql_harness::kAesMode = my_aes_256_cbc
constexpr

◆ kDefaultStackSizeInKiloBytes

const size_t mysql_harness::kDefaultStackSizeInKiloBytes = 1024
static

◆ kInvalidSocket

constexpr socket_t mysql_harness::kInvalidSocket = -1
constexpr

◆ kKeyLength

const unsigned mysql_harness::kKeyLength = 32
static

◆ kMasterKeyFileSignature

const std::array<char, 5> mysql_harness::kMasterKeyFileSignature
static
Initial value:
= {'M', 'R', 'K', 'F',
'\0'}

◆ kMaxKeyringKeyLength

const int mysql_harness::kMaxKeyringKeyLength = 255
static

◆ kStrictDirectoryPerm

const perm_mode mysql_harness::kStrictDirectoryPerm = S_IRWXU

◆ kTerminateWaitInterval

constexpr auto mysql_harness::kTerminateWaitInterval = std::chrono::seconds(10)
constexpr

◆ kWaitPidCheckInterval

constexpr auto mysql_harness::kWaitPidCheckInterval = std::chrono::milliseconds(10)
constexpr
mysql_harness::list_elements
std::string list_elements(InputIt start, InputIt finish, const std::string &delim=",")
Returns string containing list of the elements separated by selected delimiter.
Definition: common.h:176
mysql_harness::serial_comma
void serial_comma(std::ostream &out, InputIt start, InputIt finish, const std::string &delim="and")
Emit a range of elements using the serial comma.
Definition: common.h:110