2 This file is part of GNUnet.
3 Copyright (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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, 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
31 #include "gnunet_time_lib.h"
36 #if 0 /* keep Emacsens' auto-indent happy */
42 * A configuration object.
44 struct GNUNET_CONFIGURATION_Handle;
47 * Create a new configuration object.
48 * @return fresh configuration object
50 struct GNUNET_CONFIGURATION_Handle *
51 GNUNET_CONFIGURATION_create (void);
55 * Duplicate an existing configuration object.
57 * @param cfg configuration to duplicate
58 * @return duplicate configuration
60 struct GNUNET_CONFIGURATION_Handle *
61 GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg);
65 * Destroy configuration object.
67 * @param cfg configuration to destroy
70 GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg);
74 * Load configuration. This function will first parse the
75 * defaults and then parse the specific configuration file
76 * to overwrite the defaults.
78 * @param cfg configuration to update
79 * @param filename name of the configuration file, NULL to load defaults
80 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
83 GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
84 const char *filename);
88 * Load default configuration. This function will parse the
89 * defaults from the given defaults_d directory.
91 * @param cfg configuration to update
92 * @param defaults_d directory with the defaults
93 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
96 GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg,
97 const char *defaults_d);
101 * Parse a configuration file, add all of the options in the
102 * file to the configuration environment.
104 * @param cfg configuration to update
105 * @param filename name of the configuration file
106 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
109 GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
110 const char *filename);
114 * Serializes the given configuration.
116 * @param cfg configuration to serialize
117 * @param size will be set to the size of the serialized memory block
118 * @return the memory block where the serialized configuration is
119 * present. This memory should be freed by the caller
122 GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
127 * De-serializes configuration
129 * @param cfg configuration to update
130 * @param mem the memory block of serialized configuration
131 * @param size the size of the memory block
132 * @param allow_inline set to #GNUNET_YES if we recursively load configuration
133 * from inlined configurations; #GNUNET_NO if not and raise warnings
134 * when we come across them
135 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
138 GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
145 * Write configuration file.
147 * @param cfg configuration to write
148 * @param filename where to write the configuration
149 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
152 GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
153 const char *filename);
157 * Write only configuration entries that have been changed to configuration file
158 * @param cfg_default default configuration
159 * @param cfg_new new configuration
160 * @param filename where to write the configuration diff between default and new
161 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
164 GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle *cfg_default,
165 const struct GNUNET_CONFIGURATION_Handle *cfg_new,
166 const char *filename);
170 * Compute configuration with only entries that have been changed
172 * @param cfg_default original configuration
173 * @param cfg_new 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 *cfg_default,
178 const struct GNUNET_CONFIGURATION_Handle *cfg_new);
182 * Test if there are configuration options that were
183 * changed since the last save.
185 * @param cfg configuration to inspect
186 * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed)
189 GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
193 * Function to iterate over options.
196 * @param section name of the section
197 * @param option name of the option
198 * @param value value of the option
201 (*GNUNET_CONFIGURATION_Iterator) (void *cls,
208 * Function to iterate over section.
211 * @param section name of the section
214 (*GNUNET_CONFIGURATION_Section_Iterator) (void *cls,
215 const char *section);
219 * Iterate over all options in the configuration.
221 * @param cfg configuration to inspect
222 * @param iter function to call on each option
223 * @param iter_cls closure for @a iter
226 GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
227 GNUNET_CONFIGURATION_Iterator iter,
232 * Iterate over all sections in the configuration.
234 * @param cfg configuration to inspect
235 * @param iter function to call on each section
236 * @param iter_cls closure for @a iter
239 GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle *cfg,
240 GNUNET_CONFIGURATION_Section_Iterator iter,
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);
256 * Get a configuration value that should be a number.
258 * @param cfg configuration to inspect
259 * @param section section of interest
260 * @param option option of interest
261 * @param number where to store the numeric value of the option
262 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
265 GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle *cfg,
268 unsigned long long *number);
272 * Get a configuration value that should be a floating point number.
274 * @param cfg configuration to inspect
275 * @param section section of interest
276 * @param option option of interest
277 * @param number where to store the floating value of the option
278 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
281 GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle
282 *cfg, const char *section,
288 * Get a configuration value that should be a relative time.
290 * @param cfg configuration to inspect
291 * @param section section of interest
292 * @param option option of interest
293 * @param time set to the time value stored in the configuration
294 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
297 GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle *cfg,
300 struct GNUNET_TIME_Relative *time);
305 * Get a configuration value that should be a size in bytes.
307 * @param cfg configuration to inspect
308 * @param section section of interest
309 * @param option option of interest
310 * @param size set to the size in bytes as stored in the configuration
311 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
314 GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle *cfg,
317 unsigned long long *size);
321 * Test if we have a value for a particular option
323 * @param cfg configuration to inspect
324 * @param section section of interest
325 * @param option option of interest
326 * @return #GNUNET_YES if so, #GNUNET_NO if not.
329 GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
335 * Get a configuration value that should be a string.
337 * @param cfg configuration to inspect
338 * @param section section of interest
339 * @param option option of interest
340 * @param value will be set to a freshly allocated configuration
341 * value, or NULL if option is not specified
342 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
345 GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
352 * Get a configuration value that should be the name of a file
355 * @param cfg configuration to inspect
356 * @param section section of interest
357 * @param option option of interest
358 * @param value will be set to a freshly allocated configuration
359 * value, or NULL if option is not specified
360 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
363 GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
370 * Iterate over the set of filenames stored in a configuration value.
372 * @param cfg configuration to inspect
373 * @param section section of interest
374 * @param option option of interest
375 * @param cb function to call on each filename
376 * @param cb_cls closure for @a cb
377 * @return number of filenames iterated over, -1 on error
380 GNUNET_CONFIGURATION_iterate_value_filenames (const struct GNUNET_CONFIGURATION_Handle *cfg,
383 GNUNET_FileNameCallback cb,
387 * Iterate over values of a section in the configuration.
389 * @param cfg configuration to inspect
390 * @param section the section
391 * @param iter function to call on each option
392 * @param iter_cls closure for @a iter
395 GNUNET_CONFIGURATION_iterate_section_values (const struct GNUNET_CONFIGURATION_Handle *cfg,
397 GNUNET_CONFIGURATION_Iterator iter,
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 * @param choices NULL-terminated list of legal values
408 * @param value will be set to an entry in the legal list,
409 * or NULL if option is not specified and no default given
410 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
413 GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle *cfg,
416 const char *const *choices,
420 * Get a configuration value that should be in a set of
423 * @param cfg configuration to inspect
424 * @param section section of interest
425 * @param option option of interest
426 * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR
429 GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle *cfg,
435 * Get Crockford32-encoded fixed-size binary data from a configuration.
437 * @param cfg configuration to access
438 * @param section section to access
439 * @param option option to access
440 * @param buf where to store the decoded binary result
441 * @param buf_size exact number of bytes to store in @a buf
442 * @return #GNUNET_OK on success
443 * #GNUNET_NO is the value does not exist
444 * #GNUNET_SYSERR on decoding error
447 GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg,
458 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
459 * where either in the "PATHS" section or the environtment "FOO" is
460 * set to "DIRECTORY". We also support default expansion,
461 * i.e. ${VARIABLE:-default} will expand to $VARIABLE if VARIABLE is
462 * set in PATHS or the environment, and otherwise to "default". Note
463 * that "default" itself can also be a $-expression, thus
464 * "${VAR1:-{$VAR2}}" will expand to VAR1 and if that is not defined
467 * @param cfg configuration to use for path expansion
468 * @param orig string to $-expand (will be freed!) Note that multiple
469 * $-expressions can be present in this string. They will all be
471 * @return $-expanded string
474 GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
479 * Set a configuration value that should be a number.
481 * @param cfg configuration to update
482 * @param section section of interest
483 * @param option option of interest
484 * @param number value to set
487 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
490 unsigned long long number);
494 * Set a configuration value that should be a string.
496 * @param cfg configuration to update
497 * @param section section of interest
498 * @param option option of interest
499 * @param value value to set
502 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
509 * Remove a filename from a configuration value that
510 * represents a list of filenames
512 * @param cfg configuration to update
513 * @param section section of interest
514 * @param option option of interest
515 * @param value filename to remove
516 * @return #GNUNET_OK on success,
517 * #GNUNET_SYSERR if the filename is not in the list
520 GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg,
527 * Append a filename to a configuration value that
528 * represents a list of filenames
530 * @param cfg configuration to update
531 * @param section section of interest
532 * @param option option of interest
533 * @param value filename to append
534 * @return #GNUNET_OK on success,
535 * #GNUNET_SYSERR if the filename already in the list
538 GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg,
543 /** @} */ /* end of group configuration */
545 #if 0 /* keep Emacsens' auto-indent happy */