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;
50 * Used for diffing a configuration object against
54 struct GNUNET_CONFIGURATION_Handle* cfgNew;
55 struct GNUNET_CONFIGURATION_Handle* cfgDiff;
56 } GNUNNET_CONFIGURATION_Diff_Handle;
60 * Create a new configuration object.
61 * @return fresh configuration object
63 struct GNUNET_CONFIGURATION_Handle *GNUNET_CONFIGURATION_create (void);
67 * Duplicate an existing configuration object.
69 * @param cfg configuration to duplicate
70 * @return duplicate configuration
72 struct GNUNET_CONFIGURATION_Handle *
73 GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg);
77 * Destroy configuration object.
79 * @param cfg configuration to destroy
81 void GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg);
85 * Load configuration. This function will first parse the
86 * defaults and then parse the specific configuration file
87 * to overwrite the defaults.
89 * @param cfg configuration to update
90 * @param filename name of the configuration file
91 * @return GNUNET_OK on success, GNUNET_SYSERR on error
93 int GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
94 const char *filename);
98 * Parse a configuration file, add all of the options in the
99 * file to the configuration environment.
101 * @param cfg configuration to update
102 * @param filename name of the configuration file
103 * @return GNUNET_OK on success, GNUNET_SYSERR on error
105 int GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
106 const char *filename);
110 * Write configuration file.
112 * @param cfg configuration to write
113 * @param filename where to write the configuration
114 * @return GNUNET_OK on success, GNUNET_SYSERR on error
116 int GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
117 const char *filename);
120 * Write only configuration entries that have been changed to configuration file
121 * @param cfgDefault default configuration
122 * @param cfgNew new configuration
123 * @param filename where to write the configuration diff between default and new
124 * @return GNUNET_OK on success, GNUNET_SYSERR on error
127 GNUNET_CONFIGURATION_write_diffs(
128 struct GNUNET_CONFIGURATION_Handle *cfgDefault,
129 struct GNUNET_CONFIGURATION_Handle *cfgNew,
130 const char* filename);
133 * Test if there are configuration options that were
134 * changed since the last save.
136 * @param cfg configuration to inspect
137 * @return GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error (i.e. last save failed)
139 int GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
143 * Function to iterate over options.
146 * @param section name of the section
147 * @param option name of the option
148 * @param value value of the option
150 typedef void (*GNUNET_CONFIGURATION_Iterator)(void *cls,
157 * Iterate over all options in the configuration.
159 * @param cfg configuration to inspect
160 * @param iter function to call on each option
161 * @param iter_cls closure for iter
163 void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
164 GNUNET_CONFIGURATION_Iterator iter,
169 * Get a configuration value that should be a number.
171 * @param cfg configuration to inspect
172 * @param section section of interest
173 * @param option option of interest
174 * @param number where to store the numeric value of the option
175 * @return GNUNET_OK on success, GNUNET_SYSERR on error
177 int GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
178 *cfg, const char *section,
180 unsigned long long *number);
184 * Get a configuration value that should be a relative time.
186 * @param cfg configuration to inspect
187 * @param section section of interest
188 * @param option option of interest
189 * @param time set to the time value stored in the configuration
190 * @return GNUNET_OK on success, GNUNET_SYSERR on error
192 int GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
193 *cfg, const char *section,
195 struct GNUNET_TIME_Relative *time);
199 * Test if we have a value for a particular option
201 * @param cfg configuration to inspect
202 * @param section section of interest
203 * @param option option of interest
204 * @return GNUNET_YES if so, GNUNET_NO if not.
206 int GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
207 const char *section, const char *option);
211 * Get a configuration value that should be a string.
213 * @param cfg configuration to inspect
214 * @param section section of interest
215 * @param option option of interest
216 * @param value will be set to a freshly allocated configuration
217 * value, or NULL if option is not specified
218 * @return GNUNET_OK on success, GNUNET_SYSERR on error
220 int GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
221 *cfg, const char *section,
222 const char *option, char **value);
226 * Get a configuration value that should be the name of a file
229 * @param cfg configuration to inspect
230 * @param section section of interest
231 * @param option option of interest
232 * @param value will be set to a freshly allocated configuration
233 * value, or NULL if option is not specified
234 * @return GNUNET_OK on success, GNUNET_SYSERR on error
236 int GNUNET_CONFIGURATION_get_value_filename (const struct
237 GNUNET_CONFIGURATION_Handle *cfg,
243 * Iterate over the set of filenames stored in a configuration value.
245 * @param cfg configuration to inspect
246 * @param section section of interest
247 * @param option option of interest
248 * @param cb function to call on each filename
249 * @param cb_cls closure for cb
250 * @return number of filenames iterated over, -1 on error
252 int GNUNET_CONFIGURATION_iterate_value_filenames (const struct
253 GNUNET_CONFIGURATION_Handle
257 GNUNET_FileNameCallback
261 * Get a configuration value that should be in a set of
264 * @param cfg configuration to inspect
265 * @param section section of interest
266 * @param option option of interest
267 * @param choices NULL-terminated list of legal values
268 * @param value will be set to an entry in the legal list,
269 * or NULL if option is not specified and no default given
270 * @return GNUNET_OK on success, GNUNET_SYSERR on error
272 int GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle
273 *cfg, const char *section,
275 const char **choices,
279 * Get a configuration value that should be in a set of
282 * @param cfg configuration to inspect
283 * @param section section of interest
284 * @param option option of interest
285 * @return GNUNET_YES, GNUNET_NO or if option has no valid value, GNUNET_SYSERR
287 int GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
288 *cfg, const char *section,
292 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
293 * where either in the "PATHS" section or the environtment
294 * "FOO" is set to "DIRECTORY".
296 * @param cfg configuration to use for path expansion
297 * @param orig string to $-expand (will be freed!)
298 * @return $-expanded string
300 char *GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle
305 * Set a configuration value that should be a number.
307 * @param cfg configuration to update
308 * @param section section of interest
309 * @param option option of interest
310 * @param number value to set
313 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle
317 unsigned long long number);
321 * Set a configuration value that should be a string.
323 * @param cfg configuration to update
324 * @param section section of interest
325 * @param option option of interest
326 * @param value value to set
329 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle
332 const char *option, const char *value);
335 * Remove a filename from a configuration value that
336 * represents a list of filenames
338 * @param cfg configuration to update
339 * @param section section of interest
340 * @param option option of interest
341 * @param value filename to remove
342 * @return GNUNET_OK on success,
343 * GNUNET_SYSERR if the filename is not in the list
345 int GNUNET_CONFIGURATION_remove_value_filename (struct
346 GNUNET_CONFIGURATION_Handle
353 * Append a filename to a configuration value that
354 * represents a list of filenames
356 * @param cfg configuration to update
357 * @param section section of interest
358 * @param option option of interest
359 * @param value filename to append
360 * @return GNUNET_OK on success,
361 * GNUNET_SYSERR if the filename already in the list
363 int GNUNET_CONFIGURATION_append_value_filename (struct
364 GNUNET_CONFIGURATION_Handle
365 *cfg, const char *section,
370 #if 0 /* keep Emacsens' auto-indent happy */