2 This file is part of GNUnet.
3 Copyright (C) 2006, 2008, 2009, 2018 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @author Christian Grothoff
25 * @defgroup configuration Configuration library
26 * Configuration management
29 #ifndef GNUNET_CONFIGURATION_LIB_H
30 #define GNUNET_CONFIGURATION_LIB_H
32 #include "gnunet_time_lib.h"
37 #if 0 /* keep Emacsens' auto-indent happy */
43 * A configuration object.
45 struct GNUNET_CONFIGURATION_Handle;
48 * Create a new configuration object.
49 * @return fresh configuration object
51 struct GNUNET_CONFIGURATION_Handle *
52 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 *
62 GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg);
66 * Destroy configuration object.
68 * @param cfg configuration to destroy
71 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
84 GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
85 const char *filename);
89 * Load default configuration. This function will parse the
90 * defaults from the given @a defaults_d directory.
92 * @param cfg configuration to update
93 * @param defaults_d directory with the defaults
94 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
97 GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg,
98 const char *defaults_d);
102 * Parse a configuration file, add all of the options in the
103 * file to the configuration environment.
105 * @param cfg configuration to update
106 * @param filename name of the configuration file
107 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
110 GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
111 const char *filename);
115 * Serializes the given configuration.
117 * @param cfg configuration to serialize
118 * @param size will be set to the size of the serialized memory block
119 * @return the memory block where the serialized configuration is
120 * present. This memory should be freed by the caller
123 GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
128 * De-serializes configuration
130 * @param cfg configuration to update
131 * @param mem the memory block of serialized configuration
132 * @param size the size of the memory block
133 * @param allow_inline set to the base directory if we recursively load configuration
134 * from inlined configurations; NULL if not and raise warnings
135 * when we come across them
136 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
139 GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
142 const char *basedir);
146 * Write configuration file.
148 * @param cfg configuration to write
149 * @param filename where to write the configuration
150 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
153 GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
154 const char *filename);
158 * Write only configuration entries that have been changed to configuration file
159 * @param cfg_default default configuration
160 * @param cfg_new new configuration
161 * @param filename where to write the configuration diff between default and new
162 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
165 GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle *cfg_default,
166 const struct GNUNET_CONFIGURATION_Handle *cfg_new,
167 const char *filename);
171 * Compute configuration with only entries that have been changed
173 * @param cfg_default original configuration
174 * @param cfg_new new configuration
175 * @return configuration with only the differences, never NULL
177 struct GNUNET_CONFIGURATION_Handle *
178 GNUNET_CONFIGURATION_get_diff (const struct GNUNET_CONFIGURATION_Handle *cfg_default,
179 const struct GNUNET_CONFIGURATION_Handle *cfg_new);
183 * Test if there are configuration options that were
184 * changed since the last save.
186 * @param cfg configuration to inspect
187 * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed)
190 GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
194 * Signature of a function to be run with a configuration.
197 * @param cfg the configuration
198 * @return status code
201 (*GNUNET_CONFIGURATION_Callback)(void *cls,
202 const struct GNUNET_CONFIGURATION_Handle *cfg);
206 * Parse a configuration file @a filename and run the function
207 * @a cb with the resulting configuration object. Then free the
208 * configuration object and return the status value from @a cb.
210 * @param filename configuration to parse, NULL for "default"
211 * @param cb function to run
212 * @param cb_cls closure for @a cb
213 * @return #GNUNET_SYSERR if parsing the configuration failed,
214 * otherwise return value from @a cb.
217 GNUNET_CONFIGURATION_parse_and_run (const char *filename,
218 GNUNET_CONFIGURATION_Callback cb,
223 * Function to iterate over options.
226 * @param section name of the section
227 * @param option name of the option
228 * @param value value of the option
231 (*GNUNET_CONFIGURATION_Iterator) (void *cls,
238 * Function to iterate over section.
241 * @param section name of the section
244 (*GNUNET_CONFIGURATION_Section_Iterator) (void *cls,
245 const char *section);
249 * Iterate over all options in the configuration.
251 * @param cfg configuration to inspect
252 * @param iter function to call on each option
253 * @param iter_cls closure for @a iter
256 GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
257 GNUNET_CONFIGURATION_Iterator iter,
262 * Iterate over all sections in the configuration.
264 * @param cfg configuration to inspect
265 * @param iter function to call on each section
266 * @param iter_cls closure for @a iter
269 GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle *cfg,
270 GNUNET_CONFIGURATION_Section_Iterator iter,
275 * Remove the given section and all options in it.
277 * @param cfg configuration to inspect
278 * @param section name of the section to remove
281 GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
282 const char *section);
286 * Get a configuration value that should be a number.
288 * @param cfg configuration to inspect
289 * @param section section of interest
290 * @param option option of interest
291 * @param number where to store the numeric value of the option
292 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
295 GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle *cfg,
298 unsigned long long *number);
302 * Get a configuration value that should be a floating point number.
304 * @param cfg configuration to inspect
305 * @param section section of interest
306 * @param option option of interest
307 * @param number where to store the floating value of the option
308 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
311 GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle *cfg,
318 * Get a configuration value that should be a relative time.
320 * @param cfg configuration to inspect
321 * @param section section of interest
322 * @param option option of interest
323 * @param time set to the time value stored in the configuration
324 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
327 GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle *cfg,
330 struct GNUNET_TIME_Relative *time);
335 * Get a configuration value that should be a size in bytes.
337 * @param cfg configuration to inspect
338 * @param section section of interest
339 * @param option option of interest
340 * @param size set to the size in bytes as stored in the configuration
341 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
344 GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle *cfg,
347 unsigned long long *size);
351 * Test if we have a value for a particular option
353 * @param cfg configuration to inspect
354 * @param section section of interest
355 * @param option option of interest
356 * @return #GNUNET_YES if so, #GNUNET_NO if not.
359 GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
365 * Get a configuration value that should be a string.
367 * @param cfg configuration to inspect
368 * @param section section of interest
369 * @param option option of interest
370 * @param value will be set to a freshly allocated configuration
371 * value, or NULL if option is not specified
372 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
375 GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
382 * Get a configuration value that should be the name of a file
385 * @param cfg configuration to inspect
386 * @param section section of interest
387 * @param option option of interest
388 * @param value will be set to a freshly allocated configuration
389 * value, or NULL if option is not specified
390 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
393 GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
400 * Iterate over the set of filenames stored in a configuration value.
402 * @param cfg configuration to inspect
403 * @param section section of interest
404 * @param option option of interest
405 * @param cb function to call on each filename
406 * @param cb_cls closure for @a cb
407 * @return number of filenames iterated over, -1 on error
410 GNUNET_CONFIGURATION_iterate_value_filenames (const struct GNUNET_CONFIGURATION_Handle *cfg,
413 GNUNET_FileNameCallback cb,
417 * Iterate over values of a section in the configuration.
419 * @param cfg configuration to inspect
420 * @param section the section
421 * @param iter function to call on each option
422 * @param iter_cls closure for @a iter
425 GNUNET_CONFIGURATION_iterate_section_values (const struct GNUNET_CONFIGURATION_Handle *cfg,
427 GNUNET_CONFIGURATION_Iterator iter,
431 * Get a configuration value that should be in a set of
434 * @param cfg configuration to inspect
435 * @param section section of interest
436 * @param option option of interest
437 * @param choices NULL-terminated list of legal values
438 * @param value will be set to an entry in the legal list,
439 * or NULL if option is not specified and no default given
440 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
443 GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle *cfg,
446 const char *const *choices,
450 * Get a configuration value that should be in a set of
453 * @param cfg configuration to inspect
454 * @param section section of interest
455 * @param option option of interest
456 * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR
459 GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle *cfg,
465 * Get Crockford32-encoded fixed-size binary data from a configuration.
467 * @param cfg configuration to access
468 * @param section section to access
469 * @param option option to access
470 * @param buf where to store the decoded binary result
471 * @param buf_size exact number of bytes to store in @a buf
472 * @return #GNUNET_OK on success
473 * #GNUNET_NO is the value does not exist
474 * #GNUNET_SYSERR on decoding error
477 GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg,
485 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
486 * where either in the "PATHS" section or the environtment "FOO" is
487 * set to "DIRECTORY". We also support default expansion,
488 * i.e. ${VARIABLE:-default} will expand to $VARIABLE if VARIABLE is
489 * set in PATHS or the environment, and otherwise to "default". Note
490 * that "default" itself can also be a $-expression, thus
491 * "${VAR1:-{$VAR2}}" will expand to VAR1 and if that is not defined
494 * @param cfg configuration to use for path expansion
495 * @param orig string to $-expand (will be freed!) Note that multiple
496 * $-expressions can be present in this string. They will all be
498 * @return $-expanded string
501 GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
506 * Set a configuration value that should be a number.
508 * @param cfg configuration to update
509 * @param section section of interest
510 * @param option option of interest
511 * @param number value to set
514 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
517 unsigned long long number);
521 * Set a configuration value that should be a string.
523 * @param cfg configuration to update
524 * @param section section of interest
525 * @param option option of interest
526 * @param value value to set
529 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
536 * Remove a filename from a configuration value that
537 * represents a list of filenames
539 * @param cfg configuration to update
540 * @param section section of interest
541 * @param option option of interest
542 * @param value filename to remove
543 * @return #GNUNET_OK on success,
544 * #GNUNET_SYSERR if the filename is not in the list
547 GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg,
554 * Append a filename to a configuration value that
555 * represents a list of filenames
557 * @param cfg configuration to update
558 * @param section section of interest
559 * @param option option of interest
560 * @param value filename to append
561 * @return #GNUNET_OK on success,
562 * #GNUNET_SYSERR if the filename already in the list
565 GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg,
570 #if 0 /* keep Emacsens' auto-indent happy */
579 /** @} */ /* end of group configuration */