Liblinphone  5.3.0
Public Member Functions | Static Public Member Functions | List of all members
linphone::Config Class Reference

This object is used to manipulate a configuration file. More...

#include <config.hh>

Inheritance diagram for linphone::Config:

Public Member Functions

LINPHONECXX_PUBLIC Config (void *ptr, bool takeRef=true)
 
LINPHONECXX_PUBLIC _LinphoneConfig * cPtr ()
 
LINPHONECXX_PUBLIC bool isReadonly () const
 Indicates whether the LinphoneConfig object is readonly, in other words it has no file backend or file is opened without write permission. More...
 
LINPHONECXX_PUBLIC std::list< std::string > getSectionsNamesList ()
 Returns the list of sections' names in the LinphoneConfig. More...
 
LINPHONECXX_PUBLIC void cleanEntry (const std::string &section, const std::string &key)
 Removes entries for key,value in a section. More...
 
LINPHONECXX_PUBLIC void cleanSection (const std::string &section)
 Removes every pair of key,value in a section and remove the section. More...
 
LINPHONECXX_PUBLIC std::string dump () const
 Dumps the Config as INI into a buffer. More...
 
LINPHONECXX_PUBLIC std::string dumpAsXml () const
 Dumps the Config as XML into a buffer. More...
 
LINPHONECXX_PUBLIC bool getBool (const std::string &section, const std::string &key, bool defaultValue) const
 Retrieves a configuration item as a boolean, given its section, key, and default value. More...
 
LINPHONECXX_PUBLIC float getDefaultFloat (const std::string &section, const std::string &key, float defaultValue) const
 Retrieves a default configuration item as a float, given its section, key, and default value. More...
 
LINPHONECXX_PUBLIC int getDefaultInt (const std::string &section, const std::string &key, int defaultValue) const
 Retrieves a default configuration item as an integer, given its section, key, and default value. More...
 
LINPHONECXX_PUBLIC int64_t getDefaultInt64 (const std::string &section, const std::string &key, int64_t defaultValue) const
 Retrieves a default configuration item as a 64 bit integer, given its section, key, and default value. More...
 
LINPHONECXX_PUBLIC std::string getDefaultString (const std::string &section, const std::string &key, const std::string &defaultValue) const
 Retrieves a default configuration item as a string, given its section, key, and default value. More...
 
LINPHONECXX_PUBLIC float getFloat (const std::string &section, const std::string &key, float defaultValue) const
 Retrieves a configuration item as a float, given its section, key, and default value. More...
 
LINPHONECXX_PUBLIC int getInt (const std::string &section, const std::string &key, int defaultValue) const
 Retrieves a configuration item as an integer, given its section, key, and default value. More...
 
LINPHONECXX_PUBLIC int64_t getInt64 (const std::string &section, const std::string &key, int64_t defaultValue) const
 Retrieves a configuration item as a 64 bit integer, given its section, key, and default value. More...
 
LINPHONECXX_PUBLIC std::list< std::string > getKeysNamesList (const std::string &section)
 Returns the list of keys' names for a section in the LinphoneConfig. More...
 
LINPHONECXX_PUBLIC bool getOverwriteFlagForEntry (const std::string &section, const std::string &key) const
 Retrieves the overwrite flag for a config item. More...
 
LINPHONECXX_PUBLIC bool getOverwriteFlagForSection (const std::string &section) const
 Retrieves the overwrite flag for a config section. More...
 
LINPHONECXX_PUBLIC bool getRange (const std::string &section, const std::string &key, int *min, int *max, int defaultMin, int defaultMax) const
 Retrieves a configuration item as a range, given its section, key, and default min and max values. More...
 
LINPHONECXX_PUBLIC std::string getSectionParamString (const std::string &section, const std::string &key, const std::string &defaultValue) const
 Retrieves a section parameter item as a string, given its section and key. More...
 
LINPHONECXX_PUBLIC bool getSkipFlagForEntry (const std::string &section, const std::string &key) const
 Retrieves the skip flag for a config item. More...
 
LINPHONECXX_PUBLIC bool getSkipFlagForSection (const std::string &section) const
 Retrieves the skip flag for a config section. More...
 
