dodo
0.0.1
A C++ library to create containerized Linux services
|
Common and utility interfaces. More...
Data Structures | |
class | Application |
Red tape wrapper class for applications, from command line to services. More... | |
class | Bytes |
An array of Octets with size elements. More... | |
class | Cache |
Simple thread-safe Cache template for arbitrary Key-Value pairs. More... | |
class | Config |
Singleton interface to a (read-only) deployment configuration, combining data from the deployment configuration file, environment variables and some operating system attributes such as the CPU count, RAM and virtual memory size. More... | |
class | DataCrypt |
Interface to encrypt and decrypt Bytes data to/from a secure string. More... | |
class | DebugObject |
Interface to objects that support dumping their state to a string. More... | |
class | Exception |
An Exception is thrown in exceptional circumstances, and its occurrence should generally imply that the program should stop, as it has entered a state it was never designed to handle. More... | |
class | Logger |
A Logger interface. More... | |
class | Puts |
Helper class to write strings in stream format, eg. More... | |
class | StopWatch |
StopWatch timing class. More... | |
class | SystemError |
Linux system error primitive to provide a consistent interface to Linux error codes. More... | |
class | SystemException |
Descending from Exception, exceptions based on a dodo::common::SystemError code. More... | |
class | UnitTest |
Unit test assitence class. More... | |
Typedefs | |
typedef uint8_t | Octet |
Octet aka 'byte'. More... | |
Functions | |
bool | availableFileSpace (const std::string &path, size_t &avail) |
Return true when the free space could be determined, and set in avail. More... | |
std::string | bio2String (BIO *bio) |
Convert the data contents of an OpenSSL BIO to a std::string. More... | |
void | closeLibrary () |
Close the common library. More... | |
bool | directoryExists (const std::string &path) |
Return true when the directory exists. More... | |
bool | directoryWritable (const std::string &path) |
Return true when the directory exists and is writable to the caller. More... | |
void | dumpBinaryData (std::ostream &out, const std::string &s, size_t width) |
Dump binary data to a std::ostream. More... | |
std::vector< std::string > | escapedSplit (const std::string &src, std::set< char > escape, char delimiter=' ') |
Split a string into substrings by delimiter - unless the delimiter is escaped. More... | |
std::string | escapeJSON (const std::string &s) |
Escape a JSOn string. More... | |
bool | fileReadAccess (const std::string &path) |
Return true when the file exists and the calling user has read access. More... | |
bool | fileReadInt (const std::string &file, int &i) |
Read from a file, expecting it to contain a (signed) int. More... | |
std::string | fileReadString (const std::string &filename) |
Read the file as a single string. More... | |
std::vector< std::string > | fileReadStrings (const std::string &filename) |
Read the file as vector of strings. More... | |
std::vector< std::string > | fileReadStrings (const std::string &filename, const std::regex &exp) |
Read the file as vector of strings, return only regexp matches. More... | |
std::string | formatDateTimeUTC (const struct timeval &tv) |
Return a datetime string in UTC (2020-07-01T20:14:36.442929Z) More... | |
size_t | getFileSize (const std::string &path) |
Return the size of the file. More... | |
double | getSecondDiff (struct timeval &t1, struct timeval &t2) |
Return difference in seconds as a double. More... | |
std::string | getSSLErrors (char terminator) |
Get all OpenSSL errors as a single string, and clear their error state. More... | |
void | initLibrary () |
Initialize the common library. More... | |
std::vector< std::string > | split (const std::string &src, char delimiter=' ') |
Split a string into substrings. More... | |
std::string | strASCII (char c) |
Return ASCII representation of char. More... | |
size_t | writeSSLErrors (std::ostream &out, char terminator) |
Write OpenSSL errors occurred in this thread to ostream, and clear their error state. More... | |
template<typename T > | |
T | YAML_read_key (const YAML::Node &node, const std::string &key) |
Template function to check existence and read YAML values of arbitrary type. More... | |
template bool | YAML_read_key< bool > (const YAML::Node &, const std::string &) |
Instantiate template YAML_read_key for bool. More... | |
template double | YAML_read_key< double > (const YAML::Node &, const std::string &) |
Instantiate template YAML_read_key for double. More... | |
template int | YAML_read_key< int > (const YAML::Node &, const std::string &) |
Instantiate template YAML_read_key for int. More... | |
template long | YAML_read_key< long > (const YAML::Node &, const std::string &) |
Instantiate template YAML_read_key for long. More... | |
template size_t | YAML_read_key< size_t > (const YAML::Node &, const std::string &) |
Instantiate template YAML_read_key for size_t. More... | |
template std::string | YAML_read_key< std::string > (const YAML::Node &, const std::string &) |
Instantiate template YAML_read_key for std::string. More... | |
template uint16_t | YAML_read_key< uint16_t > (const YAML::Node &, const std::string &) |
Instantiate template YAML_read_key for uint16_t. More... | |
template unsigned int | YAML_read_key< unsigned int > (const YAML::Node &, const std::string &) |
Instantiate template YAML_read_key for unsigned int. More... | |
template<typename T > | |
T | YAML_read_key_default (const YAML::Node &node, const std::string &key, const T &default_value) |
Template function to check existence and read YAML values of arbitrary type. More... | |
template bool | YAML_read_key_default< bool > (const YAML::Node &, const std::string &, const bool &) |
Instantiate template YAML_read_key for bool. More... | |
template double | YAML_read_key_default< double > (const YAML::Node &, const std::string &, const double &) |
Instantiate template YAML_read_key for double. More... | |
template int | YAML_read_key_default< int > (const YAML::Node &, const std::string &, const int &) |
Instantiate template YAML_read_key for int. More... | |
template long | YAML_read_key_default< long > (const YAML::Node &, const std::string &, const long &) |
Instantiate template YAML_read_key for long. More... | |
template size_t | YAML_read_key_default< size_t > (const YAML::Node &, const std::string &, const size_t &) |
Instantiate template YAML_read_key for size_t. More... | |
template std::string | YAML_read_key_default< std::string > (const YAML::Node &, const std::string &, const std::string &) |
Instantiate template YAML_read_key for std::string. More... | |
template unsigned int | YAML_read_key_default< unsigned int > (const YAML::Node &, const std::string &, const unsigned int &) |
Instantiate template YAML_read_key for unsigned int. More... | |
Common and utility interfaces.
typedef uint8_t dodo::common::Octet |
bool dodo::common::availableFileSpace | ( | const std::string & | path, |
size_t & | avail | ||
) |
std::string dodo::common::bio2String | ( | BIO * | bio | ) |
Convert the data contents of an OpenSSL BIO to a std::string.
bio | The source BIO. |
Definition at line 132 of file util.cpp.
Referenced by dodo::network::X509Certificate::getIssuer(), dodo::network::X509CertificateSigningRequest::getSubject(), and dodo::network::X509Certificate::getSubject().
void dodo::common::closeLibrary | ( | ) |
Close the common library.
Definition at line 58 of file common.hpp.
Referenced by dodo::closeLibrary().
bool dodo::common::directoryExists | ( | const std::string & | path | ) |
Return true when the directory exists.
path | The path to the directory. |
Definition at line 230 of file util.cpp.
Referenced by dodo::common::Logger::getFileParams().
bool dodo::common::directoryWritable | ( | const std::string & | path | ) |
Return true when the directory exists and is writable to the caller.
path | The path to the directory. |
Definition at line 239 of file util.cpp.
Referenced by dodo::common::Logger::getFileParams().
void dodo::common::dumpBinaryData | ( | std::ostream & | out, |
const std::string & | s, | ||
size_t | width | ||
) |
Dump binary data to a std::ostream.
out | The std::stream to dump to. |
s | The char stream. |
width | The max character width of the output. |
Definition at line 105 of file util.cpp.
References strASCII().
|
inline |
Split a string into substrings by delimiter - unless the delimiter is escaped.
Passing ( 'one:two$:three', '$', ':' ) splits into ['one','two:three']. Passing ( 'one:t
', ':' ) splits into ['one','t$$wo','three']. So the escape character only has effect when followed by a delimiter, otherwise taken as input.
src | The string to split from. |
escape | The escape characters to use |
delimiter | The delimiter to use. |
Definition at line 157 of file util.hpp.
Referenced by dodo::network::X509Common::parseIdentity().
std::string dodo::common::escapeJSON | ( | const std::string & | s | ) |
bool dodo::common::fileReadAccess | ( | const std::string & | path | ) |
Return true when the file exists and the calling user has read access.
path | The path to the file. |
Definition at line 220 of file util.cpp.
Referenced by dodo::common::Application::detectHostType().
bool dodo::common::fileReadInt | ( | const std::string & | file, |
int & | i | ||
) |
Read from a file, expecting it to contain a (signed) int.
file | The file name. |
i | The int read. |
Definition at line 39 of file util.cpp.
Referenced by dodo::network::TCPListener::construct().
std::string dodo::common::fileReadString | ( | const std::string & | filename | ) |
Read the file as a single string.
Oops | when the file cannot be read. |
filename | the file to read from. |
Definition at line 161 of file util.cpp.
References throw_Exception.
Referenced by dodo::common::Config::checkConfig().
std::vector< std::string > dodo::common::fileReadStrings | ( | const std::string & | filename | ) |
Read the file as vector of strings.
Oops | when the file cannot be read. |
filename | the file to read from. |
Definition at line 170 of file util.cpp.
References throw_Exception.
Referenced by dodo::common::Application::detectHostType().
std::vector< std::string > dodo::common::fileReadStrings | ( | const std::string & | filename, |
const std::regex & | exp | ||
) |
Read the file as vector of strings, return only regexp matches.
Oops | when the file cannot be read. |
filename | the file to read from. |
exp | the regex that must match. |
Definition at line 183 of file util.cpp.
References throw_Exception.
std::string dodo::common::formatDateTimeUTC | ( | const struct timeval & | tv | ) |
Return a datetime string in UTC (2020-07-01T20:14:36.442929Z)
tv | The tv time struct. |
Definition at line 262 of file util.cpp.
Referenced by dodo::common::Logger::checkRotate(), and dodo::common::Logger::formatMessage().
size_t dodo::common::getFileSize | ( | const std::string & | path | ) |
Return the size of the file.
If the file does not exist or is otherwise inaccessible, returns 0.
path | The path of the file. |
Definition at line 256 of file util.cpp.
Referenced by dodo::common::Logger::checkRotate(), and dodo::common::Logger::getFileParams().
|
inline |
Return difference in seconds as a double.
t2 must be > t1 for the return value to be positive.
t1 | The earlier time. |
t2 | The later time. |
Definition at line 126 of file util.hpp.
Referenced by dodo::network::TCPServer::getIdleSeconds(), dodo::threads::Thread::getRunTime(), dodo::threads::Thread::getSnapDiffTime(), dodo::network::TCPListener::logStats(), and dodo::network::TCPServer::run().
std::string dodo::common::getSSLErrors | ( | char | terminator | ) |
Get all OpenSSL errors as a single string, and clear their error state.
terminator | The terminator character for a single error line. If 0, no character will be appended. |
Definition at line 154 of file util.cpp.
References writeSSLErrors().
Referenced by dodo::network::TLSSocket::accept(), dodo::network::TLSSocket::connect(), dodo::network::TLSContext::construct(), dodo::common::DataCrypt::decrypt(), dodo::common::DataCrypt::encrypt(), dodo::network::X509CertificateSigningRequest::getFingerPrint(), dodo::network::X509Certificate::getFingerPrint(), dodo::network::X509CertificateSigningRequest::loadPEM(), dodo::network::X509Certificate::loadPEM(), dodo::network::TLSContext::loadPEMIdentity(), dodo::network::TLSContext::loadPKCS12(), dodo::network::TLSSocket::receive(), dodo::network::TLSSocket::send(), dodo::network::TLSContext::setTrustPaths(), and dodo::network::TLSSocket::TLSSocket().
void dodo::common::initLibrary | ( | ) |
Initialize the common library.
Definition at line 48 of file common.hpp.
References throw_Exception.
Referenced by dodo::initLibrary().
|
inline |
Split a string into substrings.
src | The string to split from. |
delimiter | The delimiter to use. |
Definition at line 136 of file util.hpp.
Referenced by dodo::common::DataCrypt::decode(), and dodo::network::X509Common::parseIdentity().
std::string dodo::common::strASCII | ( | char | c | ) |
Return ASCII representation of char.
c | The char. |
Definition at line 50 of file util.cpp.
Referenced by dumpBinaryData().
size_t dodo::common::writeSSLErrors | ( | std::ostream & | out, |
char | terminator | ||
) |
Write OpenSSL errors occurred in this thread to ostream, and clear their error state.
out | The std::ostream to write to. |
terminator | The char to use to separate lines. |
Definition at line 140 of file util.cpp.
Referenced by getSSLErrors().
T dodo::common::YAML_read_key | ( | const YAML::Node & | node, |
const std::string & | key | ||
) |
Template function to check existence and read YAML values of arbitrary type.
The key-value pair must must exist under node.
node | The YAML::Node containing the key-value pair |
key | The YAML::Node name. |
common::Exception | when the node does not exist. |
Definition at line 276 of file util.cpp.
References throw_Exception.
template bool dodo::common::YAML_read_key< bool > | ( | const YAML::Node & | , |
const std::string & | |||
) |
Instantiate template YAML_read_key for bool.
Referenced by dodo::network::TLSContext::TLSContext().
template double dodo::common::YAML_read_key< double > | ( | const YAML::Node & | , |
const std::string & | |||
) |
Instantiate template YAML_read_key for double.
template int dodo::common::YAML_read_key< int > | ( | const YAML::Node & | , |
const std::string & | |||
) |
Instantiate template YAML_read_key for int.
template long dodo::common::YAML_read_key< long > | ( | const YAML::Node & | , |
const std::string & | |||
) |
Instantiate template YAML_read_key for long.
template size_t dodo::common::YAML_read_key< size_t > | ( | const YAML::Node & | , |
const std::string & | |||
) |
Instantiate template YAML_read_key for size_t.
template std::string dodo::common::YAML_read_key< std::string > | ( | const YAML::Node & | , |
const std::string & | |||
) |
Instantiate template YAML_read_key for std::string.
template uint16_t dodo::common::YAML_read_key< uint16_t > | ( | const YAML::Node & | , |
const std::string & | |||
) |
Instantiate template YAML_read_key for uint16_t.
template unsigned int dodo::common::YAML_read_key< unsigned int > | ( | const YAML::Node & | , |
const std::string & | |||
) |
Instantiate template YAML_read_key for unsigned int.
T dodo::common::YAML_read_key_default | ( | const YAML::Node & | node, |
const std::string & | key, | ||
const T & | default_value | ||
) |
Template function to check existence and read YAML values of arbitrary type.
The key-value pair must must exist under node.
node | The YAML::Node containing the key-value pair |
key | The YAML::Node name. |
default_value | The default value to assign when the key is missing |
template bool dodo::common::YAML_read_key_default< bool > | ( | const YAML::Node & | , |
const std::string & | , | ||
const bool & | |||
) |
Instantiate template YAML_read_key for bool.
Referenced by dodo::network::TCPListener::Params::Params().
template double dodo::common::YAML_read_key_default< double > | ( | const YAML::Node & | , |
const std::string & | , | ||
const double & | |||
) |
Instantiate template YAML_read_key for double.
Referenced by dodo::network::TCPListener::Params::Params().
template int dodo::common::YAML_read_key_default< int > | ( | const YAML::Node & | , |
const std::string & | , | ||
const int & | |||
) |
Instantiate template YAML_read_key for int.
Referenced by dodo::network::TCPListener::Params::Params().
template long dodo::common::YAML_read_key_default< long > | ( | const YAML::Node & | , |
const std::string & | , | ||
const long & | |||
) |
Instantiate template YAML_read_key for long.
template size_t dodo::common::YAML_read_key_default< size_t > | ( | const YAML::Node & | , |
const std::string & | , | ||
const size_t & | |||
) |
Instantiate template YAML_read_key for size_t.
Referenced by dodo::network::TCPListener::Params::Params().
template std::string dodo::common::YAML_read_key_default< std::string > | ( | const YAML::Node & | , |
const std::string & | , | ||
const std::string & | |||
) |
Instantiate template YAML_read_key for std::string.
template unsigned int dodo::common::YAML_read_key_default< unsigned int > | ( | const YAML::Node & | , |
const std::string & | , | ||
const unsigned int & | |||
) |
Instantiate template YAML_read_key for unsigned int.