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 * Write configuration file.
118 * @param cfg configuration to write
119 * @param filename where to write the configuration
120 * @return GNUNET_OK on success, GNUNET_SYSERR on error
123 GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
124 const char *filename);
127 * Write only configuration entries that have been changed to configuration file
128 * @param cfgDefault default configuration
129 * @param cfgNew new configuration
130 * @param filename where to write the configuration diff between default and new
131 * @return GNUNET_OK on success, GNUNET_SYSERR on error
134 GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
136 const struct GNUNET_CONFIGURATION_Handle
137 *cfgNew, const char *filename);
140 * Test if there are configuration options that were
141 * changed since the last save.
143 * @param cfg configuration to inspect
144 * @return GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error (i.e. last save failed)
147 GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
151 * Function to iterate over options.
154 * @param section name of the section
155 * @param option name of the option
156 * @param value value of the option
158 typedef void (*GNUNET_CONFIGURATION_Iterator) (void *cls, const char *section,
164 * Function to iterate over section.
167 * @param section name of the section
169 typedef void (*GNUNET_CONFIGURATION_Section_Iterator) (void *cls,
170 const char *section);
174 * Iterate over all options in the configuration.
176 * @param cfg configuration to inspect
177 * @param iter function to call on each option
178 * @param iter_cls closure for iter
181 GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
182 GNUNET_CONFIGURATION_Iterator iter,
187 * Iterate over all sections in the configuration.
189 * @param cfg configuration to inspect
190 * @param iter function to call on each section
191 * @param iter_cls closure for iter
194 GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle
196 GNUNET_CONFIGURATION_Section_Iterator
197 iter, void *iter_cls);
201 * Remove the given section and all options in it.
203 * @param cfg configuration to inspect
204 * @param section name of the section to remove
207 GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
208 const char *section);
211 * Get a configuration value that should be a number.
213 * @param cfg configuration to inspect
214 * @param section section of interest
215 * @param option option of interest
216 * @param number where to store the numeric value of the option
217 * @return GNUNET_OK on success, GNUNET_SYSERR on error
220 GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
221 *cfg, const char *section,
223 unsigned long long *number);
227 * Get a configuration value that should be a relative time.
229 * @param cfg configuration to inspect
230 * @param section section of interest
231 * @param option option of interest
232 * @param time set to the time value stored in the configuration
233 * @return GNUNET_OK on success, GNUNET_SYSERR on error
236 GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
237 *cfg, const char *section,
239 struct GNUNET_TIME_Relative *time);
244 * Get a configuration value that should be a size in bytes.
246 * @param cfg configuration to inspect
247 * @param section section of interest
248 * @param option option of interest
249 * @param size set to the size in bytes as stored in the configuration
250 * @return GNUNET_OK on success, GNUNET_SYSERR on error
253 GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle
254 *cfg, const char *section,
256 unsigned long long *size);
260 * Test if we have a value for a particular option
262 * @param cfg configuration to inspect
263 * @param section section of interest
264 * @param option option of interest
265 * @return GNUNET_YES if so, GNUNET_NO if not.
268 GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
269 const char *section, const char *option);
273 * Get a configuration value that should be a string.
275 * @param cfg configuration to inspect
276 * @param section section of interest
277 * @param option option of interest
278 * @param value will be set to a freshly allocated configuration
279 * value, or NULL if option is not specified
280 * @return GNUNET_OK on success, GNUNET_SYSERR on error
283 GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
284 *cfg, const char *section,
285 const char *option, char **value);
289 * Get a configuration value that should be the name of a file
292 * @param cfg configuration to inspect
293 * @param section section of interest
294 * @param option option of interest
295 * @param value will be set to a freshly allocated configuration
296 * value, or NULL if option is not specified
297 * @return GNUNET_OK on success, GNUNET_SYSERR on error
300 GNUNET_CONFIGURATION_get_value_filename (const struct
301 GNUNET_CONFIGURATION_Handle *cfg,
303 const char *option, char **value);
306 * Iterate over the set of filenames stored in a configuration value.
308 * @param cfg configuration to inspect
309 * @param section section of interest
310 * @param option option of interest
311 * @param cb function to call on each filename
312 * @param cb_cls closure for cb
313 * @return number of filenames iterated over, -1 on error
316 GNUNET_CONFIGURATION_iterate_value_filenames (const struct
317 GNUNET_CONFIGURATION_Handle *cfg,
320 GNUNET_FileNameCallback cb,
324 * Iterate over values of a section in the configuration.
326 * @param cfg configuration to inspect
327 * @param section the section
328 * @param iter function to call on each option
329 * @param iter_cls closure for iter
332 GNUNET_CONFIGURATION_iterate_section_values (const struct
333 GNUNET_CONFIGURATION_Handle *cfg,
335 GNUNET_CONFIGURATION_Iterator iter,
339 * Get a configuration value that should be in a set of
342 * @param cfg configuration to inspect
343 * @param section section of interest
344 * @param option option of interest
345 * @param choices NULL-terminated list of legal values
346 * @param value will be set to an entry in the legal list,
347 * or NULL if option is not specified and no default given
348 * @return GNUNET_OK on success, GNUNET_SYSERR on error
351 GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle
352 *cfg, const char *section,
353 const char *option, const char **choices,
357 * Get a configuration value that should be in a set of
360 * @param cfg configuration to inspect
361 * @param section section of interest
362 * @param option option of interest
363 * @return GNUNET_YES, GNUNET_NO or if option has no valid value, GNUNET_SYSERR
366 GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
367 *cfg, const char *section,
372 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
373 * where either in the "PATHS" section or the environtment
374 * "FOO" is set to "DIRECTORY".
376 * @param cfg configuration to use for path expansion
377 * @param orig string to $-expand (will be freed!)
378 * @return $-expanded string
381 GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle
386 * Set a configuration value that should be a number.
388 * @param cfg configuration to update
389 * @param section section of interest
390 * @param option option of interest
391 * @param number value to set
394 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
395 const char *section, const char *option,
396 unsigned long long number);
400 * Set a configuration value that should be a string.
402 * @param cfg configuration to update
403 * @param section section of interest
404 * @param option option of interest
405 * @param value value to set
408 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
409 const char *section, const char *option,
414 * Remove a filename from a configuration value that
415 * represents a list of filenames
417 * @param cfg configuration to update
418 * @param section section of interest
419 * @param option option of interest
420 * @param value filename to remove
421 * @return GNUNET_OK on success,
422 * GNUNET_SYSERR if the filename is not in the list
425 GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle
426 *cfg, const char *section,
431 * Append a filename to a configuration value that
432 * represents a list of filenames
434 * @param cfg configuration to update
435 * @param section section of interest
436 * @param option option of interest
437 * @param value filename to append
438 * @return GNUNET_OK on success,
439 * GNUNET_SYSERR if the filename already in the list
442 GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
443 *cfg, const char *section,
448 #if 0 /* keep Emacsens' auto-indent happy */