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::ConfigFile Class Reference

Enables manipulation with the config file and its settings. More...

#include <ConfigFile.hpp>

Public Member Functions

 ConfigFile (const std::vector< std::string > &known_names=std::vector< std::string >())
 Constructs ConfigFile object. More...
 
 ~ConfigFile ()
 Destructs ConfigFile object. More...
 
void open (const std::string &path, bool readonly=false)
 Opens the config file. More...
 
void write ()
 Writes changes into config file. More...
 
void close ()
 Closes the config file. More...
 
void setSettingValue (const std::string &name, std::string &value)
 Sets value of given key to a given value. More...
 
bool hasSettingValue (const std::string &name) const
 Checks if the config file contains key with a given name. More...
 
const std::string & getSettingValue (const std::string &name) const
 Retreives value of the given key. More...
 

Detailed Description

Enables manipulation with the config file and its settings.

Constructor & Destructor Documentation

◆ ConfigFile()

usbguard::ConfigFile::ConfigFile ( const std::vector< std::string > &  known_names = std::vector<std::string>())

Constructs ConfigFile object.

Parameters
known_namesNames present in this vector will be considered as known key names in the config file. If this vector is empty, then any key name will be considered as known.

◆ ~ConfigFile()

usbguard::ConfigFile::~ConfigFile ( )
default

Destructs ConfigFile object.

Calls close() before destroying ConfigFile object.

See also
close()

Member Function Documentation

◆ close()

void usbguard::ConfigFile::close ( )

Closes the config file.

If any changes were made and config file was not opened as readonly, changes are written to the config file before stream is closed. If config file is not opened, nothing happens.

◆ getSettingValue()

const std::string & usbguard::ConfigFile::getSettingValue ( const std::string &  name) const

Retreives value of the given key.

Parameters
nameName of the key to search for.
Returns
Value that is assigned to a given key.

◆ hasSettingValue()

bool usbguard::ConfigFile::hasSettingValue ( const std::string &  name) const

Checks if the config file contains key with a given name.

Parameters
nameName of the key to search for.
Returns
True if config file contains key with a given name, false otherwise.

◆ open()

void usbguard::ConfigFile::open ( const std::string &  path,
bool  readonly = false 
)

Opens the config file.

Opens stream to config file and parses the config file.

Parameters
pathPath to the config file.
readonlyDetermines if the config file will be opened in readonly mode.

◆ setSettingValue()

void usbguard::ConfigFile::setSettingValue ( const std::string &  name,
std::string &  value 
)

Sets value of given key to a given value.

Parameters
nameName of the key to set.
valueValue to set.

◆ write()

void usbguard::ConfigFile::write ( )

Writes changes into config file.

If the config file was not opened or was opened as readonly, then this call will fail.


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