2 This file is part of GNUnet.
3 Copyright (C) 2006, 2008, 2009 GNUnet e.V.
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 * @author Christian Grothoff
27 * @defgroup configuration Configuration library
28 * Configuration management
31 #ifndef GNUNET_CONFIGURATION_LIB_H
32 #define GNUNET_CONFIGURATION_LIB_H
34 #include "gnunet_time_lib.h"
39 #if 0 /* keep Emacsens' auto-indent happy */
45 * A configuration object.
47 struct GNUNET_CONFIGURATION_Handle;
50 * Create a new configuration object.
51 * @return fresh configuration object
53 struct GNUNET_CONFIGURATION_Handle *
54 GNUNET_CONFIGURATION_create (void);
58 * Duplicate an existing configuration object.
60 * @param cfg configuration to duplicate
61 * @return duplicate configuration
63 struct GNUNET_CONFIGURATION_Handle *
64 GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg);
68 * Destroy configuration object.
70 * @param cfg configuration to destroy
73 GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg);
77 * Load configuration. This function will first parse the
78 * defaults and then parse the specific configuration file
79 * to overwrite the defaults.
81 * @param cfg configuration to update
82 * @param filename name of the configuration file, NULL to load defaults
83 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
86 GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
87 const char *filename);
91 * Load default configuration. This function will parse the
92 * defaults from the given defaults_d directory.
94 * @param cfg configuration to update
95 * @param defaults_d directory with the defaults
96 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
99 GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg,
100 const char *defaults_d);
104 * Parse a configuration file, add all of the options in the
105 * file to the configuration environment.
107 * @param cfg configuration to update
108 * @param filename name of the configuration file
109 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
112 GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
113 const char *filename);
117 * Serializes the given configuration.
119 * @param cfg configuration to serialize
120 * @param size will be set to the size of the serialized memory block
121 * @return the memory block where the serialized configuration is
122 * present. This memory should be freed by the caller
125 GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
130 * De-serializes configuration
132 * @param cfg configuration to update
133 * @param mem the memory block of serialized configuration
134 * @param size the size of the memory block
135 * @param allow_inline set to #GNUNET_YES if we recursively load configuration
136 * from inlined configurations; #GNUNET_NO if not and raise warnings
137 * when we come across them
138 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
141 GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
148 * Write configuration file.
150 * @param cfg configuration to write
151 * @param filename where to write the configuration
152 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
155 GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
156 const char *filename);
160 * Write only configuration entries that have been changed to configuration file
161 * @param cfg_default default configuration
162 * @param cfg_new new configuration
163 * @param filename where to write the configuration diff between default and new
164 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
167 GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle *cfg_default,
168 const struct GNUNET_CONFIGURATION_Handle *cfg_new,
169 const char *filename);
173 * Compute configuration with only entries that have been changed
175 * @param cfg_default original configuration
176 * @param cfg_new 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 *cfg_default,
181 const struct GNUNET_CONFIGURATION_Handle *cfg_new);
185 * Test if there are configuration options that were
186 * changed since the last save.
188 * @param cfg configuration to inspect
189 * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed)
192 GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
196 * Function to iterate over options.
199 * @param section name of the section
200 * @param option name of the option
201 * @param value value of the option
204 (*GNUNET_CONFIGURATION_Iterator) (void *cls,
211 * Function to iterate over section.
214 * @param section name of the section
217 (*GNUNET_CONFIGURATION_Section_Iterator) (void *cls,
218 const char *section);
222 * Iterate over all options in the configuration.
224 * @param cfg configuration to inspect
225 * @param iter function to call on each option
226 * @param iter_cls closure for @a iter
229 GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
230 GNUNET_CONFIGURATION_Iterator iter,
235 * Iterate over all sections in the configuration.
237 * @param cfg configuration to inspect
238 * @param iter function to call on each section
239 * @param iter_cls closure for @a iter
242 GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle *cfg,
243 GNUNET_CONFIGURATION_Section_Iterator iter,
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);
259 * Get a configuration value that should be a number.
261 * @param cfg configuration to inspect
262 * @param section section of interest
263 * @param option option of interest
264 * @param number where to store the numeric value of the option
265 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
268 GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle *cfg,
271 unsigned long long *number);
275 * Get a configuration value that should be a floating point number.
277 * @param cfg configuration to inspect
278 * @param section section of interest
279 * @param option option of interest
280 * @param number where to store the floating value of the option
281 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
284 GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle
285 *cfg, const char *section,
291 * Get a configuration value that should be a relative time.
293 * @param cfg configuration to inspect
294 * @param section section of interest
295 * @param option option of interest
296 * @param time set to the time value stored in the configuration
297 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
300 GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle *cfg,
303 struct GNUNET_TIME_Relative *time);
308 * Get a configuration value that should be a size in bytes.
310 * @param cfg configuration to inspect
311 * @param section section of interest
312 * @param option option of interest
313 * @param size set to the size in bytes as stored in the configuration
314 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
317 GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle *cfg,
320 unsigned long long *size);
324 * Test if we have a value for a particular option
326 * @param cfg configuration to inspect
327 * @param section section of interest
328 * @param option option of interest
329 * @return #GNUNET_YES if so, #GNUNET_NO if not.
332 GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
338 * Get a configuration value that should be a string.
340 * @param cfg configuration to inspect
341 * @param section section of interest
342 * @param option option of interest
343 * @param value will be set to a freshly allocated configuration
344 * value, or NULL if option is not specified
345 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
348 GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
355 * Get a configuration value that should be the name of a file
358 * @param cfg configuration to inspect
359 * @param section section of interest
360 * @param option option of interest
361 * @param value will be set to a freshly allocated configuration
362 * value, or NULL if option is not specified
363 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
366 GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
373 * Iterate over the set of filenames stored in a configuration value.
375 * @param cfg configuration to inspect
376 * @param section section of interest
377 * @param option option of interest
378 * @param cb function to call on each filename
379 * @param cb_cls closure for @a cb
380 * @return number of filenames iterated over, -1 on error
383 GNUNET_CONFIGURATION_iterate_value_filenames (const struct GNUNET_CONFIGURATION_Handle *cfg,
386 GNUNET_FileNameCallback cb,
390 * Iterate over values of a section in the configuration.
392 * @param cfg configuration to inspect
393 * @param section the section
394 * @param iter function to call on each option
395 * @param iter_cls closure for @a iter
398 GNUNET_CONFIGURATION_iterate_section_values (const struct GNUNET_CONFIGURATION_Handle *cfg,
400 GNUNET_CONFIGURATION_Iterator iter,
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 * @param choices NULL-terminated list of legal values
411 * @param value will be set to an entry in the legal list,
412 * or NULL if option is not specified and no default given
413 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
416 GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle *cfg,
419 const char *const *choices,
423 * Get a configuration value that should be in a set of
426 * @param cfg configuration to inspect
427 * @param section section of interest
428 * @param option option of interest
429 * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR
432 GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle *cfg,
438 * Get Crockford32-encoded fixed-size binary data from a configuration.
440 * @param cfg configuration to access
441 * @param section section to access
442 * @param option option to access
443 * @param buf where to store the decoded binary result
444 * @param buf_size exact number of bytes to store in @a buf
445 * @return #GNUNET_OK on success
446 * #GNUNET_NO is the value does not exist
447 * #GNUNET_SYSERR on decoding error
450 GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg,
461 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
462 * where either in the "PATHS" section or the environtment "FOO" is
463 * set to "DIRECTORY". We also support default expansion,
464 * i.e. ${VARIABLE:-default} will expand to $VARIABLE if VARIABLE is
465 * set in PATHS or the environment, and otherwise to "default". Note
466 * that "default" itself can also be a $-expression, thus
467 * "${VAR1:-{$VAR2}}" will expand to VAR1 and if that is not defined
470 * @param cfg configuration to use for path expansion
471 * @param orig string to $-expand (will be freed!) Note that multiple
472 * $-expressions can be present in this string. They will all be
474 * @return $-expanded string
477 GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
482 * Set a configuration value that should be a number.
484 * @param cfg configuration to update
485 * @param section section of interest
486 * @param option option of interest
487 * @param number value to set
490 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
493 unsigned long long number);
497 * Set a configuration value that should be a string.
499 * @param cfg configuration to update
500 * @param section section of interest
501 * @param option option of interest
502 * @param value value to set
505 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
512 * Remove a filename from a configuration value that
513 * represents a list of filenames
515 * @param cfg configuration to update
516 * @param section section of interest
517 * @param option option of interest
518 * @param value filename to remove
519 * @return #GNUNET_OK on success,
520 * #GNUNET_SYSERR if the filename is not in the list
523 GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg,
530 * Append a filename to a configuration value that
531 * represents a list of filenames
533 * @param cfg configuration to update
534 * @param section section of interest
535 * @param option option of interest
536 * @param value filename to append
537 * @return #GNUNET_OK on success,
538 * #GNUNET_SYSERR if the filename already in the list
541 GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg,
546 #if 0 /* keep Emacsens' auto-indent happy */
555 /** @} */ /* end of group configuration */