Interface Config


public interface Config
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.
  • Method Details

    • getSectionsNamesList

      @NonNull String[] getSectionsNamesList()
      Returns the list of sections' names in the LinphoneConfig.

      Returns:
      A list of strings.
    • cleanEntry

      void cleanEntry(@NonNull String section, @NonNull 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

      void cleanSection(@NonNull String section)
      Removes every pair of key,value in a section and remove the section.

      Parameters:
      section - the section to clean
    • dump

      @NonNull String dump()
      Dumps the Config as INI into a buffer.

      Returns:
      The buffer that contains the config dump
    • dumpAsXml

      @NonNull String dumpAsXml()
      Dumps the Config as XML into a buffer.

      Returns:
      The buffer that contains the XML dump
    • getBool

      boolean getBool(@NonNull String section, @NonNull String key, boolean defaultValue)
      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

      float getDefaultFloat(@NonNull String section, @NonNull String key, float defaultValue)
      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

      int getDefaultInt(@NonNull String section, @NonNull String key, int defaultValue)
      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

      int getDefaultInt64(@NonNull String section, @NonNull String key, int defaultValue)
      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

      String getDefaultString(@NonNull String section, @NonNull String key, String defaultValue)
      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

      float getFloat(@NonNull String section, @NonNull String key, float defaultValue)
      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

      int getInt(@NonNull String section, @NonNull String key, int defaultValue)
      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

      int getInt64(@NonNull String section, @NonNull String key, int defaultValue)
      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

      @NonNull String[] getKeysNamesList(@NonNull String section)
      Returns the list of keys' names for a section in the LinphoneConfig.

      Parameters:
      section - The section name
      Returns:
      A list of strings.
    • getOverwriteFlagForEntry

      boolean getOverwriteFlagForEntry(@NonNull String section, @NonNull String key)
      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

      boolean getOverwriteFlagForSection(@NonNull String section)
      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.
    • getSectionParamString

      @Nullable String getSectionParamString(@NonNull String section, @NonNull String key, @Nullable String defaultValue)
      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.
    • getSkipFlagForEntry

      boolean getSkipFlagForEntry(@NonNull String section, String key)
      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

      boolean getSkipFlagForSection(@NonNull String section)
      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

      @Nullable String getString(@NonNull String section, @NonNull String key, @Nullable String defaultString)
      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

      @NonNull String[] getStringList(@NonNull String section, @NonNull String key, @Nullable String[] defaultList)
      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

      int hasEntry(@NonNull String section, @NonNull String key)
      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

      int hasSection(@NonNull String section)
      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
    • loadFromXmlFile

      String loadFromXmlFile(@NonNull 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

      int loadFromXmlString(@NonNull 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
    • readFile

      int readFile(@NonNull 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

      boolean relativeFileExists(@NonNull String filename)
      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
    • reload

      void reload()
      Reload the config from the file.

    • setBool

      void setBool(@NonNull String section, @NonNull String key, boolean 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

      void setFloat(@NonNull String section, @NonNull 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

      void setInt(@NonNull String section, @NonNull 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

      void setInt64(@NonNull String section, @NonNull String key, int 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

      void setIntHex(@NonNull String section, @NonNull 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

      void setOverwriteFlagForEntry(@NonNull String section, @NonNull String key, boolean 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

      void setOverwriteFlagForSection(@NonNull String section, boolean 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

      void setRange(@NonNull String section, @NonNull 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

      void setSkipFlagForEntry(@NonNull String section, @NonNull String key, boolean 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

      void setSkipFlagForSection(@NonNull String section, boolean 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

      void setString(@NonNull String section, @NonNull String key, @Nullable 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

      void setStringList(@NonNull String section, @NonNull String key, @Nullable 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

      int sync()
      Writes the config file to disk.

      Returns:
      0 if successful, -1 otherwise
    • writeRelativeFile

      void writeRelativeFile(@NonNull String filename, @NonNull String data)
      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
    • newFromBuffer

      @NonNull Config newFromBuffer(@NonNull String buffer)
      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: newWithFactory(java.lang.String, java.lang.String)
      see: linphone_config_new
      Returns:
      a Config object
    • newWithFactory

      @Nullable Config newWithFactory(@Nullable String configFilename, @Nullable String factoryConfigFilename)
      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: 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.
    • setUserData

      void setUserData(Object data)
      Sets the object to store in this object user's data
      Parameters:
      data - the object to store
    • getUserData

      Object getUserData()
      Gets the object stored in this object user's data
      Returns:
      the object store if any, null otherwise
    • getNativePointer

      long getNativePointer()
      Gets the native pointer used by this class to make native method calls.
      Returns:
      the nativer pointer, as long
    • toString

      String toString()
      Overrides:
      toString in class Object