Liblinphone: linphone::Config Class Reference

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 Config object is readonly, in other words it has no file backend or file is opened without write permission.
LINPHONECXX_PUBLIC std::list< std::string > | getSectionsNamesList ()
| Returns the list of sections' names in the Config.
LINPHONECXX_PUBLIC void | cleanEntry (const std::string &section, const std::string &key)
| Removes entries for key,value in a section.
LINPHONECXX_PUBLIC void | cleanSection (const std::string &section)
| Removes every pair of key,value in a section and remove the section.
LINPHONECXX_PUBLIC std::string | dump () const
| Dumps the Config as INI into a buffer.
LINPHONECXX_PUBLIC std::string | dumpAsXml () const
| Dumps the Config as XML into a buffer.
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.
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.
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.
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.
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.
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.
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.
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.
LINPHONECXX_PUBLIC std::list< std::string > | getKeysNamesList (const std::string &section)
| Returns the list of keys' names for a section in the Config.
LINPHONECXX_PUBLIC bool | getOverwriteFlagForEntry (const std::string &section, const std::string &key) const
| Retrieves the overwrite flag for a config item.
LINPHONECXX_PUBLIC bool | getOverwriteFlagForSection (const std::string &section) const
| Retrieves the overwrite flag for a config section.
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.
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.
LINPHONECXX_PUBLIC bool | getSkipFlagForEntry (const std::string &section, const std::string &key) const
| Retrieves the skip flag for a config item.
LINPHONECXX_PUBLIC bool | getSkipFlagForSection (const std::string &section) const
| Retrieves the skip flag for a config section.
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.
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.
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.
LINPHONECXX_PUBLIC int | hasSection (const std::string &section) const
| Returns if a given section is present in the configuration.
LINPHONECXX_PUBLIC std::string | loadFromXmlFile (const std::string &filename)
| Reads a xml config file and fill the Config with the read config dynamic values.
LINPHONECXX_PUBLIC linphone::Status | loadFromXmlString (const std::string &buffer)
| Reads a xml config string and fill the Config with the read config dynamic values.
LINPHONECXX_PUBLIC linphone::Status | readFile (const std::string &filename)
| Reads a user config file and fill the Config with the read config values.
LINPHONECXX_PUBLIC bool | relativeFileExists (const std::string &filename) const
| Check if given file name exists relatively to the current location.
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.
LINPHONECXX_PUBLIC void | setFloat (const std::string &section, const std::string &key, float value)
| Sets a float config item.
LINPHONECXX_PUBLIC void | setInt (const std::string &section, const std::string &key, int value)
| Sets an integer config item.
LINPHONECXX_PUBLIC void | setInt64 (const std::string &section, const std::string &key, int64_t value)
| Sets a 64 bits integer config item.
LINPHONECXX_PUBLIC void | setIntHex (const std::string &section, const std::string &key, int value)
| Sets an integer config item, but store it as hexadecimal.
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).
LINPHONECXX_PUBLIC void | setOverwriteFlagForSection (const std::string &section, bool value)
| Sets the overwrite flag for a config section (used when dumping config as xml).
LINPHONECXX_PUBLIC void | setRange (const std::string &section, const std::string &key, int minValue, int maxValue)
| Sets a range config item.
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).
LINPHONECXX_PUBLIC void | setSkipFlagForSection (const std::string &section, bool value)
| Sets the skip flag for a config section (used when dumping config as xml).
LINPHONECXX_PUBLIC void | setString (const std::string &section, const std::string &key, const std::string &value)
| Sets a string config item.
LINPHONECXX_PUBLIC void | setStringList (const std::string &section, const std::string &key, const std::list< std::string > &value)
| Sets a string list config item.
LINPHONECXX_PUBLIC linphone::Status | sync ()
| Writes the config file to disk.
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.

