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 2, 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
25 * @author Christian Grothoff
28 #ifndef GNUNET_CONFIGURATION_LIB_H
29 #define GNUNET_CONFIGURATION_LIB_H
35 #if 0 /* keep Emacsens' auto-indent happy */
40 #include "gnunet_common.h"
41 #include "gnunet_time_lib.h"
44 * A configuration object.
46 struct GNUNET_CONFIGURATION_Handle;
49 * Create a new configuration object.
50 * @return fresh configuration object
52 struct GNUNET_CONFIGURATION_Handle *
53 GNUNET_CONFIGURATION_create (void);
57 * Duplicate an existing configuration object.
59 * @param cfg configuration to duplicate
60 * @return duplicate configuration
62 struct GNUNET_CONFIGURATION_Handle *
63 GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg);
67 * Destroy configuration object.
69 * @param cfg configuration to destroy
72 GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg);
76 * Load configuration. This function will first parse the
77 * defaults and then parse the specific configuration file
78 * to overwrite the defaults.
80 * @param cfg configuration to update
81 * @param filename name of the configuration file, NULL to load defaults
82 * @return GNUNET_OK on success, GNUNET_SYSERR on error
85 GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
86 const char *filename);
90 * Load default configuration. This function will parse the
91 * defaults from the given defaults_d directory.
93 * @param cfg configuration to update
94 * @param defaults_d directory with the defaults
95 * @return GNUNET_OK on success, GNUNET_SYSERR on error
98 GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg,
99 const char *defaults_d);
103 * Parse a configuration file, add all of the options in the
104 * file to the configuration environment.
106 * @param cfg configuration to update
107 * @param filename name of the configuration file
108 * @return GNUNET_OK on success, GNUNET_SYSERR on error
111 GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
112 const char *filename);
116 * Serializes the given configuration.
118 * @param cfg configuration to serialize
119 * @param size will be set to the size of the serialized memory block
120 * @return the memory block where the serialized configuration is
121 * present. This memory should be freed by the caller
124 GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
129 * De-serializes configuration
131 * @param cfg configuration to update
132 * @param mem the memory block of serialized configuration
133 * @param size the size of the memory block
134 * @param allow_inline set to GNUNET_YES if we recursively load configuration
135 * from inlined configurations; GNUNET_NO if not and raise warnings
136 * when we come across them
137 * @return GNUNET_OK on success, GNUNET_ERROR on error
140 GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
147 * Write configuration file.
149 * @param cfg configuration to write
150 * @param filename where to write the configuration
151 * @return GNUNET_OK on success, GNUNET_SYSERR on error
154 GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
155 const char *filename);
158 * Write only configuration entries that have been changed to configuration file
159 * @param cfgDefault default configuration
160 * @param cfgNew new configuration
161 * @param filename where to write the configuration diff between default and new
162 * @return GNUNET_OK on success, GNUNET_SYSERR on error
165 GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
167 const struct GNUNET_CONFIGURATION_Handle
168 *cfgNew, const char *filename);
171 * Test if there are configuration options that were
172 * changed since the last save.
174 * @param cfg configuration to inspect
175 * @return GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error (i.e. last save failed)
178 GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
182 * Function to iterate over options.
185 * @param section name of the section
186 * @param option name of the option
187 * @param value value of the option
189 typedef void (*GNUNET_CONFIGURATION_Iterator) (void *cls, const char *section,
195 * Function to iterate over section.
198 * @param section name of the section
200 typedef void (*GNUNET_CONFIGURATION_Section_Iterator) (void *cls,
201 const char *section);
205 * Iterate over all options in the configuration.
207 * @param cfg configuration to inspect
208 * @param iter function to call on each option
209 * @param iter_cls closure for iter
212 GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
213 GNUNET_CONFIGURATION_Iterator iter,
218 * Iterate over all sections in the configuration.
220 * @param cfg configuration to inspect
221 * @param iter function to call on each section
222 * @param iter_cls closure for iter
225 GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle
227 GNUNET_CONFIGURATION_Section_Iterator
228 iter, void *iter_cls);
232 * Remove the given section and all options in it.
234 * @param cfg configuration to inspect
235 * @param section name of the section to remove
238 GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
239 const char *section);
242 * Get a configuration value that should be a number.
244 * @param cfg configuration to inspect
245 * @param section section of interest
246 * @param option option of interest
247 * @param number where to store the numeric value of the option
248 * @return GNUNET_OK on success, GNUNET_SYSERR on error
251 GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
252 *cfg, const char *section,
254 unsigned long long *number);
258 * Get a configuration value that should be a relative time.
260 * @param cfg configuration to inspect
261 * @param section section of interest
262 * @param option option of interest
263 * @param time set to the time value stored in the configuration
264 * @return GNUNET_OK on success, GNUNET_SYSERR on error
267 GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
268 *cfg, const char *section,
270 struct GNUNET_TIME_Relative *time);
275 * Get a configuration value that should be a size in bytes.
277 * @param cfg configuration to inspect
278 * @param section section of interest
279 * @param option option of interest
280 * @param size set to the size in bytes as stored in the configuration
281 * @return GNUNET_OK on success, GNUNET_SYSERR on error
284 GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle
285 *cfg, const char *section,
287 unsigned long long *size);
291 * Test if we have a value for a particular option
293 * @param cfg configuration to inspect
294 * @param section section of interest
295 * @param option option of interest
296 * @return GNUNET_YES if so, GNUNET_NO if not.
299 GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
300 const char *section, const char *option);
304 * Get a configuration value that should be a string.
306 * @param cfg configuration to inspect
307 * @param section section of interest
308 * @param option option of interest
309 * @param value will be set to a freshly allocated configuration
310 * value, or NULL if option is not specified
311 * @return GNUNET_OK on success, GNUNET_SYSERR on error
314 GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
315 *cfg, const char *section,
316 const char *option, char **value);
320 * Get a configuration value that should be the name of a file
323 * @param cfg configuration to inspect
324 * @param section section of interest
325 * @param option option of interest
326 * @param value will be set to a freshly allocated configuration
327 * value, or NULL if option is not specified
328 * @return GNUNET_OK on success, GNUNET_SYSERR on error
331 GNUNET_CONFIGURATION_get_value_filename (const struct
332 GNUNET_CONFIGURATION_Handle *cfg,
334 const char *option, char **value);
337 * Iterate over the set of filenames stored in a configuration value.
339 * @param cfg configuration to inspect
340 * @param section section of interest
341 * @param option option of interest
342 * @param cb function to call on each filename
343 * @param cb_cls closure for cb
344 * @return number of filenames iterated over, -1 on error
347 GNUNET_CONFIGURATION_iterate_value_filenames (const struct
348 GNUNET_CONFIGURATION_Handle *cfg,
351 GNUNET_FileNameCallback cb,
355 * Iterate over values of a section in the configuration.
357 * @param cfg configuration to inspect
358 * @param section the section
359 * @param iter function to call on each option
360 * @param iter_cls closure for iter
363 GNUNET_CONFIGURATION_iterate_section_values (const struct
364 GNUNET_CONFIGURATION_Handle *cfg,
366 GNUNET_CONFIGURATION_Iterator iter,
370 * Get a configuration value that should be in a set of
373 * @param cfg configuration to inspect
374 * @param section section of interest
375 * @param option option of interest
376 * @param choices NULL-terminated list of legal values
377 * @param value will be set to an entry in the legal list,
378 * or NULL if option is not specified and no default given
379 * @return GNUNET_OK on success, GNUNET_SYSERR on error
382 GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle
383 *cfg, const char *section,
384 const char *option, const char **choices,
388 * Get a configuration value that should be in a set of
391 * @param cfg configuration to inspect
392 * @param section section of interest
393 * @param option option of interest
394 * @return GNUNET_YES, GNUNET_NO or if option has no valid value, GNUNET_SYSERR
397 GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
398 *cfg, const char *section,
403 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
404 * where either in the "PATHS" section or the environtment
405 * "FOO" is set to "DIRECTORY".
407 * @param cfg configuration to use for path expansion
408 * @param orig string to $-expand (will be freed!)
409 * @return $-expanded string
412 GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle
417 * Set a configuration value that should be a number.
419 * @param cfg configuration to update
420 * @param section section of interest
421 * @param option option of interest
422 * @param number value to set
425 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
426 const char *section, const char *option,
427 unsigned long long number);
431 * Set a configuration value that should be a string.
433 * @param cfg configuration to update
434 * @param section section of interest
435 * @param option option of interest
436 * @param value value to set
439 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
440 const char *section, const char *option,
445 * Remove a filename from a configuration value that
446 * represents a list of filenames
448 * @param cfg configuration to update
449 * @param section section of interest
450 * @param option option of interest
451 * @param value filename to remove
452 * @return GNUNET_OK on success,
453 * GNUNET_SYSERR if the filename is not in the list
456 GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle
457 *cfg, const char *section,
462 * Append a filename to a configuration value that
463 * represents a list of filenames
465 * @param cfg configuration to update
466 * @param section section of interest
467 * @param option option of interest
468 * @param value filename to append
469 * @return GNUNET_OK on success,
470 * GNUNET_SYSERR if the filename already in the list
473 GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
474 *cfg, const char *section,
479 #if 0 /* keep Emacsens' auto-indent happy */