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 */
41 * A configuration object.
43 struct GNUNET_CONFIGURATION_Handle;
46 * Create a new configuration object.
47 * @return fresh configuration object
49 struct GNUNET_CONFIGURATION_Handle *
50 GNUNET_CONFIGURATION_create (void);
54 * Duplicate an existing configuration object.
56 * @param cfg configuration to duplicate
57 * @return duplicate configuration
59 struct GNUNET_CONFIGURATION_Handle *
60 GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg);
64 * Destroy configuration object.
66 * @param cfg configuration to destroy
69 GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg);
73 * Load configuration. This function will first parse the
74 * defaults and then parse the specific configuration file
75 * to overwrite the defaults.
77 * @param cfg configuration to update
78 * @param filename name of the configuration file, NULL to load defaults
79 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
82 GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
83 const char *filename);
87 * Load default configuration. This function will parse the
88 * defaults from the given defaults_d directory.
90 * @param cfg configuration to update
91 * @param defaults_d directory with the defaults
92 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
95 GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg,
96 const char *defaults_d);
100 * Parse a configuration file, add all of the options in the
101 * file to the configuration environment.
103 * @param cfg configuration to update
104 * @param filename name of the configuration file
105 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
108 GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
109 const char *filename);
113 * Serializes the given configuration.
115 * @param cfg configuration to serialize
116 * @param size will be set to the size of the serialized memory block
117 * @return the memory block where the serialized configuration is
118 * present. This memory should be freed by the caller
121 GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
126 * De-serializes configuration
128 * @param cfg configuration to update
129 * @param mem the memory block of serialized configuration
130 * @param size the size of the memory block
131 * @param allow_inline set to #GNUNET_YES if we recursively load configuration
132 * from inlined configurations; #GNUNET_NO if not and raise warnings
133 * when we come across them
134 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
137 GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
144 * Write configuration file.
146 * @param cfg configuration to write
147 * @param filename where to write the configuration
148 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
151 GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
152 const char *filename);
156 * Write only configuration entries that have been changed to configuration file
157 * @param cfgDefault default configuration
158 * @param cfgNew new configuration
159 * @param filename where to write the configuration diff between default and new
160 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
163 GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
165 const struct GNUNET_CONFIGURATION_Handle
166 *cfgNew, const char *filename);
170 * Compute configuration with only entries that have been changed
172 * @param cfgDefault original configuration
173 * @param cfgNew new configuration
174 * @return configuration with only the differences, never NULL
176 struct GNUNET_CONFIGURATION_Handle *
177 GNUNET_CONFIGURATION_get_diff (const struct GNUNET_CONFIGURATION_Handle
179 const struct GNUNET_CONFIGURATION_Handle
184 * Test if there are configuration options that were
185 * changed since the last save.
187 * @param cfg configuration to inspect
188 * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed)
191 GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
195 * Function to iterate over options.
198 * @param section name of the section
199 * @param option name of the option
200 * @param value value of the option
202 typedef void (*GNUNET_CONFIGURATION_Iterator) (void *cls, const char *section,
208 * Function to iterate over section.
211 * @param section name of the section
213 typedef void (*GNUNET_CONFIGURATION_Section_Iterator) (void *cls,
214 const char *section);
218 * Iterate over all options in the configuration.
220 * @param cfg configuration to inspect
221 * @param iter function to call on each option
222 * @param iter_cls closure for iter
225 GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
226 GNUNET_CONFIGURATION_Iterator iter,
231 * Iterate over all sections in the configuration.
233 * @param cfg configuration to inspect
234 * @param iter function to call on each section
235 * @param iter_cls closure for iter
238 GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle
240 GNUNET_CONFIGURATION_Section_Iterator
241 iter, void *iter_cls);
245 * Remove the given section and all options in it.
247 * @param cfg configuration to inspect
248 * @param section name of the section to remove
251 GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
252 const char *section);
255 * Get a configuration value that should be a number.
257 * @param cfg configuration to inspect
258 * @param section section of interest
259 * @param option option of interest
260 * @param number where to store the numeric value of the option
261 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
264 GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
265 *cfg, const char *section,
267 unsigned long long *number);
271 * Get a configuration value that should be a relative time.
273 * @param cfg configuration to inspect
274 * @param section section of interest
275 * @param option option of interest
276 * @param time set to the time value stored in the configuration
277 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
280 GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
281 *cfg, const char *section,
283 struct GNUNET_TIME_Relative *time);
288 * Get a configuration value that should be a size in bytes.
290 * @param cfg configuration to inspect
291 * @param section section of interest
292 * @param option option of interest
293 * @param size set to the size in bytes as stored in the configuration
294 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
297 GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle
298 *cfg, const char *section,
300 unsigned long long *size);
304 * Test if we have a value for a particular option
306 * @param cfg configuration to inspect
307 * @param section section of interest
308 * @param option option of interest
309 * @return #GNUNET_YES if so, #GNUNET_NO if not.
312 GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
313 const char *section, const char *option);
317 * Get a configuration value that should be a string.
319 * @param cfg configuration to inspect
320 * @param section section of interest
321 * @param option option of interest
322 * @param value will be set to a freshly allocated configuration
323 * value, or NULL if option is not specified
324 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
327 GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
328 *cfg, const char *section,
329 const char *option, char **value);
333 * Get a configuration value that should be the name of a file
336 * @param cfg configuration to inspect
337 * @param section section of interest
338 * @param option option of interest
339 * @param value will be set to a freshly allocated configuration
340 * value, or NULL if option is not specified
341 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
344 GNUNET_CONFIGURATION_get_value_filename (const struct
345 GNUNET_CONFIGURATION_Handle *cfg,
347 const char *option, char **value);
350 * Iterate over the set of filenames stored in a configuration value.
352 * @param cfg configuration to inspect
353 * @param section section of interest
354 * @param option option of interest
355 * @param cb function to call on each filename
356 * @param cb_cls closure for @a cb
357 * @return number of filenames iterated over, -1 on error
360 GNUNET_CONFIGURATION_iterate_value_filenames (const struct
361 GNUNET_CONFIGURATION_Handle *cfg,
364 GNUNET_FileNameCallback cb,
368 * Iterate over values of a section in the configuration.
370 * @param cfg configuration to inspect
371 * @param section the section
372 * @param iter function to call on each option
373 * @param iter_cls closure for @a iter
376 GNUNET_CONFIGURATION_iterate_section_values (const struct
377 GNUNET_CONFIGURATION_Handle *cfg,
379 GNUNET_CONFIGURATION_Iterator iter,
383 * Get a configuration value that should be in a set of
386 * @param cfg configuration to inspect
387 * @param section section of interest
388 * @param option option of interest
389 * @param choices NULL-terminated list of legal values
390 * @param value will be set to an entry in the legal list,
391 * or NULL if option is not specified and no default given
392 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
395 GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle
396 *cfg, const char *section,
397 const char *option, const char **choices,
401 * Get a configuration value that should be in a set of
404 * @param cfg configuration to inspect
405 * @param section section of interest
406 * @param option option of interest
407 * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR
410 GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
411 *cfg, const char *section,
416 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
417 * where either in the "PATHS" section or the environtment
418 * "FOO" is set to "DIRECTORY".
420 * @param cfg configuration to use for path expansion
421 * @param orig string to $-expand (will be freed!)
422 * @return $-expanded string
425 GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle
430 * Set a configuration value that should be a number.
432 * @param cfg configuration to update
433 * @param section section of interest
434 * @param option option of interest
435 * @param number value to set
438 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
439 const char *section, const char *option,
440 unsigned long long number);
444 * Set a configuration value that should be a string.
446 * @param cfg configuration to update
447 * @param section section of interest
448 * @param option option of interest
449 * @param value value to set
452 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
453 const char *section, const char *option,
458 * Remove a filename from a configuration value that
459 * represents a list of filenames
461 * @param cfg configuration to update
462 * @param section section of interest
463 * @param option option of interest
464 * @param value filename to remove
465 * @return #GNUNET_OK on success,
466 * #GNUNET_SYSERR if the filename is not in the list
469 GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle
470 *cfg, const char *section,
475 * Append a filename to a configuration value that
476 * represents a list of filenames
478 * @param cfg configuration to update
479 * @param section section of interest
480 * @param option option of interest
481 * @param value filename to append
482 * @return #GNUNET_OK on success,
483 * #GNUNET_SYSERR if the filename already in the list
486 GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
487 *cfg, const char *section,
491 /** @} */ /* end of group configuration */
493 #if 0 /* keep Emacsens' auto-indent happy */