]> sjero.net Git - linphone/blob - coreapi/lpconfig.h
Define common macros to get default configuration values.
[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
53 #define LP_CONFIG_DEFAULT_STRING(config, name, default) \
54         (config) ? (lp_config_get_string(config, "default_values", name, default)) : (default)
55
56 #define LP_CONFIG_DEFAULT_INT(config, name, default) \
57         (config) ? (lp_config_get_int(config, "default_values", name, default)) : (default)
58
59 #define LP_CONFIG_DEFAULT_INT64(config, name, default) \
60         (config) ? (lp_config_get_int64(config, "default_values", name, default)) : (default)
61
62 #define LP_CONFIG_DEFAULT_FLOAT(config, name, default) \
63         (config) ? (lp_config_get_float(config, "default_values", name, default)) : (default)
64
65
66 LpConfig * lp_config_new(const char *filename);
67 int lp_config_read_file(LpConfig *lpconfig, const char *filename);
68 /**
69  * Retrieves a configuration item as a string, given its section, key, and default value.
70  * 
71  * @ingroup misc
72  * The default value string is returned if the config item isn't found.
73 **/
74 const char *lp_config_get_string(LpConfig *lpconfig, const char *section, const char *key, const char *default_string);
75 int lp_config_read_file(LpConfig *lpconfig, const char *filename);
76 /**
77  * Retrieves a configuration item as a range, given its section, key, and default min and max values.
78  *
79  * @ingroup misc
80  * @return TRUE if the value is successfully parsed as a range, FALSE otherwise.
81  * If FALSE is returned, min and max are filled respectively with default_min and default_max values.
82  */
83 bool_t lp_config_get_range(LpConfig *lpconfig, const char *section, const char *key, int *min, int *max, int default_min, int default_max);
84 /**
85  * Retrieves a configuration item as an integer, given its section, key, and default value.
86  * 
87  * @ingroup misc
88  * The default integer value is returned if the config item isn't found.
89 **/
90 int lp_config_get_int(LpConfig *lpconfig,const char *section, const char *key, int default_value);
91
92 /**
93  * Retrieves a configuration item as a 64 bit integer, given its section, key, and default value.
94  * 
95  * @ingroup misc
96  * The default integer value is returned if the config item isn't found.
97 **/
98 int64_t lp_config_get_int64(LpConfig *lpconfig,const char *section, const char *key, int64_t default_value);
99
100
101 int lp_config_read_file(LpConfig *lpconfig, const char *filename);
102 /**
103  * Retrieves a configuration item as a float, given its section, key, and default value.
104  * 
105  * @ingroup misc
106  * The default float value is returned if the config item isn't found.
107 **/
108 float lp_config_get_float(LpConfig *lpconfig,const char *section, const char *key, float default_value);
109 /**
110  * Sets a string config item 
111  *
112  * @ingroup misc
113 **/
114 void lp_config_set_string(LpConfig *lpconfig,const char *section, const char *key, const char *value);
115 /**
116  * Sets a range config item
117  *
118  * @ingroup misc
119  */
120 void lp_config_set_range(LpConfig *lpconfig, const char *section, const char *key, int min_value, int max_value);
121 /**
122  * Sets an integer config item
123  *
124  * @ingroup misc
125 **/
126 void lp_config_set_int(LpConfig *lpconfig,const char *section, const char *key, int value);
127
128 /**
129  * Sets an integer config item, but store it as hexadecimal
130  *
131  * @ingroup misc
132 **/
133 void lp_config_set_int_hex(LpConfig *lpconfig,const char *section, const char *key, int value);
134
135 /**
136  * Sets a 64 bits integer config item
137  *
138  * @ingroup misc
139 **/
140 void lp_config_set_int64(LpConfig *lpconfig,const char *section, const char *key, int64_t value);
141
142 /**
143  * Sets a float config item
144  *
145  * @ingroup misc
146 **/
147 void lp_config_set_float(LpConfig *lpconfig,const char *section, const char *key, float value); 
148 /**
149  * Writes the config file to disk.
150  * 
151  * @ingroup misc
152 **/
153 int lp_config_sync(LpConfig *lpconfig);
154 /**
155  * Returns 1 if a given section is present in the configuration.
156  *
157  * @ingroup misc
158 **/
159 int lp_config_has_section(LpConfig *lpconfig, const char *section);
160 /**
161  * Removes every pair of key,value in a section and remove the section.
162  *
163  * @ingroup misc
164 **/
165 void lp_config_clean_section(LpConfig *lpconfig, const char *section);
166 /*tells whether uncommited (with lp_config_sync()) modifications exist*/
167 int lp_config_needs_commit(const LpConfig *lpconfig);
168 void lp_config_destroy(LpConfig *cfg);
169         
170 #ifdef __cplusplus
171 }
172 #endif
173
174 #endif