lpconfig.h 11.9 KB
Newer Older
aymeric's avatar
aymeric committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/***************************************************************************
 *            lpconfig.h
 *
 *  Thu Mar 10 15:02:49 2005
 *  Copyright  2005  Simon Morlat
 *  Email simon.morlat@linphone.org
 ****************************************************************************/

/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
24

aymeric's avatar
aymeric committed
25 26
#ifndef LPCONFIG_H
#define LPCONFIG_H
Ghislain MARY's avatar
Ghislain MARY committed
27
#include <mediastreamer2/mscommon.h>
Yann Diorcet's avatar
Yann Diorcet committed
28 29
#include <ortp/port.h>

Ghislain MARY's avatar
Ghislain MARY committed
30 31 32 33
#ifndef LINPHONE_PUBLIC
	#define LINPHONE_PUBLIC MS2_PUBLIC
#endif

smorlat's avatar
smorlat committed
34 35
/**
 * The LpConfig object is used to manipulate a configuration file.
36
 *
smorlat's avatar
smorlat committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
 * @ingroup misc
 * The format of the configuration file is a .ini like format:
 * - sections are defined in []
 * - each section contains a sequence of key=value pairs.
 *
 * Example:
 * @code
 * [sound]
 * echocanceler=1
 * playback_dev=ALSA: Default device
 *
 * [video]
 * enabled=1
 * @endcode
**/
aymeric's avatar
aymeric committed
52 53 54 55 56 57
typedef struct _LpConfig LpConfig;

#ifdef __cplusplus
extern "C" {
#endif

58 59
/**
 * Instantiates a LpConfig object from a user config file.
60
 * The caller of this constructor owns a reference. lp_config_unref() must be called when this object is no longer needed.
61 62 63 64
 * @ingroup misc
 * @param filename the filename of the config file to read to fill the instantiated LpConfig
 * @see lp_config_new_with_factory
 */
Ghislain MARY's avatar
Ghislain MARY committed
65
LINPHONE_PUBLIC LpConfig * lp_config_new(const char *filename);
66

67 68
/**
 * Instantiates a LpConfig object from a user provided buffer.
69
 * The caller of this constructor owns a reference. lp_config_unref() must be called when this object is no longer needed.
70 71 72 73 74 75 76
 * @ingroup misc
 * @param buffer the buffer from which the lpconfig will be retrieved. We expect the buffer to be null-terminated.
 * @see lp_config_new_with_factory
 * @see lp_config_new
 */
LINPHONE_PUBLIC LpConfig * lp_config_new_from_buffer(const char *buffer);

77 78
/**
 * Instantiates a LpConfig object from a user config file and a factory config file.
79
 * The caller of this constructor owns a reference. lp_config_unref() must be called when this object is no longer needed.
80 81 82 83 84 85 86 87 88
 * @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.
 */
Ghislain MARY's avatar
Ghislain MARY committed
89
LINPHONE_PUBLIC LpConfig * lp_config_new_with_factory(const char *config_filename, const char *factory_config_filename);
90

91 92 93 94 95 96 97
/**
 * Reads a user config file and fill the LpConfig with the read config values.
 * @ingroup misc
 * @param lpconfig The LpConfig object to fill with the content of the file
 * @param filename The filename of the config file to read to fill the LpConfig
 */
LINPHONE_PUBLIC int lp_config_read_file(LpConfig *lpconfig, const char *filename);
98

smorlat's avatar
smorlat committed
99 100
/**
 * Retrieves a configuration item as a string, given its section, key, and default value.
101
 *
smorlat's avatar
smorlat committed
102 103 104
 * @ingroup misc
 * The default value string is returned if the config item isn't found.
**/
Ghislain MARY's avatar
Ghislain MARY committed
105
LINPHONE_PUBLIC const char *lp_config_get_string(const LpConfig *lpconfig, const char *section, const char *key, const char *default_string);
106

107 108 109 110 111 112 113
/**
 * 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.
 */
Ghislain MARY's avatar
Ghislain MARY committed
114
LINPHONE_PUBLIC 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);
115

smorlat's avatar
smorlat committed
116 117
/**
 * Retrieves a configuration item as an integer, given its section, key, and default value.
118
 *
smorlat's avatar
smorlat committed
119 120 121
 * @ingroup misc
 * The default integer value is returned if the config item isn't found.
**/
Ghislain MARY's avatar
Ghislain MARY committed
122
LINPHONE_PUBLIC int lp_config_get_int(const LpConfig *lpconfig,const char *section, const char *key, int default_value);
123 124 125

/**
 * Retrieves a configuration item as a 64 bit integer, given its section, key, and default value.
126
 *
127 128 129
 * @ingroup misc
 * The default integer value is returned if the config item isn't found.
**/
Ghislain MARY's avatar
Ghislain MARY committed
130
LINPHONE_PUBLIC int64_t lp_config_get_int64(const LpConfig *lpconfig,const char *section, const char *key, int64_t default_value);
131

smorlat's avatar
smorlat committed
132 133
/**
 * Retrieves a configuration item as a float, given its section, key, and default value.
134
 *
smorlat's avatar
smorlat committed
135 136 137
 * @ingroup misc
 * The default float value is returned if the config item isn't found.
**/
Ghislain MARY's avatar
Ghislain MARY committed
138
LINPHONE_PUBLIC float lp_config_get_float(const LpConfig *lpconfig,const char *section, const char *key, float default_value);
139

smorlat's avatar
smorlat committed
140
/**
141
 * Sets a string config item
smorlat's avatar
smorlat committed
142 143 144
 *
 * @ingroup misc
**/
Ghislain MARY's avatar
Ghislain MARY committed
145
LINPHONE_PUBLIC void lp_config_set_string(LpConfig *lpconfig,const char *section, const char *key, const char *value);
146

147 148 149 150 151
/**
 * Sets a range config item
 *
 * @ingroup misc
 */
Ghislain MARY's avatar
Ghislain MARY committed
152
LINPHONE_PUBLIC void lp_config_set_range(LpConfig *lpconfig, const char *section, const char *key, int min_value, int max_value);
153

smorlat's avatar
smorlat committed
154 155 156 157 158
/**
 * Sets an integer config item
 *
 * @ingroup misc
**/
Ghislain MARY's avatar
Ghislain MARY committed
159
LINPHONE_PUBLIC void lp_config_set_int(LpConfig *lpconfig,const char *section, const char *key, int value);
160 161 162 163 164 165

/**
 * Sets an integer config item, but store it as hexadecimal
 *
 * @ingroup misc
**/
166
LINPHONE_PUBLIC void lp_config_set_int_hex(LpConfig *lpconfig,const char *section, const char *key, int value);
167

168 169 170 171 172
/**
 * Sets a 64 bits integer config item
 *
 * @ingroup misc
**/
Ghislain MARY's avatar
Ghislain MARY committed
173
LINPHONE_PUBLIC void lp_config_set_int64(LpConfig *lpconfig,const char *section, const char *key, int64_t value);
174

175 176 177 178 179
/**
 * Sets a float config item
 *
 * @ingroup misc
**/
180
LINPHONE_PUBLIC void lp_config_set_float(LpConfig *lpconfig,const char *section, const char *key, float value);
181

smorlat's avatar
smorlat committed
182 183
/**
 * Writes the config file to disk.
184
 *
smorlat's avatar
smorlat committed
185 186
 * @ingroup misc
**/
187
LINPHONE_PUBLIC int lp_config_sync(LpConfig *lpconfig);
188

smorlat's avatar
smorlat committed
189 190 191 192 193
/**
 * Returns 1 if a given section is present in the configuration.
 *
 * @ingroup misc
**/
194
LINPHONE_PUBLIC int lp_config_has_section(const LpConfig *lpconfig, const char *section);
195

smorlat's avatar
smorlat committed
196 197 198 199 200
/**
 * Removes every pair of key,value in a section and remove the section.
 *
 * @ingroup misc
**/
201
LINPHONE_PUBLIC void lp_config_clean_section(LpConfig *lpconfig, const char *section);
202

203
/**
204
 * Returns the list of sections' names in the LpConfig.
205
 * @param[in] lpconfig The LpConfig object
206
 * @return a null terminated static array of strings
207
**/
208
LINPHONE_PUBLIC const char** lp_config_get_sections_names(LpConfig *lpconfig);
209

210 211 212 213 214 215
/**
 * 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);
216

217 218 219 220 221 222 223
/**
 * 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);

224 225
/*tells whether uncommited (with lp_config_sync()) modifications exist*/
int lp_config_needs_commit(const LpConfig *lpconfig);
226

227
LINPHONE_PUBLIC void lp_config_destroy(LpConfig *cfg);
228 229 230

/**
 * Retrieves a default configuration item as an integer, given its section, key, and default value.
231
 *
232 233 234 235 236 237 238
 * @ingroup misc
 * The default integer value is returned if the config item isn't found.
**/
LINPHONE_PUBLIC int lp_config_get_default_int(const LpConfig *lpconfig, const char *section, const char *key, int default_value);

