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 it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
17 * @author Christian Grothoff
22 * @defgroup configuration Configuration library
23 * Configuration management
26 #ifndef GNUNET_CONFIGURATION_LIB_H
27 #define GNUNET_CONFIGURATION_LIB_H
29 #include "gnunet_time_lib.h"
34 #if 0 /* keep Emacsens' auto-indent happy */
40 * A configuration object.
42 struct GNUNET_CONFIGURATION_Handle;
45 * Create a new configuration object.
46 * @return fresh configuration object
48 struct GNUNET_CONFIGURATION_Handle *
49 GNUNET_CONFIGURATION_create (void);
53 * Duplicate an existing configuration object.
55 * @param cfg configuration to duplicate
56 * @return duplicate configuration
58 struct GNUNET_CONFIGURATION_Handle *
59 GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg);
63 * Destroy configuration object.
65 * @param cfg configuration to destroy
68 GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg);
72 * Load configuration. This function will first parse the
73 * defaults and then parse the specific configuration file
74 * to overwrite the defaults.
76 * @param cfg configuration to update
77 * @param filename name of the configuration file, NULL to load defaults
78 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
81 GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
82 const char *filename);
86 * Load default configuration. This function will parse the
87 * defaults from the given @a defaults_d directory.
89 * @param cfg configuration to update
90 * @param defaults_d directory with the defaults
91 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
94 GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg,
95 const char *defaults_d);
99 * Parse a configuration file, add all of the options in the
100 * file to the configuration environment.
102 * @param cfg configuration to update
103 * @param filename name of the configuration file
104 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
107 GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
108 const char *filename);
112 * Serializes the given configuration.
114 * @param cfg configuration to serialize
115 * @param size will be set to the size of the serialized memory block
116 * @return the memory block where the serialized configuration is
117 * present. This memory should be freed by the caller
120 GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
125 * De-serializes configuration
127 * @param cfg configuration to update
128 * @param mem the memory block of serialized configuration
129 * @param size the size of the memory block
130 * @param allow_inline set to the base directory if we recursively load configuration
131 * from inlined configurations; NULL if not and raise warnings
132 * when we come across them
133 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
136 GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
139 const char *basedir);
143 * Write configuration file.
145 * @param cfg configuration to write
146 * @param filename where to write the configuration
147 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
150 GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
151 const char *filename);
155 * Write only configuration entries that have been changed to configuration file
156 * @param cfg_default default configuration
157 * @param cfg_new new configuration
158 * @param filename where to write the configuration diff between default and new
159 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
162 GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle *cfg_default,
163 const struct GNUNET_CONFIGURATION_Handle *cfg_new,
164 const char *filename);
168 * Compute configuration with only entries that have been changed
170 * @param cfg_default original configuration
171 * @param cfg_new new configuration
172 * @return configuration with only the differences, never NULL
174 struct GNUNET_CONFIGURATION_Handle *
175 GNUNET_CONFIGURATION_get_diff (const struct GNUNET_CONFIGURATION_Handle *cfg_default,
176 const struct GNUNET_CONFIGURATION_Handle *cfg_new);
180 * Test if there are configuration options that were
181 * changed since the last save.
183 * @param cfg configuration to inspect
184 * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed)
187 GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
191 * Function to iterate over options.
194 * @param section name of the section
195 * @param option name of the option
196 * @param value value of the option
199 (*GNUNET_CONFIGURATION_Iterator) (void *cls,
206 * Function to iterate over section.
209 * @param section name of the section
212 (*GNUNET_CONFIGURATION_Section_Iterator) (void *cls,
213 const char *section);
217 * Iterate over all options in the configuration.
219 * @param cfg configuration to inspect
220 * @param iter function to call on each option
221 * @param iter_cls closure for @a iter
224 GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
225 GNUNET_CONFIGURATION_Iterator iter,
230 * Iterate over all sections in the configuration.
232 * @param cfg configuration to inspect
233 * @param iter function to call on each section
234 * @param iter_cls closure for @a iter
237 GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle *cfg,
238 GNUNET_CONFIGURATION_Section_Iterator iter,
243 * Remove the given section and all options in it.
245 * @param cfg configuration to inspect
246 * @param section name of the section to remove
249 GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
250 const char *section);
254 * Get a configuration value that should be a number.
256 * @param cfg configuration to inspect
257 * @param section section of interest
258 * @param option option of interest
259 * @param number where to store the numeric value of the option
260 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
263 GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle *cfg,
266 unsigned long long *number);
270 * Get a configuration value that should be a floating point number.
272 * @param cfg configuration to inspect
273 * @param section section of interest
274 * @param option option of interest
275 * @param number where to store the floating value of the option
276 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
279 GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle *cfg,
286 * Get a configuration value that should be a relative time.
288 * @param cfg configuration to inspect
289 * @param section section of interest
290 * @param option option of interest
291 * @param time set to the time value stored in the configuration
292 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
295 GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle *cfg,
298 struct GNUNET_TIME_Relative *time);
303 * Get a configuration value that should be a size in bytes.
305 * @param cfg configuration to inspect
306 * @param section section of interest
307 * @param option option of interest
308 * @param size set to the size in bytes as stored in the configuration
309 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
312 GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle *cfg,
315 unsigned long long *size);
319 * Test if we have a value for a particular option
321 * @param cfg configuration to inspect
322 * @param section section of interest
323 * @param option option of interest
324 * @return #GNUNET_YES if so, #GNUNET_NO if not.
327 GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
333 * Get a configuration value that should be a string.
335 * @param cfg configuration to inspect
336 * @param section section of interest
337 * @param option option of interest
338 * @param value will be set to a freshly allocated configuration
339 * value, or NULL if option is not specified
340 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
343 GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
350 * Get a configuration value that should be the name of a file
353 * @param cfg configuration to inspect
354 * @param section section of interest
355 * @param option option of interest
356 * @param value will be set to a freshly allocated configuration
357 * value, or NULL if option is not specified
358 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
361 GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
368 * Iterate over the set of filenames stored in a configuration value.
370 * @param cfg configuration to inspect
371 * @param section section of interest
372 * @param option option of interest
373 * @param cb function to call on each filename
374 * @param cb_cls closure for @a cb
375 * @return number of filenames iterated over, -1 on error
378 GNUNET_CONFIGURATION_iterate_value_filenames (const struct GNUNET_CONFIGURATION_Handle *cfg,
381 GNUNET_FileNameCallback cb,
385 * Iterate over values of a section in the configuration.
387 * @param cfg configuration to inspect
388 * @param section the section
389 * @param iter function to call on each option
390 * @param iter_cls closure for @a iter
393 GNUNET_CONFIGURATION_iterate_section_values (const struct GNUNET_CONFIGURATION_Handle *cfg,
395 GNUNET_CONFIGURATION_Iterator iter,
399 * Get a configuration value that should be in a set of
402 * @param cfg configuration to inspect
403 * @param section section of interest
404 * @param option option of interest
405 * @param choices NULL-terminated list of legal values
406 * @param value will be set to an entry in the legal list,
407 * or NULL if option is not specified and no default given
408 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
411 GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle *cfg,
414 const char *const *choices,
418 * Get a configuration value that should be in a set of
421 * @param cfg configuration to inspect
422 * @param section section of interest
423 * @param option option of interest
424 * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR
427 GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle *cfg,
433 * Get Crockford32-encoded fixed-size binary data from a configuration.
435 * @param cfg configuration to access
436 * @param section section to access
437 * @param option option to access
438 * @param buf where to store the decoded binary result
439 * @param buf_size exact number of bytes to store in @a buf
440 * @return #GNUNET_OK on success
441 * #GNUNET_NO is the value does not exist
442 * #GNUNET_SYSERR on decoding error
445 GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg,
453 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
454 * where either in the "PATHS" section or the environtment "FOO" is
455 * set to "DIRECTORY". We also support default expansion,
456 * i.e. ${VARIABLE:-default} will expand to $VARIABLE if VARIABLE is
457 * set in PATHS or the environment, and otherwise to "default". Note
458 * that "default" itself can also be a $-expression, thus
459 * "${VAR1:-{$VAR2}}" will expand to VAR1 and if that is not defined
462 * @param cfg configuration to use for path expansion
463 * @param orig string to $-expand (will be freed!) Note that multiple
464 * $-expressions can be present in this string. They will all be
466 * @return $-expanded string
469 GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
474 * Set a configuration value that should be a number.
476 * @param cfg configuration to update
477 * @param section section of interest
478 * @param option option of interest
479 * @param number value to set
482 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
485 unsigned long long number);
489 * Set a configuration value that should be a string.
491 * @param cfg configuration to update
492 * @param section section of interest
493 * @param option option of interest
494 * @param value value to set
497 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
504 * Remove a filename from a configuration value that
505 * represents a list of filenames
507 * @param cfg configuration to update
508 * @param section section of interest
509 * @param option option of interest
510 * @param value filename to remove
511 * @return #GNUNET_OK on success,
512 * #GNUNET_SYSERR if the filename is not in the list
515 GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg,
522 * Append a filename to a configuration value that
523 * represents a list of filenames
525 * @param cfg configuration to update
526 * @param section section of interest
527 * @param option option of interest
528 * @param value filename to append
529 * @return #GNUNET_OK on success,
530 * #GNUNET_SYSERR if the filename already in the list
533 GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg,
538 #if 0 /* keep Emacsens' auto-indent happy */
547 /** @} */ /* end of group configuration */