LINPHONECXX_PUBLIC std::string getString (const std::string &section, const std::string &key, const std::string &defaultString) const
 Retrieves a configuration item as a string, given its section, key, and default value. More...
 
LINPHONECXX_PUBLIC std::list< std::string > getStringList (const std::string &section, const std::string &key, const std::list< std::string > &defaultList) const
 Retrieves a configuration item as a list of strings, given its section, key, and default value. More...
 
LINPHONECXX_PUBLIC int hasEntry (const std::string &section, const std::string &key) const
 Returns if a given section with a given key is present in the configuration. More...
 
LINPHONECXX_PUBLIC int hasSection (const std::string &section) const
 Returns if a given section is present in the configuration. More...
 
LINPHONECXX_PUBLIC std::string loadFromXmlFile (const std::string &filename)
 Reads a xml config file and fill the Config with the read config dynamic values. More...
 
LINPHONECXX_PUBLIC linphone::Status loadFromXmlString (const std::string &buffer)
 Reads a xml config string and fill the Config with the read config dynamic values. More...
 
LINPHONECXX_PUBLIC linphone::Status readFile (const std::string &filename)
 Reads a user config file and fill the Config with the read config values. More...
 
LINPHONECXX_PUBLIC bool relativeFileExists (const std::string &filename) const
 Check if given file name exists relatively to the current location. More...
 
LINPHONECXX_PUBLIC void reload ()
 Reload the config from the file.
 
LINPHONECXX_PUBLIC void setBool (const std::string &section, const std::string &key, bool value)
 Sets a boolean config item. More...
 
LINPHONECXX_PUBLIC void setFloat (const std::string &section, const std::string &key, float value)
 Sets a float config item. More...
 
LINPHONECXX_PUBLIC void setInt (const std::string &section, const std::string &key, int value)
 Sets an integer config item. More...
 
LINPHONECXX_PUBLIC void setInt64 (const std::string &section, const std::string &key, int64_t value)
 Sets a 64 bits integer config item. More...
 
LINPHONECXX_PUBLIC void setIntHex (const std::string &section, const std::string &key, int value)
 Sets an integer config item, but store it as hexadecimal. More...
 
LINPHONECXX_PUBLIC void setOverwriteFlagForEntry (const std::string &section, const std::string &key, bool value)
 Sets the overwrite flag for a config item (used when dumping config as xml) More...
 
LINPHONECXX_PUBLIC void setOverwriteFlagForSection (const std::string &section, bool value)
 Sets the overwrite flag for a config section (used when dumping config as xml) More...
 
LINPHONECXX_PUBLIC void setRange (const std::string &section, const std::string &key, int minValue, int maxValue)
 Sets a range config item. More...
 
LINPHONECXX_PUBLIC void setSkipFlagForEntry (const std::string &section, const std::string &key, bool value)
 Sets the skip flag for a config item (used when dumping config as xml) More...
 
LINPHONECXX_PUBLIC void setSkipFlagForSection (const std::string &section, bool value)
 Sets the skip flag for a config section (used when dumping config as xml) More...
 
LINPHONECXX_PUBLIC void setString (const std::string &section, const std::string &key, const std::string &value)
 Sets a string config item. More...
 
LINPHONECXX_PUBLIC void setStringList (const std::string &section, const std::string &key, const std::list< std::string > &value)
 Sets a string list config item. More...
 
LINPHONECXX_PUBLIC linphone::Status sync ()
 Writes the config file to disk. More...
 
LINPHONECXX_PUBLIC void writeRelativeFile (const std::string &filename, const std::string &data) const
 Write a string in a file placed relatively with the Linphone configuration file. More...
 

Static Public Member Functions

static LINPHONECXX_PUBLIC std::shared_ptr< linphone::ConfignewFromBuffer (const std::string &buffer)
 Instantiates a Config object from a user provided buffer. More...
 
static LINPHONECXX_PUBLIC std::shared_ptr< linphone::ConfignewWithFactory (const std::string &configFilename, const std::string &factoryConfigFilename)
 Instantiates a Config object from a user config file and a factory config file. More...
 

Detailed Description

This object is used to manipulate a configuration file.

