]> sjero.net Git - linphone/blobdiff - coreapi/lpconfig.h
Add the linphone_core_new_with_config() function to instantiate a LinphoneCore given...
[linphone] / coreapi / lpconfig.h
index a27f7e39a28327ed54fd12ea34f6b6b02a26434f..43f761adb74663d7f92e81cba25043087d30ca1b 100644 (file)
@@ -25,6 +25,8 @@
 #ifndef LPCONFIG_H
 #define LPCONFIG_H
 
+#include <ortp/port.h>
+
 /**
  * The LpConfig object is used to manipulate a configuration file.
  * 
@@ -49,7 +51,43 @@ typedef struct _LpConfig LpConfig;
 extern "C" {
 #endif
 
+
+#define LP_CONFIG_DEFAULT_STRING(config, name, default) \
+       (config) ? (lp_config_get_string(config, "default_values", name, default)) : (default)
+
+#define LP_CONFIG_DEFAULT_INT(config, name, default) \
+       (config) ? (lp_config_get_int(config, "default_values", name, default)) : (default)
+
+#define LP_CONFIG_DEFAULT_INT64(config, name, default) \
+       (config) ? (lp_config_get_int64(config, "default_values", name, default)) : (default)
+
+#define LP_CONFIG_DEFAULT_FLOAT(config, name, default) \
+       (config) ? (lp_config_get_float(config, "default_values", name, default)) : (default)
+
+
+/**
+ * Instantiates a LpConfig object from a user config file.
+ *
+ * @ingroup misc
+ * @param filename the filename of the config file to read to fill the instantiated LpConfig
+ * @see lp_config_new_with_factory
+ */
 LpConfig * lp_config_new(const char *filename);
+
+/**
+ * Instantiates a LpConfig object from a user config file and a factory config file.
+ *
+ * @ingroup misc
+ * @param config_filename the filename of the user config file to read to fill the instantiated LpConfig
+ * @param factory_config_filename the filename of the factory config file to read to fill the instantiated LpConfig
+ * @see lp_config_new
+ *
+ * The user config file is read first to fill the LpConfig 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.
+ */
+LpConfig * lp_config_new_with_factory(const char *config_filename, const char *factory_config_filename);
+
 int lp_config_read_file(LpConfig *lpconfig, const char *filename);
 /**
  * Retrieves a configuration item as a string, given its section, key, and default value.
@@ -57,15 +95,23 @@ int lp_config_read_file(LpConfig *lpconfig, const char *filename);
  * @ingroup misc
  * The default value string is returned if the config item isn't found.
 **/
-const char *lp_config_get_string(LpConfig *lpconfig, const char *section, const char *key, const char *default_string);
+const char *lp_config_get_string(const LpConfig *lpconfig, const char *section, const char *key, const char *default_string);
 int lp_config_read_file(LpConfig *lpconfig, const char *filename);
+/**
+ * Retrieves a configuration item as a range, given its section, key, and default min and max values.
+ *
+ * @ingroup misc
+ * @return 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.
+ */
+bool_t lp_config_get_range(const LpConfig *lpconfig, const char *section, const char *key, int *min, int *max, int default_min, int default_max);
 /**
  * Retrieves a configuration item as an integer, given its section, key, and default value.
  * 
  * @ingroup misc
  * The default integer value is returned if the config item isn't found.
 **/
-int lp_config_get_int(LpConfig *lpconfig,const char *section, const char *key, int default_value);
+int lp_config_get_int(const LpConfig *lpconfig,const char *section, const char *key, int default_value);
 
 /**
  * Retrieves a configuration item as a 64 bit integer, given its section, key, and default value.
@@ -73,7 +119,7 @@ int lp_config_get_int(LpConfig *lpconfig,const char *section, const char *key, i
  * @ingroup misc
  * The default integer value is returned if the config item isn't found.
 **/
-int64_t lp_config_get_int64(LpConfig *lpconfig,const char *section, const char *key, int64_t default_value);
+int64_t lp_config_get_int64(const LpConfig *lpconfig,const char *section, const char *key, int64_t default_value);
 
 
 int lp_config_read_file(LpConfig *lpconfig, const char *filename);
@@ -83,13 +129,19 @@ int lp_config_read_file(LpConfig *lpconfig, const char *filename);
  * @ingroup misc
  * The default float value is returned if the config item isn't found.
 **/
-float lp_config_get_float(LpConfig *lpconfig,const char *section, const char *key, float default_value);
+float lp_config_get_float(const LpConfig *lpconfig,const char *section, const char *key, float default_value);
 /**
  * Sets a string config item 
  *
  * @ingroup misc
 **/
 void lp_config_set_string(LpConfig *lpconfig,const char *section, const char *key, const char *value);
+/**
+ * Sets a range config item
+ *
+ * @ingroup misc
+ */
+void lp_config_set_range(LpConfig *lpconfig, const char *section, const char *key, int min_value, int max_value);
 /**
  * Sets an integer config item
  *
@@ -128,13 +180,26 @@ int lp_config_sync(LpConfig *lpconfig);
  *
  * @ingroup misc
 **/
-int lp_config_has_section(LpConfig *lpconfig, const char *section);
+int lp_config_has_section(const LpConfig *lpconfig, const char *section);
 /**
  * Removes every pair of key,value in a section and remove the section.
  *
  * @ingroup misc
 **/
 void lp_config_clean_section(LpConfig *lpconfig, const char *section);
+/**
+ * Call a function for each section present in the configuration.
+ *
+ * @ingroup misc
+**/
+void lp_config_for_each_section(const LpConfig *lpconfig, void (*callback)(const char *section, void *ctx), void *ctx);
+/**
+ * Call a function for each entry present in a section configuration.
+ *
+ * @ingroup misc
+**/
+void lp_config_for_each_entry(const LpConfig *lpconfig, const char *section, void (*callback)(const char *entry, void *ctx), void *ctx);
+
 /*tells whether uncommited (with lp_config_sync()) modifications exist*/
 int lp_config_needs_commit(const LpConfig *lpconfig);
 void lp_config_destroy(LpConfig *cfg);