USBGuard
Software framework that protects your computer against rogue USB devices by implementing basic whitelisting and blacklisting capabilities.
|
Serves as a config file parser. More...
#include <KeyValueParser.hpp>
Public Member Functions | |
KeyValueParser (const std::vector< std::string > &v, bool case_sensitive, bool validate_keys) | |
Constructs object of KeyValueParser. More... | |
KeyValueParser (const std::vector< std::string > &v, const std::string &sep, bool case_sensitive, bool validate_keys) | |
Constructs object of KeyValueParser. More... | |
~KeyValueParser () | |
Default destructor of KeyValueParser. | |
std::pair< std::string, std::string > | parseLine (std::string &str) |
Retreives key-value pair from given string. More... | |
void | parseStream (std::istream &stream) |
Parses given stream for key-value pairs. More... | |
std::map< std::string, std::string > | getMap () |
Retreives map of key-value pairs. More... | |
void | viewConfig () |
Prints key-value separator and known key names into the log. | |
Serves as a config file parser.
usbguard::KeyValueParser::KeyValueParser | ( | const std::vector< std::string > & | v, |
bool | case_sensitive, | ||
bool | validate_keys | ||
) |
Constructs object of KeyValueParser.
v | Vector of known key names. |
case_sensitive | Determines if key names should be parsed as case sensitive. If enabled, then all key names in vector v must be upper case. |
validate_keys | When enabled, every key that is parsed must be known (present in vector of known key names). |
usbguard::KeyValueParser::KeyValueParser | ( | const std::vector< std::string > & | v, |
const std::string & | sep, | ||
bool | case_sensitive, | ||
bool | validate_keys | ||
) |
Constructs object of KeyValueParser.
v | Vector of known key names. |
sep | Separator of keys and values in key-value pairs. |
case_sensitive | Determines if key names should be parsed as case sensitive. If enabled, then all key names in vector v must be upper case. |
validate_keys | When enabled, every key that is parsed must be known (present in vector of known key names). |
std::map< std::string, std::string > usbguard::KeyValueParser::getMap | ( | ) |
Retreives map of key-value pairs.
This map is filled by function parseStream().
std::pair< std::string, std::string > usbguard::KeyValueParser::parseLine | ( | std::string & | str | ) |
Retreives key-value pair from given string.
This function serves to parse single line of config file and return key-value pair. If given string does not contain valid key-value pair, then exception is thrown.
str | String to be parsed for key-value pair. |
void usbguard::KeyValueParser::parseStream | ( | std::istream & | stream | ) |
Parses given stream for key-value pairs.
Given stream is parsed line by line using function parseLine. Lines that start with #
are ignored. Parsed key-value pairs can be retreived using function getMap().
stream | Stream to be parsed. |