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 cfg_default default configuration
158 * @param cfg_new 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 *cfg_default,
164 const struct GNUNET_CONFIGURATION_Handle *cfg_new,
165 const char *filename);
169 * Compute configuration with only entries that have been changed
171 * @param cfg_default original configuration
172 * @param cfg_new new configuration
173 * @return configuration with only the differences, never NULL
175 struct GNUNET_CONFIGURATION_Handle *
176 GNUNET_CONFIGURATION_get_diff (const struct GNUNET_CONFIGURATION_Handle *cfg_default,
177 const struct GNUNET_CONFIGURATION_Handle *cfg_new);
181 * Test if there are configuration options that were
182 * changed since the last save.
184 * @param cfg configuration to inspect
185 * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed)
188 GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
192 * Function to iterate over options.
195 * @param section name of the section
196 * @param option name of the option
197 * @param value value of the option
200 (*GNUNET_CONFIGURATION_Iterator) (void *cls,
207 * Function to iterate over section.
210 * @param section name of the section
213 (*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 @a 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 @a iter
238 GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle *cfg,
239 GNUNET_CONFIGURATION_Section_Iterator iter,
244 * Remove the given section and all options in it.
246 * @param cfg configuration to inspect
247 * @param section name of the section to remove
250 GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
251 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 *cfg,
267 unsigned long long *number);
271 * Get a configuration value that should be a floating point number.
273 * @param cfg configuration to inspect
274 * @param section section of interest
275 * @param option option of interest
276 * @param number where to store the floating value of the option
277 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
280 GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle
281 *cfg, const char *section,
287 * Get a configuration value that should be a relative time.
289 * @param cfg configuration to inspect
290 * @param section section of interest
291 * @param option option of interest
292 * @param time set to the time value stored in the configuration
293 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
296 GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle *cfg,
299 struct GNUNET_TIME_Relative *time);
304 * Get a configuration value that should be a size in bytes.
306 * @param cfg configuration to inspect
307 * @param section section of interest
308 * @param option option of interest
309 * @param size set to the size in bytes as stored in the configuration
310 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
313 GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle *cfg,
316 unsigned long long *size);
320 * Test if we have a value for a particular option
322 * @param cfg configuration to inspect
323 * @param section section of interest
324 * @param option option of interest
325 * @return #GNUNET_YES if so, #GNUNET_NO if not.
328 GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
334 * Get a configuration value that should be a string.
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_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
351 * Get a configuration value that should be the name of a file
354 * @param cfg configuration to inspect
355 * @param section section of interest
356 * @param option option of interest
357 * @param value will be set to a freshly allocated configuration
358 * value, or NULL if option is not specified
359 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
362 GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
369 * Iterate over the set of filenames stored in a configuration value.
371 * @param cfg configuration to inspect
372 * @param section section of interest
373 * @param option option of interest
374 * @param cb function to call on each filename
375 * @param cb_cls closure for @a cb
376 * @return number of filenames iterated over, -1 on error
379 GNUNET_CONFIGURATION_iterate_value_filenames (const struct GNUNET_CONFIGURATION_Handle *cfg,
382 GNUNET_FileNameCallback cb,
386 * Iterate over values of a section in the configuration.
388 * @param cfg configuration to inspect
389 * @param section the section
390 * @param iter function to call on each option
391 * @param iter_cls closure for @a iter
394 GNUNET_CONFIGURATION_iterate_section_values (const struct GNUNET_CONFIGURATION_Handle *cfg,
396 GNUNET_CONFIGURATION_Iterator iter,
400 * Get a configuration value that should be in a set of
403 * @param cfg configuration to inspect
404 * @param section section of interest
405 * @param option option of interest
406 * @param choices NULL-terminated list of legal values
407 * @param value will be set to an entry in the legal list,
408 * or NULL if option is not specified and no default given
409 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
412 GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle *cfg,
415 const char *const *choices,
419 * Get a configuration value that should be in a set of
422 * @param cfg configuration to inspect
423 * @param section section of interest
424 * @param option option of interest
425 * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR
428 GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle *cfg,
434 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
435 * where either in the "PATHS" section or the environtment "FOO" is
436 * set to "DIRECTORY". We also support default expansion,
437 * i.e. ${VARIABLE:-default} will expand to $VARIABLE if VARIABLE is
438 * set in PATHS or the environment, and otherwise to "default". Note
439 * that "default" itself can also be a $-expression, thus
440 * "${VAR1:-{$VAR2}}" will expand to VAR1 and if that is not defined
443 * @param cfg configuration to use for path expansion
444 * @param orig string to $-expand (will be freed!) Note that multiple
445 * $-expressions can be present in this string. They will all be
447 * @return $-expanded string
450 GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
455 * Set a configuration value that should be a number.
457 * @param cfg configuration to update
458 * @param section section of interest
459 * @param option option of interest
460 * @param number value to set
463 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
466 unsigned long long number);
470 * Set a configuration value that should be a string.
472 * @param cfg configuration to update
473 * @param section section of interest
474 * @param option option of interest
475 * @param value value to set
478 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
485 * Remove a filename from a configuration value that
486 * represents a list of filenames
488 * @param cfg configuration to update
489 * @param section section of interest
490 * @param option option of interest
491 * @param value filename to remove
492 * @return #GNUNET_OK on success,
493 * #GNUNET_SYSERR if the filename is not in the list
496 GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg,
503 * Append a filename to a configuration value that
504 * represents a list of filenames
506 * @param cfg configuration to update
507 * @param section section of interest
508 * @param option option of interest
509 * @param value filename to append
510 * @return #GNUNET_OK on success,
511 * #GNUNET_SYSERR if the filename already in the list
514 GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg,
519 /** @} */ /* end of group configuration */
521 #if 0 /* keep Emacsens' auto-indent happy */