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 *GNUNET_CONFIGURATION_create (void);
56 * Duplicate an existing configuration object.
58 * @param cfg configuration to duplicate
59 * @return duplicate configuration
61 struct GNUNET_CONFIGURATION_Handle *GNUNET_CONFIGURATION_dup (const struct
62 GNUNET_CONFIGURATION_Handle
67 * Destroy configuration object.
69 * @param cfg configuration to destroy
71 void GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg);
75 * Load configuration. This function will first parse the
76 * defaults and then parse the specific configuration file
77 * to overwrite the defaults.
79 * @param cfg configuration to update
80 * @param filename name of the configuration file, NULL to load defaults
81 * @return GNUNET_OK on success, GNUNET_SYSERR on error
83 int GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
84 const char *filename);
88 * Parse a configuration file, add all of the options in the
89 * file to the configuration environment.
91 * @param cfg configuration to update
92 * @param filename name of the configuration file
93 * @return GNUNET_OK on success, GNUNET_SYSERR on error
95 int GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
96 const char *filename);
100 * Write configuration file.
102 * @param cfg configuration to write
103 * @param filename where to write the configuration
104 * @return GNUNET_OK on success, GNUNET_SYSERR on error
106 int GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
107 const char *filename);
110 * Write only configuration entries that have been changed to configuration file
111 * @param cfgDefault default configuration
112 * @param cfgNew new configuration
113 * @param filename where to write the configuration diff between default and new
114 * @return GNUNET_OK on success, GNUNET_SYSERR on error
116 int GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
118 const struct GNUNET_CONFIGURATION_Handle
119 *cfgNew, const char *filename);
122 * Test if there are configuration options that were
123 * changed since the last save.
125 * @param cfg configuration to inspect
126 * @return GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error (i.e. last save failed)
128 int GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle
133 * Function to iterate over options.
136 * @param section name of the section
137 * @param option name of the option
138 * @param value value of the option
140 typedef void (*GNUNET_CONFIGURATION_Iterator) (void *cls, const char *section,
146 * Function to iterate over section.
149 * @param section name of the section
151 typedef void (*GNUNET_CONFIGURATION_Section_Iterator) (void *cls,
152 const char *section);
156 * Iterate over all options in the configuration.
158 * @param cfg configuration to inspect
159 * @param iter function to call on each option
160 * @param iter_cls closure for iter
162 void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle
163 *cfg, GNUNET_CONFIGURATION_Iterator iter,
168 * Iterate over all sections in the configuration.
170 * @param cfg configuration to inspect
171 * @param iter function to call on each section
172 * @param iter_cls closure for iter
174 void GNUNET_CONFIGURATION_iterate_sections (const struct
175 GNUNET_CONFIGURATION_Handle *cfg,
176 GNUNET_CONFIGURATION_Section_Iterator
177 iter, void *iter_cls);
181 * Remove the given section and all options in it.
183 * @param cfg configuration to inspect
184 * @param section name of the section to remove
186 void GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle
187 *cfg, const char *section);
190 * Get a configuration value that should be a number.
192 * @param cfg configuration to inspect
193 * @param section section of interest
194 * @param option option of interest
195 * @param number where to store the numeric value of the option
196 * @return GNUNET_OK on success, GNUNET_SYSERR on error
198 int GNUNET_CONFIGURATION_get_value_number (const struct
199 GNUNET_CONFIGURATION_Handle *cfg,
202 unsigned long long *number);
206 * Get a configuration value that should be a relative time.
208 * @param cfg configuration to inspect
209 * @param section section of interest
210 * @param option option of interest
211 * @param time set to the time value stored in the configuration
212 * @return GNUNET_OK on success, GNUNET_SYSERR on error
214 int GNUNET_CONFIGURATION_get_value_time (const struct
215 GNUNET_CONFIGURATION_Handle *cfg,
218 struct GNUNET_TIME_Relative *time);
222 * Test if we have a value for a particular option
224 * @param cfg configuration to inspect
225 * @param section section of interest
226 * @param option option of interest
227 * @return GNUNET_YES if so, GNUNET_NO if not.
229 int GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle
230 *cfg, const char *section,
235 * Get a configuration value that should be a string.
237 * @param cfg configuration to inspect
238 * @param section section of interest
239 * @param option option of interest
240 * @param value will be set to a freshly allocated configuration
241 * value, or NULL if option is not specified
242 * @return GNUNET_OK on success, GNUNET_SYSERR on error
244 int GNUNET_CONFIGURATION_get_value_string (const struct
245 GNUNET_CONFIGURATION_Handle *cfg,
247 const char *option, char **value);
251 * Get a configuration value that should be the name of a file
254 * @param cfg configuration to inspect
255 * @param section section of interest
256 * @param option option of interest
257 * @param value will be set to a freshly allocated configuration
258 * value, or NULL if option is not specified
259 * @return GNUNET_OK on success, GNUNET_SYSERR on error
261 int GNUNET_CONFIGURATION_get_value_filename (const struct
262 GNUNET_CONFIGURATION_Handle *cfg,
264 const char *option, char **value);
267 * Iterate over the set of filenames stored in a configuration value.
269 * @param cfg configuration to inspect
270 * @param section section of interest
271 * @param option option of interest
272 * @param cb function to call on each filename
273 * @param cb_cls closure for cb
274 * @return number of filenames iterated over, -1 on error
276 int GNUNET_CONFIGURATION_iterate_value_filenames (const struct
277 GNUNET_CONFIGURATION_Handle
278 *cfg, const char *section,
280 GNUNET_FileNameCallback cb,
284 * Iterate over values of a section in the configuration.
286 * @param cfg configuration to inspect
287 * @param section the section
288 * @param iter function to call on each option
289 * @param iter_cls closure for iter
291 void GNUNET_CONFIGURATION_iterate_section_values (const struct
292 GNUNET_CONFIGURATION_Handle
293 *cfg, const char *section,
294 GNUNET_CONFIGURATION_Iterator
295 iter, void *iter_cls);
298 * Get a configuration value that should be in a set of
301 * @param cfg configuration to inspect
302 * @param section section of interest
303 * @param option option of interest
304 * @param choices NULL-terminated list of legal values
305 * @param value will be set to an entry in the legal list,
306 * or NULL if option is not specified and no default given
307 * @return GNUNET_OK on success, GNUNET_SYSERR on error
309 int GNUNET_CONFIGURATION_get_value_choice (const struct
310 GNUNET_CONFIGURATION_Handle *cfg,
313 const char **choices,
317 * Get a configuration value that should be in a set of
320 * @param cfg configuration to inspect
321 * @param section section of interest
322 * @param option option of interest
323 * @return GNUNET_YES, GNUNET_NO or if option has no valid value, GNUNET_SYSERR
325 int GNUNET_CONFIGURATION_get_value_yesno (const struct
326 GNUNET_CONFIGURATION_Handle *cfg,
331 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
332 * where either in the "PATHS" section or the environtment
333 * "FOO" is set to "DIRECTORY".
335 * @param cfg configuration to use for path expansion
336 * @param orig string to $-expand (will be freed!)
337 * @return $-expanded string
339 char *GNUNET_CONFIGURATION_expand_dollar (const struct
340 GNUNET_CONFIGURATION_Handle *cfg,
345 * Set a configuration value that should be a number.
347 * @param cfg configuration to update
348 * @param section section of interest
349 * @param option option of interest
350 * @param number value to set
352 void GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle
353 *cfg, const char *section,
355 unsigned long long number);
359 * Set a configuration value that should be a string.
361 * @param cfg configuration to update
362 * @param section section of interest
363 * @param option option of interest
364 * @param value value to set
366 void GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle
367 *cfg, const char *section,
372 * Remove a filename from a configuration value that
373 * represents a list of filenames
375 * @param cfg configuration to update
376 * @param section section of interest
377 * @param option option of interest
378 * @param value filename to remove
379 * @return GNUNET_OK on success,
380 * GNUNET_SYSERR if the filename is not in the list
382 int GNUNET_CONFIGURATION_remove_value_filename (struct
383 GNUNET_CONFIGURATION_Handle
384 *cfg, const char *section,
389 * Append a filename to a configuration value that
390 * represents a list of filenames
392 * @param cfg configuration to update
393 * @param section section of interest
394 * @param option option of interest
395 * @param value filename to append
396 * @return GNUNET_OK on success,
397 * GNUNET_SYSERR if the filename already in the list
399 int GNUNET_CONFIGURATION_append_value_filename (struct
400 GNUNET_CONFIGURATION_Handle
401 *cfg, const char *section,
406 #if 0 /* keep Emacsens' auto-indent happy */