2 This file is part of GNUnet.
3 (C) 2006, 2008, 2009 Christian Grothoff (and other contributing authors)
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 3, or (at your
8 option) any later version.
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.
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.
22 * @file include/gnunet_configuration_lib.h
23 * @brief configuration API
24 * @author Christian Grothoff
25 * @defgroup configuration Configuration management
28 #ifndef GNUNET_CONFIGURATION_LIB_H
29 #define GNUNET_CONFIGURATION_LIB_H
35 #if 0 /* keep Emacsens' auto-indent happy */
40 #include "gnunet_common.h"
41 #include "gnunet_time_lib.h"
44 * A configuration object.
46 struct GNUNET_CONFIGURATION_Handle;
49 * Create a new configuration object.
50 * @return fresh configuration object
52 struct GNUNET_CONFIGURATION_Handle *
53 GNUNET_CONFIGURATION_create (void);
57 * Duplicate an existing configuration object.
59 * @param cfg configuration to duplicate
60 * @return duplicate configuration
62 struct GNUNET_CONFIGURATION_Handle *
63 GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg);
67 * Destroy configuration object.
69 * @param cfg configuration to destroy
72 GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg);
76 * Load configuration. This function will first parse the
77 * defaults and then parse the specific configuration file
78 * to overwrite the defaults.
80 * @param cfg configuration to update
81 * @param filename name of the configuration file, NULL to load defaults
82 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
85 GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
86 const char *filename);
90 * Load default configuration. This function will parse the
91 * defaults from the given defaults_d directory.
93 * @param cfg configuration to update
94 * @param defaults_d directory with the defaults
95 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
98 GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg,
99 const char *defaults_d);
103 * Parse a configuration file, add all of the options in the
104 * file to the configuration environment.
106 * @param cfg configuration to update
107 * @param filename name of the configuration file
108 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
111 GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
112 const char *filename);
116 * Serializes the given configuration.
118 * @param cfg configuration to serialize
119 * @param size will be set to the size of the serialized memory block
120 * @return the memory block where the serialized configuration is
121 * present. This memory should be freed by the caller
124 GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
129 * De-serializes configuration
131 * @param cfg configuration to update
132 * @param mem the memory block of serialized configuration
133 * @param size the size of the memory block
134 * @param allow_inline set to #GNUNET_YES if we recursively load configuration
135 * from inlined configurations; #GNUNET_NO if not and raise warnings
136 * when we come across them
137 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
140 GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
147 * Write configuration file.
149 * @param cfg configuration to write
150 * @param filename where to write the configuration
151 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
154 GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
155 const char *filename);
159 * Write only configuration entries that have been changed to configuration file
160 * @param cfgDefault default configuration
161 * @param cfgNew new configuration
162 * @param filename where to write the configuration diff between default and new
163 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
166 GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
168 const struct GNUNET_CONFIGURATION_Handle
169 *cfgNew, const char *filename);
173 * Compute configuration with only entries that have been changed
175 * @param cfgDefault original configuration
176 * @param cfgNew new configuration
177 * @return configuration with only the differences, never NULL
179 struct GNUNET_CONFIGURATION_Handle *
180 GNUNET_CONFIGURATION_get_diff (const struct GNUNET_CONFIGURATION_Handle
182 const struct GNUNET_CONFIGURATION_Handle
187 * Test if there are configuration options that were
188 * changed since the last save.
190 * @param cfg configuration to inspect
191 * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed)
194 GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
198 * Function to iterate over options.
201 * @param section name of the section
202 * @param option name of the option
203 * @param value value of the option
205 typedef void (*GNUNET_CONFIGURATION_Iterator) (void *cls, const char *section,
211 * Function to iterate over section.
214 * @param section name of the section
216 typedef void (*GNUNET_CONFIGURATION_Section_Iterator) (void *cls,
217 const char *section);
221 * Iterate over all options in the configuration.
223 * @param cfg configuration to inspect
224 * @param iter function to call on each option
225 * @param iter_cls closure for iter
228 GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
229 GNUNET_CONFIGURATION_Iterator iter,
234 * Iterate over all sections in the configuration.
236 * @param cfg configuration to inspect
237 * @param iter function to call on each section
238 * @param iter_cls closure for iter
241 GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle
243 GNUNET_CONFIGURATION_Section_Iterator
244 iter, void *iter_cls);
248 * Remove the given section and all options in it.
250 * @param cfg configuration to inspect
251 * @param section name of the section to remove
254 GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
255 const char *section);
258 * Get a configuration value that should be a number.
260 * @param cfg configuration to inspect
261 * @param section section of interest
262 * @param option option of interest
263 * @param number where to store the numeric value of the option
264 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
267 GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
268 *cfg, const char *section,
270 unsigned long long *number);
274 * Get a configuration value that should be a relative time.
276 * @param cfg configuration to inspect
277 * @param section section of interest
278 * @param option option of interest
279 * @param time set to the time value stored in the configuration
280 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
283 GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
284 *cfg, const char *section,
286 struct GNUNET_TIME_Relative *time);
291 * Get a configuration value that should be a size in bytes.
293 * @param cfg configuration to inspect
294 * @param section section of interest
295 * @param option option of interest
296 * @param size set to the size in bytes as stored in the configuration
297 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
300 GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle
301 *cfg, const char *section,
303 unsigned long long *size);
307 * Test if we have a value for a particular option
309 * @param cfg configuration to inspect
310 * @param section section of interest
311 * @param option option of interest
312 * @return #GNUNET_YES if so, #GNUNET_NO if not.
315 GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
316 const char *section, const char *option);
320 * Get a configuration value that should be a string.
322 * @param cfg configuration to inspect
323 * @param section section of interest
324 * @param option option of interest
325 * @param value will be set to a freshly allocated configuration
326 * value, or NULL if option is not specified
327 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
330 GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
331 *cfg, const char *section,
332 const char *option, char **value);
336 * Get a configuration value that should be the name of a file
339 * @param cfg configuration to inspect
340 * @param section section of interest
341 * @param option option of interest
342 * @param value will be set to a freshly allocated configuration
343 * value, or NULL if option is not specified
344 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
347 GNUNET_CONFIGURATION_get_value_filename (const struct
348 GNUNET_CONFIGURATION_Handle *cfg,
350 const char *option, char **value);
353 * Iterate over the set of filenames stored in a configuration value.
355 * @param cfg configuration to inspect
356 * @param section section of interest
357 * @param option option of interest
358 * @param cb function to call on each filename
359 * @param cb_cls closure for @a cb
360 * @return number of filenames iterated over, -1 on error
363 GNUNET_CONFIGURATION_iterate_value_filenames (const struct
364 GNUNET_CONFIGURATION_Handle *cfg,
367 GNUNET_FileNameCallback cb,
371 * Iterate over values of a section in the configuration.
373 * @param cfg configuration to inspect
374 * @param section the section
375 * @param iter function to call on each option
376 * @param iter_cls closure for @a iter
379 GNUNET_CONFIGURATION_iterate_section_values (const struct
380 GNUNET_CONFIGURATION_Handle *cfg,
382 GNUNET_CONFIGURATION_Iterator iter,
386 * Get a configuration value that should be in a set of
389 * @param cfg configuration to inspect
390 * @param section section of interest
391 * @param option option of interest
392 * @param choices NULL-terminated list of legal values
393 * @param value will be set to an entry in the legal list,
394 * or NULL if option is not specified and no default given
395 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
398 GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle
399 *cfg, const char *section,
400 const char *option, const char **choices,
404 * Get a configuration value that should be in a set of
407 * @param cfg configuration to inspect
408 * @param section section of interest
409 * @param option option of interest
410 * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR
413 GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
414 *cfg, const char *section,
419 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
420 * where either in the "PATHS" section or the environtment
421 * "FOO" is set to "DIRECTORY".
423 * @param cfg configuration to use for path expansion
424 * @param orig string to $-expand (will be freed!)
425 * @return $-expanded string
428 GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle
433 * Set a configuration value that should be a number.
435 * @param cfg configuration to update
436 * @param section section of interest
437 * @param option option of interest
438 * @param number value to set
441 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
442 const char *section, const char *option,
443 unsigned long long number);
447 * Set a configuration value that should be a string.
449 * @param cfg configuration to update
450 * @param section section of interest
451 * @param option option of interest
452 * @param value value to set
455 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
456 const char *section, const char *option,
461 * Remove a filename from a configuration value that
462 * represents a list of filenames
464 * @param cfg configuration to update
465 * @param section section of interest
466 * @param option option of interest
467 * @param value filename to remove
468 * @return #GNUNET_OK on success,
469 * #GNUNET_SYSERR if the filename is not in the list
472 GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle
473 *cfg, const char *section,
478 * Append a filename to a configuration value that
479 * represents a list of filenames
481 * @param cfg configuration to update
482 * @param section section of interest
483 * @param option option of interest
484 * @param value filename to append
485 * @return #GNUNET_OK on success,
486 * #GNUNET_SYSERR if the filename already in the list
489 GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
490 *cfg, const char *section,
494 /** @} */ /* end of group configuration */
496 #if 0 /* keep Emacsens' auto-indent happy */