The format of the configuration file is a .ini like format: Various types can be used: strings and lists of strings, integers, floats, booleans (written as 0 or 1) and range of integers. Usually a Core is initialized using two Config, one default (where configuration changes through API calls will be saved) and one named 'factory' which is read-only and overwrites any setting that may exists in the default one. It is also possible to use only one (either default or factory) or even none.

Member Function Documentation

◆ cleanEntry()

LINPHONECXX_PUBLIC void linphone::Config::cleanEntry ( const std::string &  section,
const std::string &  key 
)

Removes entries for key,value in a section.

Parameters
sectionthe section for which to clean the key entry
keythe key to clean

◆ cleanSection()

LINPHONECXX_PUBLIC void linphone::Config::cleanSection ( const std::string &  section)

Removes every pair of key,value in a section and remove the section.

Parameters
sectionthe section to clean

◆ dump()

LINPHONECXX_PUBLIC std::string linphone::Config::dump ( ) const

Dumps the Config as INI into a buffer.

Returns
The buffer that contains the config dump

◆ dumpAsXml()

LINPHONECXX_PUBLIC std::string linphone::Config::dumpAsXml ( ) const

Dumps the Config as XML into a buffer.

Returns
The buffer that contains the XML dump

◆ getBool()

LINPHONECXX_PUBLIC bool linphone::Config::getBool ( const std::string &  section,
const std::string &  key,
bool  defaultValue 
) const

Retrieves a configuration item as a boolean, given its section, key, and default value.

The default boolean value is returned if the config item isn't found.

Parameters
sectionThe section from which to retrieve a configuration item
keyThe name of the configuration item to retrieve
defaultValueThe default value to return if not found
Returns
the found value or default_value if not found.

◆ getDefaultFloat()

LINPHONECXX_PUBLIC float linphone::Config::getDefaultFloat ( const std::string &  section,
const std::string &  key,
float  defaultValue 
) const

Retrieves a default configuration item as a float, given its section, key, and default value.

The default float value is returned if the config item isn't found.

Parameters
sectionThe section from which to retrieve the default value
keyThe name of the configuration item to retrieve
defaultValueThe default value to return if not found
Returns
the found default value or default_value if not found.

◆ getDefaultInt()

LINPHONECXX_PUBLIC int linphone::Config::getDefaultInt ( const std::string &  section,
const std::string &  key,
int  defaultValue 
) const

Retrieves a default configuration item as an integer, given its section, key, and default value.

The default integer value is returned if the config item isn't found.

Parameters
sectionThe section from which to retrieve the default value
keyThe name of the configuration item to retrieve
defaultValueThe default value to return if not found
Returns
the found default value or default_value if not found.

◆ getDefaultInt64()

LINPHONECXX_PUBLIC int64_t linphone::Config::getDefaultInt64 ( const std::string &  section,
const std::string &  key,
int64_t  defaultValue 
) const

Retrieves a default configuration item as a 64 bit integer, given its section, key, and default value.

The default integer value is returned if the config item isn't found.

Parameters
sectionThe section from which to retrieve the default value
keyThe name of the configuration item to retrieve
defaultValueThe default value to return if not found
Returns
the found default value or default_value if not found.

◆ getDefaultString()

LINPHONECXX_PUBLIC std::string linphone::Config::getDefaultString ( const std::string &  section,
const std::string &  key,
const std::string &  defaultValue 
) const

Retrieves a default configuration item as a string, given its section, key, and default value.

The default value string is returned if the config item isn't found.

Parameters
sectionThe section from which to retrieve the default value
keyThe name of the configuration item to retrieve
defaultValueThe default value to return if not found
Returns
the found default value or default_value if not found.

◆ getFloat()

LINPHONECXX_PUBLIC float linphone::Config::getFloat ( const std::string &  section,
const std::string &  key,
float  defaultValue 
) const

Retrieves a configuration item as a float, given its section, key, and default value.

The default float value is returned if the config item isn't found.

Parameters
sectionThe section from which to retrieve a configuration item
keyThe name of the configuration item to retrieve
defaultValueThe default value to return if not found
Returns
the found value or default_value if not found.

◆ getInt()

LINPHONECXX_PUBLIC int linphone::Config::getInt ( const std::string &  section,
const std::string &  key,
int  defaultValue 
) const

