USBGuard
Software framework that protects your computer against rogue USB devices by implementing basic whitelisting and blacklisting capabilities.
Public Member Functions | List of all members
usbguard::KeyValueParser Class Reference

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.
 

Detailed Description

Serves as a config file parser.

Constructor & Destructor Documentation

◆ KeyValueParser() [1/2]

usbguard::KeyValueParser::KeyValueParser ( const std::vector< std::string > &  v,
bool  case_sensitive,
bool  validate_keys 
)

Constructs object of KeyValueParser.

Parameters
vVector of known key names.
case_sensitiveDetermines if key names should be parsed as case sensitive. If enabled, then all key names in vector v must be upper case.
validate_keysWhen enabled, every key that is parsed must be known (present in vector of known key names).

◆ KeyValueParser() [2/2]

usbguard::KeyValueParser::KeyValueParser ( const std::vector< std::string > &  v,
const std::string &  sep,
bool  case_sensitive,
bool  validate_keys 
)

Constructs object of KeyValueParser.

Parameters
vVector of known key names.
sepSeparator of keys and values in key-value pairs.
case_sensitiveDetermines if key names should be parsed as case sensitive. If enabled, then all key names in vector v must be upper case.
validate_keysWhen enabled, every key that is parsed must be known (present in vector of known key names).

Member Function Documentation

◆ getMap()

std::map< std::string, std::string > usbguard::KeyValueParser::getMap ( )

Retreives map of key-value pairs.

This map is filled by function parseStream().

See also
parseStream()
Returns
Map of key-value pairs

◆ parseLine()

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.

Parameters
strString to be parsed for key-value pair.
Returns
Key-value pair present in given string.

◆ parseStream()

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().

See also
parseLine()
getMap()
Parameters
streamStream to be parsed.

The documentation for this class was generated from the following files: