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 * Parse a configuration file, add all of the options in the
91 * file to the configuration environment.
93 * @param cfg configuration to update
94 * @param filename name of the configuration file
95 * @return GNUNET_OK on success, GNUNET_SYSERR on error
98 GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
99 const char *filename);
103 * Write configuration file.
105 * @param cfg configuration to write
106 * @param filename where to write the configuration
107 * @return GNUNET_OK on success, GNUNET_SYSERR on error
110 GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
111 const char *filename);
114 * Write only configuration entries that have been changed to configuration file
115 * @param cfgDefault default configuration
116 * @param cfgNew new configuration
117 * @param filename where to write the configuration diff between default and new
118 * @return GNUNET_OK on success, GNUNET_SYSERR on error
121 GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
123 const struct GNUNET_CONFIGURATION_Handle
124 *cfgNew, const char *filename);
127 * Test if there are configuration options that were
128 * changed since the last save.
130 * @param cfg configuration to inspect
131 * @return GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error (i.e. last save failed)
134 GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
138 * Function to iterate over options.
141 * @param section name of the section
142 * @param option name of the option
143 * @param value value of the option
145 typedef void (*GNUNET_CONFIGURATION_Iterator) (void *cls, const char *section,
151 * Function to iterate over section.
154 * @param section name of the section
156 typedef void (*GNUNET_CONFIGURATION_Section_Iterator) (void *cls,
157 const char *section);
161 * Iterate over all options in the configuration.
163 * @param cfg configuration to inspect
164 * @param iter function to call on each option
165 * @param iter_cls closure for iter
168 GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
169 GNUNET_CONFIGURATION_Iterator iter,
174 * Iterate over all sections in the configuration.
176 * @param cfg configuration to inspect
177 * @param iter function to call on each section
178 * @param iter_cls closure for iter
181 GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle
183 GNUNET_CONFIGURATION_Section_Iterator
184 iter, void *iter_cls);
188 * Remove the given section and all options in it.
190 * @param cfg configuration to inspect
191 * @param section name of the section to remove
194 GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
195 const char *section);
198 * Get a configuration value that should be a number.
200 * @param cfg configuration to inspect
201 * @param section section of interest
202 * @param option option of interest
203 * @param number where to store the numeric value of the option
204 * @return GNUNET_OK on success, GNUNET_SYSERR on error
207 GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
208 *cfg, const char *section,
210 unsigned long long *number);
214 * Get a configuration value that should be a relative time.
216 * @param cfg configuration to inspect
217 * @param section section of interest
218 * @param option option of interest
219 * @param time set to the time value stored in the configuration
220 * @return GNUNET_OK on success, GNUNET_SYSERR on error
223 GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
224 *cfg, const char *section,
226 struct GNUNET_TIME_Relative *time);
230 * Test if we have a value for a particular option
232 * @param cfg configuration to inspect
233 * @param section section of interest
234 * @param option option of interest
235 * @return GNUNET_YES if so, GNUNET_NO if not.
238 GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
239 const char *section, const char *option);
243 * Get a configuration value that should be a string.
245 * @param cfg configuration to inspect
246 * @param section section of interest
247 * @param option option of interest
248 * @param value will be set to a freshly allocated configuration
249 * value, or NULL if option is not specified
250 * @return GNUNET_OK on success, GNUNET_SYSERR on error
253 GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
254 *cfg, const char *section,
255 const char *option, char **value);
259 * Get a configuration value that should be the name of a file
262 * @param cfg configuration to inspect
263 * @param section section of interest
264 * @param option option of interest
265 * @param value will be set to a freshly allocated configuration
266 * value, or NULL if option is not specified
267 * @return GNUNET_OK on success, GNUNET_SYSERR on error
270 GNUNET_CONFIGURATION_get_value_filename (const struct
271 GNUNET_CONFIGURATION_Handle *cfg,
273 const char *option, char **value);
276 * Iterate over the set of filenames stored in a configuration value.
278 * @param cfg configuration to inspect
279 * @param section section of interest
280 * @param option option of interest
281 * @param cb function to call on each filename
282 * @param cb_cls closure for cb
283 * @return number of filenames iterated over, -1 on error
286 GNUNET_CONFIGURATION_iterate_value_filenames (const struct
287 GNUNET_CONFIGURATION_Handle *cfg,
290 GNUNET_FileNameCallback cb,
294 * Iterate over values of a section in the configuration.
296 * @param cfg configuration to inspect
297 * @param section the section
298 * @param iter function to call on each option
299 * @param iter_cls closure for iter
302 GNUNET_CONFIGURATION_iterate_section_values (const struct
303 GNUNET_CONFIGURATION_Handle *cfg,
305 GNUNET_CONFIGURATION_Iterator iter,
309 * Get a configuration value that should be in a set of
312 * @param cfg configuration to inspect
313 * @param section section of interest
314 * @param option option of interest
315 * @param choices NULL-terminated list of legal values
316 * @param value will be set to an entry in the legal list,
317 * or NULL if option is not specified and no default given
318 * @return GNUNET_OK on success, GNUNET_SYSERR on error
321 GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle
322 *cfg, const char *section,
323 const char *option, const char **choices,
327 * Get a configuration value that should be in a set of
330 * @param cfg configuration to inspect
331 * @param section section of interest
332 * @param option option of interest
333 * @return GNUNET_YES, GNUNET_NO or if option has no valid value, GNUNET_SYSERR
336 GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
337 *cfg, const char *section,
341 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
342 * where either in the "PATHS" section or the environtment
343 * "FOO" is set to "DIRECTORY".
345 * @param cfg configuration to use for path expansion
346 * @param orig string to $-expand (will be freed!)
347 * @return $-expanded string
350 GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle
355 * Set a configuration value that should be a number.
357 * @param cfg configuration to update
358 * @param section section of interest
359 * @param option option of interest
360 * @param number value to set
363 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
364 const char *section, const char *option,
365 unsigned long long number);
369 * Set a configuration value that should be a string.
371 * @param cfg configuration to update
372 * @param section section of interest
373 * @param option option of interest
374 * @param value value to set
377 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
378 const char *section, const char *option,
382 * Remove a filename from a configuration value that
383 * represents a list of filenames
385 * @param cfg configuration to update
386 * @param section section of interest
387 * @param option option of interest
388 * @param value filename to remove
389 * @return GNUNET_OK on success,
390 * GNUNET_SYSERR if the filename is not in the list
393 GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle
394 *cfg, const char *section,
399 * Append a filename to a configuration value that
400 * represents a list of filenames
402 * @param cfg configuration to update
403 * @param section section of interest
404 * @param option option of interest
405 * @param value filename to append
406 * @return GNUNET_OK on success,
407 * GNUNET_SYSERR if the filename already in the list
410 GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
411 *cfg, const char *section,
416 #if 0 /* keep Emacsens' auto-indent happy */