Retrieves a configuration item as an integer, given its section, key, and default value.

The default integer value is returned if the config item isn't found.

Parameters
sectionThe section from which to retrieve a configuration item
keyThe name of the configuration item to retrieve
defaultValueThe default value to return if not found
Returns
the found value or default_value if not found.

◆ getInt64()

LINPHONECXX_PUBLIC int64_t linphone::Config::getInt64 ( const std::string &  section,
const std::string &  key,
int64_t  defaultValue 
) const

Retrieves a configuration item as a 64 bit integer, given its section, key, and default value.

The default integer value is returned if the config item isn't found.

Parameters
sectionThe section from which to retrieve a configuration item
keyThe name of the configuration item to retrieve
defaultValueThe default value to return if not found
Returns
the found value or default_value if not found.

◆ getKeysNamesList()

LINPHONECXX_PUBLIC std::list<std::string> linphone::Config::getKeysNamesList ( const std::string &  section)

Returns the list of keys' names for a section in the LinphoneConfig.

Parameters
sectionThe section name
Returns
A list of strings.

◆ getOverwriteFlagForEntry()

LINPHONECXX_PUBLIC bool linphone::Config::getOverwriteFlagForEntry ( const std::string &  section,
const std::string &  key 
) const

Retrieves the overwrite flag for a config item.

Parameters
sectionThe section from which to retrieve the overwrite flag
keyThe name of the configuration item to retrieve the overwrite flag from.
Returns
true if overwrite flag is set, false otherwise.

◆ getOverwriteFlagForSection()

LINPHONECXX_PUBLIC bool linphone::Config::getOverwriteFlagForSection ( const std::string &  section) const

Retrieves the overwrite flag for a config section.

Parameters
sectionThe section from which to retrieve the overwrite flag
Returns
true if overwrite flag is set, false otherwise.

◆ getRange()

LINPHONECXX_PUBLIC bool linphone::Config::getRange ( const std::string &  section,
const std::string &  key,
int *  min,
int *  max,
int  defaultMin,
int  defaultMax 
) const

Retrieves a configuration item as a range, given its section, key, and default min and max values.

Parameters
sectionThe section from which to retrieve a configuration item
keyThe name of the configuration item to retrieve
minThe min value found or default_min
maxThe max value found or default_max
defaultMinthe default min value to return if not found
defaultMaxthe default max value to return if not found.
Returns
true if the value is successfully parsed as a range, false otherwise. If false is returned, min and max are filled respectively with default_min and default_max values.

◆ getSectionParamString()

LINPHONECXX_PUBLIC std::string linphone::Config::getSectionParamString ( const std::string &  section,
const std::string &  key,
const std::string &  defaultValue 
) const

Retrieves a section parameter item as a string, given its section and key.

The default value string is returned if the config item isn't found.

Parameters
sectionThe section from which to retrieve the default value
keyThe name of the configuration item to retrieve
defaultValueThe default value to return if not found.
Returns
the found default value or default_value if not found.

◆ getSectionsNamesList()

LINPHONECXX_PUBLIC std::list<std::string> linphone::Config::getSectionsNamesList ( )

Returns the list of sections' names in the LinphoneConfig.

Returns
A list of strings.

◆ getSkipFlagForEntry()

LINPHONECXX_PUBLIC bool linphone::Config::getSkipFlagForEntry ( const std::string &  section,
const std::string &  key 
) const

Retrieves the skip flag for a config item.

Parameters
sectionThe section from which to retrieve the skip flag
keyThe name of the configuration item to retrieve the skip flag from
Returns
true if skip flag is set, false otherwise.

◆ getSkipFlagForSection()

LINPHONECXX_PUBLIC bool linphone::Config::getSkipFlagForSection ( const std::string &  section) const

Retrieves the skip flag for a config section.

Parameters
sectionThe section from which to retrieve the skip flag
Returns
true if skip flag is set, false otherwise.

◆ getString()

LINPHONECXX_PUBLIC std::string linphone::Config::getString ( const std::string &  section,
const std::string &  key,
const std::string &  defaultString 
) const

Retrieves a configuration item as a string, given its section, key, and default value.