/**
 * Retrieves a default configuration item as a 64 bit integer, given its section, key, and default value.
239
 *
240 241 242 243 244 245 246
 * @ingroup misc
 * The default integer value is returned if the config item isn't found.
**/
LINPHONE_PUBLIC int64_t lp_config_get_default_int64(const LpConfig *lpconfig, const char *section, const char *key, int64_t default_value);

/**
 * Retrieves a default configuration item as a float, given its section, key, and default value.
247
 *
248 249 250 251 252 253 254
 * @ingroup misc
 * The default float value is returned if the config item isn't found.
**/
LINPHONE_PUBLIC float lp_config_get_default_float(const LpConfig *lpconfig, const char *section, const char *key, float default_value);

/**
 * Retrieves a default configuration item as a string, given its section, key, and default value.
255
 *
256 257 258 259
 * @ingroup misc
 * The default value string is returned if the config item isn't found.
**/
LINPHONE_PUBLIC const char* lp_config_get_default_string(const LpConfig *lpconfig, const char *section, const char *key, const char *default_value);
260 261 262

/**
 * Retrieves a section parameter item as a string, given its section and key.
263
 *
264 265 266 267
 * @ingroup misc
 * The default value string is returned if the config item isn't found.
**/
LINPHONE_PUBLIC const char* lp_config_get_section_param_string(const LpConfig *lpconfig, const char *section, const char *key, const char *default_value);
268

269 270 271 272 273 274 275 276 277 278 279 280 281

/**
 * increment reference count
 * @ingroup misc
**/
LINPHONE_PUBLIC LpConfig *lp_config_ref(LpConfig *lpconfig);

/**
 * Decrement reference count, which will eventually free the object.
 * @ingroup misc
**/
LINPHONE_PUBLIC void lp_config_unref(LpConfig *lpconfig);

282 283 284 285 286 287 288 289 290
/**
 * @brief Write a string in a file placed relatively with the Linphone configuration file.
 * @param lpconfig LpConfig instance used as a reference
 * @param filename Name of the file where to write data. The name is relative to the place of the config file
 * @param data String to write
 */
LINPHONE_PUBLIC void lp_config_write_relative_file(const LpConfig *lpconfig, const char *filename, const char *data);

/**
291
 * @brief Read a string from a file placed beside the Linphone configuration file
292 293
 * @param lpconfig LpConfig instance used as a reference
 * @param filename Name of the file where data will be read from. The name is relative to the place of the config file
294 295 296
 * @param data Buffer where read string will be stored
 * @param max_length Length of the buffer
 * @return 0 on success, -1 on failure
297
 */
298
LINPHONE_PUBLIC int lp_config_read_relative_file(const LpConfig *lpconfig, const char *filename, char *data, size_t max_length);
299

300 301 302 303 304
/**
 * @return TRUE if file exists relative to the to the current location
**/
LINPHONE_PUBLIC bool_t lp_config_relative_file_exists(const LpConfig *lpconfig, const char *filename);

305 306 307 308 309 310 311 312 313
/**
 * Dumps the LpConfig as XML into a buffer
 * @param[in] lpconfig The LpConfig object
 * @return The buffer that contains the XML dump
 * 
 * @ingroup misc
**/
LINPHONE_PUBLIC char* lp_config_dump_as_xml(const LpConfig *lpconfig);

314 315 316 317 318 319 320 321 322 323 324 325 326 327
/**
 * Retrieves the overwrite flag for a config item
 *
 * @ingroup misc
**/
LINPHONE_PUBLIC bool_t lp_config_get_overwrite_flag_for_entry(const LpConfig *lpconfig, const char *section, const char *key);

/**
 * Sets the overwrite flag for a config item (used when dumping config as xml)
 *
 * @ingroup misc
**/
LINPHONE_PUBLIC void lp_config_set_overwrite_flag_for_entry(LpConfig *lpconfig, const char *section, const char *key, bool_t value);

328 329 330 331 332 333 334 335 336 337 338 339 340 341
/**
 * Retrieves the overwrite flag for a config section
 *
 * @ingroup misc
**/
LINPHONE_PUBLIC bool_t lp_config_get_overwrite_flag_for_section(const LpConfig *lpconfig, const char *section);

/**
 * Sets the overwrite flag for a config section (used when dumping config as xml)
 *
 * @ingroup misc
**/
LINPHONE_PUBLIC void lp_config_set_overwrite_flag_for_section(LpConfig *lpconfig, const char *section, bool_t value);

aymeric's avatar
aymeric committed
342 343 344 345 346
#ifdef __cplusplus
}
#endif

#endif