]> sjero.net Git - linphone/blob - coreapi/lpconfig.h
Add the linphone_core_new_with_config() function to instantiate a LinphoneCore given...
[linphone] / coreapi / lpconfig.h
1 /***************************************************************************
2  *            lpconfig.h
3  *
4  *  Thu Mar 10 15:02:49 2005
5  *  Copyright  2005  Simon Morlat
6  *  Email simon.morlat@linphone.org
7  ****************************************************************************/
8
9 /*
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU Library General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23  */
24  
25 #ifndef LPCONFIG_H
26 #define LPCONFIG_H
27
28 #include <ortp/port.h>
29
30 /**
31  * The LpConfig object is used to manipulate a configuration file.
32  * 
33  * @ingroup misc
34  * The format of the configuration file is a .ini like format:
35  * - sections are defined in []
36  * - each section contains a sequence of key=value pairs.
37  *
38  * Example:
39  * @code
40  * [sound]
41  * echocanceler=1
42  * playback_dev=ALSA: Default device
43  *
44  * [video]
45  * enabled=1
46  * @endcode
47 **/
48 typedef struct _LpConfig LpConfig;
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
54
55 #define LP_CONFIG_DEFAULT_STRING(config, name, default) \
56         (config) ? (lp_config_get_string(config, "default_values", name, default)) : (default)
57
58 #define LP_CONFIG_DEFAULT_INT(config, name, default) \
59         (config) ? (lp_config_get_int(config, "default_values", name, default)) : (default)
60
61 #define LP_CONFIG_DEFAULT_INT64(config, name, default) \
62         (config) ? (lp_config_get_int64(config, "default_values", name, default)) : (default)
63
64 #define LP_CONFIG_DEFAULT_FLOAT(config, name, default) \
65         (config) ? (lp_config_get_float(config, "default_values", name, default)) : (default)
66
67
68 /**
69  * Instantiates a LpConfig object from a user config file.
70  *
71  * @ingroup misc
72  * @param filename the filename of the config file to read to fill the instantiated LpConfig
73  * @see lp_config_new_with_factory
74  */
75 LpConfig * lp_config_new(const char *filename);
76
77 /**
78  * Instantiates a LpConfig object from a user config file and a factory config file.
79  *
80  * @ingroup misc
81  * @param config_filename the filename of the user config file to read to fill the instantiated LpConfig
82  * @param factory_config_filename the filename of the factory config file to read to fill the instantiated LpConfig
83  * @see lp_config_new
84  *
85  * The user config file is read first to fill the LpConfig and then the factory config file is read.
86  * Therefore the configuration parameters defined in the user config file will be overwritten by the parameters
87  * defined in the factory config file.
88  */
89 LpConfig * lp_config_new_with_factory(const char *config_filename, const char *factory_config_filename);
90
91 int lp_config_read_file(LpConfig *lpconfig, const char *filename);
92 /**
93  * Retrieves a configuration item as a string, given its section, key, and default value.
94  * 
95  * @ingroup misc
96  * The default value string is returned if the config item isn't found.
97 **/
98 const char *lp_config_get_string(const LpConfig *lpconfig, const char *section, const char *key, const char *default_string);
99 int lp_config_read_file(LpConfig *lpconfig, const char *filename);
100 /**
101  * Retrieves a configuration item as a range, given its section, key, and default min and max values.
102  *
103  * @ingroup misc
104  * @return TRUE if the value is successfully parsed as a range, FALSE otherwise.
105  * If FALSE is returned, min and max are filled respectively with default_min and default_max values.
106  */
107 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);
108 /**
109  * Retrieves a configuration item as an integer, given its section, key, and default value.
110  * 
111  * @ingroup misc
112  * The default integer value is returned if the config item isn't found.
113 **/
114 int lp_config_get_int(const LpConfig *lpconfig,const char *section, const char *key, int default_value);
115
116 /**
117  * Retrieves a configuration item as a 64 bit integer, given its section, key, and default value.
118  * 
119  * @ingroup misc
120  * The default integer value is returned if the config item isn't found.
121 **/
122 int64_t lp_config_get_int64(const LpConfig *lpconfig,const char *section, const char *key, int64_t default_value);
123
124
125 int lp_config_read_file(LpConfig *lpconfig, const char *filename);
126 /**
127  * Retrieves a configuration item as a float, given its section, key, and default value.
128  * 
129  * @ingroup misc
130  * The default float value is returned if the config item isn't found.
131 **/
132 float lp_config_get_float(const LpConfig *lpconfig,const char *section, const char *key, float default_value);
133 /**
134  * Sets a string config item 
135  *
136  * @ingroup misc
137 **/
138 void lp_config_set_string(LpConfig *lpconfig,const char *section, const char *key, const char *value);
139 /**
140  * Sets a range config item
141  *
142  * @ingroup misc
143  */
144 void lp_config_set_range(LpConfig *lpconfig, const char *section, const char *key, int min_value, int max_value);
145 /**
146  * Sets an integer config item
147  *
148  * @ingroup misc
149 **/
150 void lp_config_set_int(LpConfig *lpconfig,const char *section, const char *key, int value);
151
152 /**
153  * Sets an integer config item, but store it as hexadecimal
154  *
155  * @ingroup misc
156 **/
157 void lp_config_set_int_hex(LpConfig *lpconfig,const char *section, const char *key, int value);
158
159 /**
160  * Sets a 64 bits integer config item
161  *
162  * @ingroup misc
163 **/
164 void lp_config_set_int64(LpConfig *lpconfig,const char *section, const char *key, int64_t value);
165
166 /**
167  * Sets a float config item
168  *
169  * @ingroup misc
170 **/
171 void lp_config_set_float(LpConfig *lpconfig,const char *section, const char *key, float value); 
172 /**
173  * Writes the config file to disk.
174  * 
175  * @ingroup misc
176 **/
177 int lp_config_sync(LpConfig *lpconfig);
178 /**
179  * Returns 1 if a given section is present in the configuration.
180  *
181  * @ingroup misc
182 **/
183 int lp_config_has_section(const LpConfig *lpconfig, const char *section);
184 /**
185  * Removes every pair of key,value in a section and remove the section.
186  *
187  * @ingroup misc
188 **/
189 void lp_config_clean_section(LpConfig *lpconfig, const char *section);
190 /**
191  * Call a function for each section present in the configuration.
192  *
193  * @ingroup misc
194 **/
195 void lp_config_for_each_section(const LpConfig *lpconfig, void (*callback)(const char *section, void *ctx), void *ctx);
196 /**
197  * Call a function for each entry present in a section configuration.
198  *
199  * @ingroup misc
200 **/
201 void lp_config_for_each_entry(const LpConfig *lpconfig, const char *section, void (*callback)(const char *entry, void *ctx), void *ctx);
202
203 /*tells whether uncommited (with lp_config_sync()) modifications exist*/
204 int lp_config_needs_commit(const LpConfig *lpconfig);
205 void lp_config_destroy(LpConfig *cfg);
206         
207 #ifdef __cplusplus
208 }
209 #endif
210
211 #endif