## Static Public Member Functions
static LINPHONECXX_PUBLIC std::shared_ptr< linphone::Config > | newFromBuffer (const std::string &buffer)
| Instantiates a Config object from a user provided buffer.
static LINPHONECXX_PUBLIC std::shared_ptr< linphone::Config > | newWithFactory (const std::string &configFilename, const std::string &factoryConfigFilename)
| Instantiates a Config object from a user config file and a factory config file.

## 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

  section | the section for which to clean the key entry
  key | the 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

  section | the 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

  section | The section from which to retrieve a configuration item
  key | The name of the configuration item to retrieve
  defaultValue | The 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

  section | The section from which to retrieve the default value
  key | The name of the configuration item to retrieve
  defaultValue | The 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

  section | The section from which to retrieve the default value
  key | The name of the configuration item to retrieve
  defaultValue | The 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

  section | The section from which to retrieve the default value
  key | The name of the configuration item to retrieve
  defaultValue | The 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

  section | The section from which to retrieve the default value
  key | The name of the configuration item to retrieve
  defaultValue | The 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

  section | The section from which to retrieve a configuration item
  key | The name of the configuration item to retrieve
  defaultValue | The 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

  section | The section from which to retrieve a configuration item
  key | The name of the configuration item to retrieve
  defaultValue | The 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

  section | The section from which to retrieve a configuration item
  key | The name of the configuration item to retrieve
  defaultValue | The 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 Config.

Parameters

  section | The 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

  section | The section from which to retrieve the overwrite flag
  key | The 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

  section | The 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

  section | The section from which to retrieve a configuration item
  key | The name of the configuration item to retrieve
  min | The min value found or default_min
  max | The max value found or default_max
  defaultMin | the default min value to return if not found
  defaultMax | the 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

  section | The section from which to retrieve the default value
  key | The name of the configuration item to retrieve
  defaultValue | The 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 Config.

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

  section | The section from which to retrieve the skip flag
  key | The 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

  section | The 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

  section | The section from which to retrieve a configuration item
  key | The name of the configuration item to retrieve
  defaultString | The 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

  section | The section from which to retrieve a configuration item
  key | The name of the configuration item to retrieve
  defaultList | The 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

  section | to check if the given entry exists
  key | to 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

  section | the section to check if exists

Returns
  1 if it exists, 0 otherwise

## ◆ isReadonly()

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

Indicates whether the Config 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

  filename | The 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

  buffer | The string of the config file to fill the Config

Returns
  0 in case of success

## ◆ newFromBuffer()

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

  buffer | the 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()

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

  configFilename | the filename of the user config file to read to fill the instantiated Config
  factoryConfigFilename | the 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

  filename | The 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

  filename | The 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

  section | The section from which to retrieve a configuration item
  key | The name of the configuration item to retrieve
  value | the 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

  section | The section from which to retrieve a configuration item
  key | The name of the configuration item to retrieve
  value | the 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

  section | The section from which to retrieve a configuration item
  key | The name of the configuration item to retrieve
  value | the 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

  section | The section from which to retrieve a configuration item
  key | The name of the configuration item to retrieve
  value | the 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

  section | The section from which to retrieve a configuration item
  key | The name of the configuration item to retrieve
  value | the 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

  section | The section from which to set the overwrite flag
  key | The name of the configuration item to set the overwrite flag from
  value | The 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

  section | The section from which to set the overwrite flag
  value | The 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

  section | The section from which to retrieve a configuration item
  key | The name of the configuration item to retrieve
  minValue | the min value to set
  maxValue | the 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

  section | The section from which to set the skip flag
  key | The name of the configuration item to set the skip flag from
  value | The 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

  section | The section from which to set the skip flag
  value | The 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

  section | The section from which to retrieve a configuration item
  key | The name of the configuration item to retrieve
  value | The 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

  section | The name of the section to put the configuration item into
  key | The name of the configuration item to set
  value | The 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

  filename | Name of the file where to write data. The name is relative to the place of the config file
  data | String to write

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

- config.hh