The default value string is returned if the config item isn't found.

Parameters
sectionThe section from which to retrieve a configuration item
keyThe name of the configuration item to retrieve
defaultStringThe default value to return if not found.
Returns
the found value or the default one if not found.

◆ getStringList()

LINPHONECXX_PUBLIC std::list<std::string> linphone::Config::getStringList ( const std::string &  section,
const std::string &  key,
const std::list< std::string > &  defaultList 
) const

Retrieves a configuration item as a list of strings, given its section, key, and default value.

The default value is returned if the config item is not found.

Parameters
sectionThe section from which to retrieve a configuration item
keyThe name of the configuration item to retrieve
defaultListThe list to return when the key doesn't exist.
Returns
A list of strings.

◆ hasEntry()

LINPHONECXX_PUBLIC int linphone::Config::hasEntry ( const std::string &  section,
const std::string &  key 
) const

Returns if a given section with a given key is present in the configuration.

Parameters
sectionto check if the given entry exists
keyto check if it exists
Returns
1 if it exists, 0 otherwise

◆ hasSection()

LINPHONECXX_PUBLIC int linphone::Config::hasSection ( const std::string &  section) const

Returns if a given section is present in the configuration.

Parameters
sectionthe section to check if exists
Returns
1 if it exists, 0 otherwise

◆ isReadonly()

LINPHONECXX_PUBLIC bool linphone::Config::isReadonly ( ) const

Indicates whether the LinphoneConfig object is readonly, in other words it has no file backend or file is opened without write permission.

Returns
a boolean.

◆ loadFromXmlFile()

LINPHONECXX_PUBLIC std::string linphone::Config::loadFromXmlFile ( const std::string &  filename)

Reads a xml config file and fill the Config with the read config dynamic values.

Parameters
filenameThe filename of the config file to read to fill the Config

◆ loadFromXmlString()

LINPHONECXX_PUBLIC linphone::Status linphone::Config::loadFromXmlString ( const std::string &  buffer)

Reads a xml config string and fill the Config with the read config dynamic values.

Parameters
bufferThe string of the config file to fill the Config
Returns
0 in case of success

◆ newFromBuffer()

static LINPHONECXX_PUBLIC std::shared_ptr<linphone::Config> linphone::Config::newFromBuffer ( const std::string &  buffer)
static

Instantiates a Config object from a user provided buffer.

The caller of this constructor owns a reference. linphone_config_unref must be called when this object is no longer needed.

Parameters
bufferthe buffer from which the Config will be retrieved. We expect the buffer to be null-terminated.
See also
newWithFactory()
linphone_config_new
Returns
a Config object

◆ newWithFactory()

static LINPHONECXX_PUBLIC std::shared_ptr<linphone::Config> linphone::Config::newWithFactory ( const std::string &  configFilename,
const std::string &  factoryConfigFilename 
)
static

Instantiates a Config object from a user config file and a factory config file.

The caller of this constructor owns a reference. linphone_config_unref must be called when this object is no longer needed.

Parameters
configFilenamethe filename of the user config file to read to fill the instantiated Config
factoryConfigFilenamethe filename of the factory config file to read to fill the instantiated Config
See also
linphone_config_new
Returns
a Config object The user config file is read first to fill the Config and then the factory config file is read. Therefore the configuration parameters defined in the user config file will be overwritten by the parameters defined in the factory config file.

◆ readFile()

LINPHONECXX_PUBLIC linphone::Status linphone::Config::readFile ( const std::string &  filename)

Reads a user config file and fill the Config with the read config values.

Parameters
filenameThe filename of the config file to read to fill the Config

◆ relativeFileExists()

LINPHONECXX_PUBLIC bool linphone::Config::relativeFileExists ( const std::string &  filename) const

Check if given file name exists relatively to the current location.

Parameters
filenameThe file name to check if exists
Returns
true if file exists relative to the to the current location

◆ setBool()

LINPHONECXX_PUBLIC void linphone::Config::setBool ( const std::string &  section,
const std::string &  key,
bool  value 
)

Sets a boolean config item.

Parameters
sectionThe section from which to retrieve a configuration item
keyThe name of the configuration item to retrieve
valuethe value to set

◆ setFloat()

