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 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 *cfg,
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 *cfg,
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,
318 * Get a configuration value that should be a string.
320 * @param cfg configuration to inspect
321 * @param section section of interest
322 * @param option option of interest
323 * @param value will be set to a freshly allocated configuration
324 * value, or NULL if option is not specified
325 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
328 GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
335 * Get a configuration value that should be the name of a file
338 * @param cfg configuration to inspect
339 * @param section section of interest
340 * @param option option of interest
341 * @param value will be set to a freshly allocated configuration
342 * value, or NULL if option is not specified
343 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
346 GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
353 * Iterate over the set of filenames stored in a configuration value.
355 * @param cfg configuration to inspect
356 * @param section section of interest
357 * @param option option of interest
358 * @param cb function to call on each filename
359 * @param cb_cls closure for @a cb
360 * @return number of filenames iterated over, -1 on error
363 GNUNET_CONFIGURATION_iterate_value_filenames (const struct GNUNET_CONFIGURATION_Handle *cfg,
366 GNUNET_FileNameCallback cb,
370 * Iterate over values of a section in the configuration.
372 * @param cfg configuration to inspect
373 * @param section the section
374 * @param iter function to call on each option
375 * @param iter_cls closure for @a iter
378 GNUNET_CONFIGURATION_iterate_section_values (const struct GNUNET_CONFIGURATION_Handle *cfg,
380 GNUNET_CONFIGURATION_Iterator iter,
384 * Get a configuration value that should be in a set of
387 * @param cfg configuration to inspect
388 * @param section section of interest
389 * @param option option of interest
390 * @param choices NULL-terminated list of legal values
391 * @param value will be set to an entry in the legal list,
392 * or NULL if option is not specified and no default given
393 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
396 GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle *cfg,
399 const char *const *choices,
403 * Get a configuration value that should be in a set of
406 * @param cfg configuration to inspect
407 * @param section section of interest
408 * @param option option of interest
409 * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR
412 GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle *cfg,
418 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
419 * where either in the "PATHS" section or the environtment "FOO" is
420 * set to "DIRECTORY". We also support default expansion,
421 * i.e. ${VARIABLE:-default} will expand to $VARIABLE if VARIABLE is
422 * set in PATHS or the environment, and otherwise to "default". Note
423 * that "default" itself can also be a $-expression, thus
424 * "${VAR1:-{$VAR2}}" will expand to VAR1 and if that is not defined
427 * @param cfg configuration to use for path expansion
428 * @param orig string to $-expand (will be freed!) Note that multiple
429 * $-expressions can be present in this string. They will all be
431 * @return $-expanded string
434 GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
439 * Set a configuration value that should be a number.
441 * @param cfg configuration to update
442 * @param section section of interest
443 * @param option option of interest
444 * @param number value to set
447 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
450 unsigned long long number);
454 * Set a configuration value that should be a string.
456 * @param cfg configuration to update
457 * @param section section of interest
458 * @param option option of interest
459 * @param value value to set
462 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
469 * Remove a filename from a configuration value that
470 * represents a list of filenames
472 * @param cfg configuration to update
473 * @param section section of interest
474 * @param option option of interest
475 * @param value filename to remove
476 * @return #GNUNET_OK on success,
477 * #GNUNET_SYSERR if the filename is not in the list
480 GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg,
487 * Append a filename to a configuration value that
488 * represents a list of filenames
490 * @param cfg configuration to update
491 * @param section section of interest
492 * @param option option of interest
493 * @param value filename to append
494 * @return #GNUNET_OK on success,
495 * #GNUNET_SYSERR if the filename already in the list
498 GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg,
503 /** @} */ /* end of group configuration */
505 #if 0 /* keep Emacsens' auto-indent happy */