Smallers steps to keep plugin running
[oweals/gnunet.git] / src / include / gnunet_configuration_lib.h
1 /*
2      This file is part of GNUnet.
3      (C) 2006, 2008, 2009 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 2, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file include/gnunet_configuration_lib.h
23  * @brief configuration API
24  *
25  * @author Christian Grothoff
26  */
27
28 #ifndef GNUNET_CONFIGURATION_LIB_H
29 #define GNUNET_CONFIGURATION_LIB_H
30
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40 #include "gnunet_common.h"
41 #include "gnunet_time_lib.h"
42
43 /**
44  * A configuration object.
45  */
46 struct GNUNET_CONFIGURATION_Handle;
47
48 /**
49  * Create a new configuration object.
50  * @return fresh configuration object
51  */
52 struct GNUNET_CONFIGURATION_Handle *GNUNET_CONFIGURATION_create (void);
53
54
55 /**
56  * Duplicate an existing configuration object.
57  *
58  * @param cfg configuration to duplicate
59  * @return duplicate configuration
60  */
61 struct GNUNET_CONFIGURATION_Handle *
62 GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg);
63
64
65 /**
66  * Destroy configuration object.
67  *
68  * @param cfg configuration to destroy
69  */
70 void GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg);
71
72
73 /**
74  * Load configuration.  This function will first parse the
75  * defaults and then parse the specific configuration file
76  * to overwrite the defaults.
77  *
78  * @param cfg configuration to update
79  * @param filename name of the configuration file
80  * @return GNUNET_OK on success, GNUNET_SYSERR on error
81  */
82 int GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
83                                const char *filename);
84
85
86 /**
87  * Parse a configuration file, add all of the options in the
88  * file to the configuration environment.
89  *
90  * @param cfg configuration to update
91  * @param filename name of the configuration file
92  * @return GNUNET_OK on success, GNUNET_SYSERR on error
93  */
94 int GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
95                                 const char *filename);
96
97
98 /**
99  * Write configuration file.
100  *
101  * @param cfg configuration to write
102  * @param filename where to write the configuration
103  * @return GNUNET_OK on success, GNUNET_SYSERR on error
104  */
105 int GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
106                                 const char *filename);
107
108 /**
109  * Write only configuration entries that have been changed to configuration file
110  * @param cfgDefault default configuration
111  * @param cfgNew new configuration
112  * @param filename where to write the configuration diff between default and new
113  * @return GNUNET_OK on success, GNUNET_SYSERR on error
114  */
115 int
116 GNUNET_CONFIGURATION_write_diffs(const struct GNUNET_CONFIGURATION_Handle *cfgDefault,
117                                  const struct GNUNET_CONFIGURATION_Handle *cfgNew,
118                                  const char* filename);
119
120 /**
121  * Test if there are configuration options that were
122  * changed since the last save.
123  *
124  * @param cfg configuration to inspect
125  * @return GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error (i.e. last save failed)
126  */
127 int GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
128
129
130 /**
131  * Function to iterate over options.
132  *
133  * @param cls closure
134  * @param section name of the section
135  * @param option name of the option
136  * @param value value of the option
137  */
138 typedef void (*GNUNET_CONFIGURATION_Iterator)(void *cls,
139                                               const char *section,
140                                               const char *option,
141                                               const char *value);
142
143
144 /**
145  * Iterate over all options in the configuration.
146  *
147  * @param cfg configuration to inspect
148  * @param iter function to call on each option
149  * @param iter_cls closure for iter
150  */
151 void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
152                                    GNUNET_CONFIGURATION_Iterator iter,
153                                    void *iter_cls);
154
155
156 /**
157  * Get a configuration value that should be a number.
158  *
159  * @param cfg configuration to inspect
160  * @param section section of interest
161  * @param option option of interest
162  * @param number where to store the numeric value of the option
163  * @return GNUNET_OK on success, GNUNET_SYSERR on error
164  */
165 int GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
166                                            *cfg, const char *section,
167                                            const char *option,
168                                            unsigned long long *number);
169
170
171 /**
172  * Get a configuration value that should be a relative time.
173  *
174  * @param cfg configuration to inspect
175  * @param section section of interest
176  * @param option option of interest
177  * @param time set to the time value stored in the configuration
178  * @return GNUNET_OK on success, GNUNET_SYSERR on error
179  */
180 int GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
181                                          *cfg, const char *section,
182                                          const char *option,
183                                          struct GNUNET_TIME_Relative *time);
184
185
186 /**
187  * Test if we have a value for a particular option
188  *
189  * @param cfg configuration to inspect
190  * @param section section of interest
191  * @param option option of interest
192  * @return GNUNET_YES if so, GNUNET_NO if not.
193  */
194 int GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
195                                      const char *section, const char *option);
196
197
198 /**
199  * Get a configuration value that should be a string.
200  *
201  * @param cfg configuration to inspect
202  * @param section section of interest
203  * @param option option of interest
204  * @param value will be set to a freshly allocated configuration
205  *        value, or NULL if option is not specified
206  * @return GNUNET_OK on success, GNUNET_SYSERR on error
207  */
208 int GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
209                                            *cfg, const char *section,
210                                            const char *option, char **value);
211
212
213 /**
214  * Get a configuration value that should be the name of a file
215  * or directory.
216  *
217  * @param cfg configuration to inspect
218  * @param section section of interest
219  * @param option option of interest
220  * @param value will be set to a freshly allocated configuration
221  *        value, or NULL if option is not specified
222  * @return GNUNET_OK on success, GNUNET_SYSERR on error
223  */
224 int GNUNET_CONFIGURATION_get_value_filename (const struct
225                                              GNUNET_CONFIGURATION_Handle *cfg,
226                                              const char *section,
227                                              const char *option,
228                                              char **value);
229
230 /**
231  * Iterate over the set of filenames stored in a configuration value.
232  *
233  * @param cfg configuration to inspect
234  * @param section section of interest
235  * @param option option of interest
236  * @param cb function to call on each filename
237  * @param cb_cls closure for cb
238  * @return number of filenames iterated over, -1 on error
239  */
240 int GNUNET_CONFIGURATION_iterate_value_filenames (const struct
241                                                   GNUNET_CONFIGURATION_Handle
242                                                   *cfg,
243                                                   const char *section,
244                                                   const char *option,
245                                                   GNUNET_FileNameCallback
246                                                   cb, void *cb_cls);
247
248 /**
249  * Get a configuration value that should be in a set of
250  * predefined strings
251  *
252  * @param cfg configuration to inspect
253  * @param section section of interest
254  * @param option option of interest
255  * @param choices NULL-terminated list of legal values
256  * @param value will be set to an entry in the legal list,
257  *        or NULL if option is not specified and no default given
258  * @return GNUNET_OK on success, GNUNET_SYSERR on error
259  */
260 int GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle
261                                            *cfg, const char *section,
262                                            const char *option,
263                                            const char **choices,
264                                            const char **value);
265
266 /**
267  * Get a configuration value that should be in a set of
268  * "YES" or "NO".
269  *
270  * @param cfg configuration to inspect
271  * @param section section of interest
272  * @param option option of interest
273  * @return GNUNET_YES, GNUNET_NO or if option has no valid value, GNUNET_SYSERR
274  */
275 int GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
276                                           *cfg, const char *section,
277                                           const char *option);
278
279 /**
280  * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
281  * where either in the "PATHS" section or the environtment
282  * "FOO" is set to "DIRECTORY".
283  *
284  * @param cfg configuration to use for path expansion
285  * @param orig string to $-expand (will be freed!)
286  * @return $-expanded string
287  */
288 char *GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle
289                                           *cfg, char *orig);
290
291
292 /**
293  * Set a configuration value that should be a number.
294  *
295  * @param cfg configuration to update
296  * @param section section of interest
297  * @param option option of interest
298  * @param number value to set
299  */
300 void
301 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle
302                                        *cfg,
303                                        const char *section,
304                                        const char *option,
305                                        unsigned long long number);
306
307
308 /**
309  * Set a configuration value that should be a string.
310  *
311  * @param cfg configuration to update
312  * @param section section of interest
313  * @param option option of interest
314  * @param value value to set
315  */
316 void
317 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle
318                                        *cfg,
319                                        const char *section,
320                                        const char *option, const char *value);
321
322 /**
323  * Remove a filename from a configuration value that
324  * represents a list of filenames
325  *
326  * @param cfg configuration to update
327  * @param section section of interest
328  * @param option option of interest
329  * @param value filename to remove
330  * @return GNUNET_OK on success,
331  *         GNUNET_SYSERR if the filename is not in the list
332  */
333 int GNUNET_CONFIGURATION_remove_value_filename (struct
334                                                 GNUNET_CONFIGURATION_Handle
335                                                 *cfg,
336                                                 const char *section,
337                                                 const char *option,
338                                                 const char *value);
339
340 /**
341  * Append a filename to a configuration value that
342  * represents a list of filenames
343  *
344  * @param cfg configuration to update
345  * @param section section of interest
346  * @param option option of interest
347  * @param value filename to append
348  * @return GNUNET_OK on success,
349  *         GNUNET_SYSERR if the filename already in the list
350  */
351 int GNUNET_CONFIGURATION_append_value_filename (struct
352                                                 GNUNET_CONFIGURATION_Handle
353                                                 *cfg, const char *section,
354                                                 const char *option,
355                                                 const char *value);
356
357
358 #if 0                           /* keep Emacsens' auto-indent happy */
359 {
360 #endif
361 #ifdef __cplusplus
362 }
363 #endif
364
365 #endif