LINPHONECXX_PUBLIC void linphone::Config::setFloat ( const std::string &  section,
const std::string &  key,
float  value 
)

Sets a float config item.

Parameters
sectionThe section from which to retrieve a configuration item
keyThe name of the configuration item to retrieve
valuethe value to set

◆ setInt()

LINPHONECXX_PUBLIC void linphone::Config::setInt ( const std::string &  section,
const std::string &  key,
int  value 
)

Sets an integer config item.

Parameters
sectionThe section from which to retrieve a configuration item
keyThe name of the configuration item to retrieve
valuethe value to set

◆ setInt64()

LINPHONECXX_PUBLIC void linphone::Config::setInt64 ( const std::string &  section,
const std::string &  key,
int64_t  value 
)

Sets a 64 bits integer config item.

Parameters
sectionThe section from which to retrieve a configuration item
keyThe name of the configuration item to retrieve
valuethe value to set

◆ setIntHex()

LINPHONECXX_PUBLIC void linphone::Config::setIntHex ( const std::string &  section,
const std::string &  key,
int  value 
)

Sets an integer config item, but store it as hexadecimal.

Parameters
sectionThe section from which to retrieve a configuration item
keyThe name of the configuration item to retrieve
valuethe value to set

◆ setOverwriteFlagForEntry()

LINPHONECXX_PUBLIC void linphone::Config::setOverwriteFlagForEntry ( const std::string &  section,
const std::string &  key,
bool  value 
)

Sets the overwrite flag for a config item (used when dumping config as xml)

Parameters
sectionThe section from which to set the overwrite flag
keyThe name of the configuration item to set the overwrite flag from
valueThe overwrite flag value to set

◆ setOverwriteFlagForSection()

LINPHONECXX_PUBLIC void linphone::Config::setOverwriteFlagForSection ( const std::string &  section,
bool  value 
)

Sets the overwrite flag for a config section (used when dumping config as xml)

Parameters
sectionThe section from which to set the overwrite flag
valueThe overwrite flag value to set

◆ setRange()

LINPHONECXX_PUBLIC void linphone::Config::setRange ( const std::string &  section,
const std::string &  key,
int  minValue,
int  maxValue 
)

Sets a range config item.

Parameters
sectionThe section from which to retrieve a configuration item
keyThe name of the configuration item to retrieve
minValuethe min value to set
maxValuethe max value to set

◆ setSkipFlagForEntry()

LINPHONECXX_PUBLIC void linphone::Config::setSkipFlagForEntry ( const std::string &  section,
const std::string &  key,
bool  value 
)

Sets the skip flag for a config item (used when dumping config as xml)

Parameters
sectionThe section from which to set the skip flag
keyThe name of the configuration item to set the skip flag from
valueThe skip flag value to set

◆ setSkipFlagForSection()

LINPHONECXX_PUBLIC void linphone::Config::setSkipFlagForSection ( const std::string &  section,
bool  value 
)

Sets the skip flag for a config section (used when dumping config as xml)

Parameters
sectionThe section from which to set the skip flag
valueThe skip flag value to set

◆ setString()

LINPHONECXX_PUBLIC void linphone::Config::setString ( const std::string &  section,
const std::string &  key,
const std::string &  value 
)

Sets a string config item.

Parameters
sectionThe section from which to retrieve a configuration item
keyThe name of the configuration item to retrieve
valueThe value to set

◆ setStringList()

LINPHONECXX_PUBLIC void linphone::Config::setStringList ( const std::string &  section,
const std::string &  key,
const std::list< std::string > &  value 
)

Sets a string list config item.

Parameters
sectionThe name of the section to put the configuration item into
keyThe name of the configuration item to set
valueThe value to set.

◆ sync()

LINPHONECXX_PUBLIC linphone::Status linphone::Config::sync ( )

Writes the config file to disk.

Returns
0 if successful, -1 otherwise

◆ writeRelativeFile()

LINPHONECXX_PUBLIC void linphone::Config::writeRelativeFile ( const std::string &  filename,
const std::string &  data 
) const

Write a string in a file placed relatively with the Linphone configuration file.

Parameters
filenameName of the file where to write data. The name is relative to the place of the config file
dataString to write

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