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 (struct GNUNET_CONFIGURATION_Handle *cfg,
129 * Write configuration file.
131 * @param cfg configuration to write
132 * @param filename where to write the configuration
133 * @return GNUNET_OK on success, GNUNET_SYSERR on error
136 GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
137 const char *filename);
140 * Write only configuration entries that have been changed to configuration file
141 * @param cfgDefault default configuration
142 * @param cfgNew new configuration
143 * @param filename where to write the configuration diff between default and new
144 * @return GNUNET_OK on success, GNUNET_SYSERR on error
147 GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
149 const struct GNUNET_CONFIGURATION_Handle
150 *cfgNew, const char *filename);
153 * Test if there are configuration options that were
154 * changed since the last save.
156 * @param cfg configuration to inspect
157 * @return GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error (i.e. last save failed)
160 GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
164 * Function to iterate over options.
167 * @param section name of the section
168 * @param option name of the option
169 * @param value value of the option
171 typedef void (*GNUNET_CONFIGURATION_Iterator) (void *cls, const char *section,
177 * Function to iterate over section.
180 * @param section name of the section
182 typedef void (*GNUNET_CONFIGURATION_Section_Iterator) (void *cls,
183 const char *section);
187 * Iterate over all options in the configuration.
189 * @param cfg configuration to inspect
190 * @param iter function to call on each option
191 * @param iter_cls closure for iter
194 GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
195 GNUNET_CONFIGURATION_Iterator iter,
200 * Iterate over all sections in the configuration.
202 * @param cfg configuration to inspect
203 * @param iter function to call on each section
204 * @param iter_cls closure for iter
207 GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle
209 GNUNET_CONFIGURATION_Section_Iterator
210 iter, void *iter_cls);
214 * Remove the given section and all options in it.
216 * @param cfg configuration to inspect
217 * @param section name of the section to remove
220 GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
221 const char *section);
224 * Get a configuration value that should be a number.
226 * @param cfg configuration to inspect
227 * @param section section of interest
228 * @param option option of interest
229 * @param number where to store the numeric value of the option
230 * @return GNUNET_OK on success, GNUNET_SYSERR on error
233 GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
234 *cfg, const char *section,
236 unsigned long long *number);
240 * Get a configuration value that should be a relative time.
242 * @param cfg configuration to inspect
243 * @param section section of interest
244 * @param option option of interest
245 * @param time set to the time value stored in the configuration
246 * @return GNUNET_OK on success, GNUNET_SYSERR on error
249 GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
250 *cfg, const char *section,
252 struct GNUNET_TIME_Relative *time);
257 * Get a configuration value that should be a size in bytes.
259 * @param cfg configuration to inspect
260 * @param section section of interest
261 * @param option option of interest
262 * @param size set to the size in bytes as stored in the configuration
263 * @return GNUNET_OK on success, GNUNET_SYSERR on error
266 GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle
267 *cfg, const char *section,
269 unsigned long long *size);
273 * Test if we have a value for a particular option
275 * @param cfg configuration to inspect
276 * @param section section of interest
277 * @param option option of interest
278 * @return GNUNET_YES if so, GNUNET_NO if not.
281 GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
282 const char *section, const char *option);
286 * Get a configuration value that should be a string.
288 * @param cfg configuration to inspect
289 * @param section section of interest
290 * @param option option of interest
291 * @param value will be set to a freshly allocated configuration
292 * value, or NULL if option is not specified
293 * @return GNUNET_OK on success, GNUNET_SYSERR on error
296 GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
297 *cfg, const char *section,
298 const char *option, char **value);
302 * Get a configuration value that should be the name of a file
305 * @param cfg configuration to inspect
306 * @param section section of interest
307 * @param option option of interest
308 * @param value will be set to a freshly allocated configuration
309 * value, or NULL if option is not specified
310 * @return GNUNET_OK on success, GNUNET_SYSERR on error
313 GNUNET_CONFIGURATION_get_value_filename (const struct
314 GNUNET_CONFIGURATION_Handle *cfg,
316 const char *option, char **value);
319 * Iterate over the set of filenames stored in a configuration value.
321 * @param cfg configuration to inspect
322 * @param section section of interest
323 * @param option option of interest
324 * @param cb function to call on each filename
325 * @param cb_cls closure for cb
326 * @return number of filenames iterated over, -1 on error
329 GNUNET_CONFIGURATION_iterate_value_filenames (const struct
330 GNUNET_CONFIGURATION_Handle *cfg,
333 GNUNET_FileNameCallback cb,
337 * Iterate over values of a section in the configuration.
339 * @param cfg configuration to inspect
340 * @param section the section
341 * @param iter function to call on each option
342 * @param iter_cls closure for iter
345 GNUNET_CONFIGURATION_iterate_section_values (const struct
346 GNUNET_CONFIGURATION_Handle *cfg,
348 GNUNET_CONFIGURATION_Iterator iter,
352 * Get a configuration value that should be in a set of
355 * @param cfg configuration to inspect
356 * @param section section of interest
357 * @param option option of interest
358 * @param choices NULL-terminated list of legal values
359 * @param value will be set to an entry in the legal list,
360 * or NULL if option is not specified and no default given
361 * @return GNUNET_OK on success, GNUNET_SYSERR on error
364 GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle
365 *cfg, const char *section,
366 const char *option, const char **choices,
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 * @return GNUNET_YES, GNUNET_NO or if option has no valid value, GNUNET_SYSERR
379 GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
380 *cfg, const char *section,
385 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
386 * where either in the "PATHS" section or the environtment
387 * "FOO" is set to "DIRECTORY".
389 * @param cfg configuration to use for path expansion
390 * @param orig string to $-expand (will be freed!)
391 * @return $-expanded string
394 GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle
399 * Set a configuration value that should be a number.
401 * @param cfg configuration to update
402 * @param section section of interest
403 * @param option option of interest
404 * @param number value to set
407 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
408 const char *section, const char *option,
409 unsigned long long number);
413 * Set a configuration value that should be a string.
415 * @param cfg configuration to update
416 * @param section section of interest
417 * @param option option of interest
418 * @param value value to set
421 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
422 const char *section, const char *option,
427 * Remove a filename from a configuration value that
428 * represents a list of filenames
430 * @param cfg configuration to update
431 * @param section section of interest
432 * @param option option of interest
433 * @param value filename to remove
434 * @return GNUNET_OK on success,
435 * GNUNET_SYSERR if the filename is not in the list
438 GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle
439 *cfg, const char *section,
444 * Append a filename to a configuration value that
445 * represents a list of filenames
447 * @param cfg configuration to update
448 * @param section section of interest
449 * @param option option of interest
450 * @param value filename to append
451 * @return GNUNET_OK on success,
452 * GNUNET_SYSERR if the filename already in the list
455 GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
456 *cfg, const char *section,
461 #if 0 /* keep Emacsens' auto-indent happy */