]> sjero.net Git - linphone/blob - coreapi/lpconfig.h
c1821d2aab7fe4b34e1c61c9b22eb74529f7c92d
[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 /**
29  * The LpConfig object is used to manipulate a configuration file.
30  * 
31  * @ingroup misc
32  * The format of the configuration file is a .ini like format:
33  * - sections are defined in []
34  * - each section contains a sequence of key=value pairs.
35  *
36  * Example:
37  * @code
38  * [sound]
39  * echocanceler=1
40  * playback_dev=ALSA: Default device
41  *
42  * [video]
43  * enabled=1
44  * @endcode
45 **/
46 typedef struct _LpConfig LpConfig;
47
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
52 LpConfig * lp_config_new(const char *filename);
53 int lp_config_read_file(LpConfig *lpconfig, const char *filename);
54 /**
55  * Retrieves a configuration item as a string, given its section, key, and default value.
56  * 
57  * @ingroup misc
58  * The default value string is returned if the config item isn't found.
59 **/
60 const char *lp_config_get_string(LpConfig *lpconfig, const char *section, const char *key, const char *default_string);
61 int lp_config_read_file(LpConfig *lpconfig, const char *filename);
62 /**
63  * Retrieves a configuration item as an integer, given its section, key, and default value.
64  * 
65  * @ingroup misc
66  * The default integer value is returned if the config item isn't found.
67 **/
68 int lp_config_get_int(LpConfig *lpconfig,const char *section, const char *key, int default_value);
69
70 /**
71  * Retrieves a configuration item as a 64 bit integer, given its section, key, and default value.
72  * 
73  * @ingroup misc
74  * The default integer value is returned if the config item isn't found.
75 **/
76 int64_t lp_config_get_int64(LpConfig *lpconfig,const char *section, const char *key, int64_t default_value);
77
78
79 int lp_config_read_file(LpConfig *lpconfig, const char *filename);
80 /**
81  * Retrieves a configuration item as a float, given its section, key, and default value.
82  * 
83  * @ingroup misc
84  * The default float value is returned if the config item isn't found.
85 **/
86 float lp_config_get_float(LpConfig *lpconfig,const char *section, const char *key, float default_value);
87 /**
88  * Sets a string config item 
89  *
90  * @ingroup misc
91 **/
92 void lp_config_set_string(LpConfig *lpconfig,const char *section, const char *key, const char *value);
93 /**
94  * Sets an integer config item
95  *
96  * @ingroup misc
97 **/
98 void lp_config_set_int(LpConfig *lpconfig,const char *section, const char *key, int value);
99 /**
100  * Sets a 64 bits integer config item
101  *
102  * @ingroup misc
103 **/
104 void lp_config_set_int64(LpConfig *lpconfig,const char *section, const char *key, int64_t value);
105
106 /**
107  * Sets a float config item
108  *
109  * @ingroup misc
110 **/
111 void lp_config_set_float(LpConfig *lpconfig,const char *section, const char *key, float value); 
112 /**
113  * Writes the config file to disk.
114  * 
115  * @ingroup misc
116 **/
117 int lp_config_sync(LpConfig *lpconfig);
118 /**
119  * Returns 1 if a given section is present in the configuration.
120  *
121  * @ingroup misc
122 **/
123 int lp_config_has_section(LpConfig *lpconfig, const char *section);
124 /**
125  * Removes every pair of key,value in a section and remove the section.
126  *
127  * @ingroup misc
128 **/
129 void lp_config_clean_section(LpConfig *lpconfig, const char *section);
130 /*tells whether uncommited (with lp_config_sync()) modifications exist*/
131 int lp_config_needs_commit(const LpConfig *lpconfig);
132 void lp_config_destroy(LpConfig *cfg);
133         
134 #ifdef __cplusplus
135 }
136 #endif
137
138 #endif