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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @author Christian Grothoff
27 * @defgroup configuration Configuration library
28 * Configuration management
31 #ifndef GNUNET_CONFIGURATION_LIB_H
32 #define GNUNET_CONFIGURATION_LIB_H
34 #include "gnunet_time_lib.h"
39 #if 0 /* keep Emacsens' auto-indent happy */
45 * A configuration object.
47 struct GNUNET_CONFIGURATION_Handle;
50 * Create a new configuration object.
51 * @return fresh configuration object
53 struct GNUNET_CONFIGURATION_Handle *
54 GNUNET_CONFIGURATION_create (void);
58 * Duplicate an existing configuration object.
60 * @param cfg configuration to duplicate
61 * @return duplicate configuration
63 struct GNUNET_CONFIGURATION_Handle *
64 GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg);
68 * Destroy configuration object.
70 * @param cfg configuration to destroy
73 GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg);
77 * Load configuration. This function will first parse the
78 * defaults and then parse the specific configuration file
79 * to overwrite the defaults.
81 * @param cfg configuration to update
82 * @param filename name of the configuration file, NULL to load defaults
83 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
86 GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
87 const char *filename);
91 * Load default configuration. This function will parse the
92 * defaults from the given @a defaults_d directory.
94 * @param cfg configuration to update
95 * @param defaults_d directory with the defaults
96 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
99 GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg,
100 const char *defaults_d);
104 * Parse a configuration file, add all of the options in the
105 * file to the configuration environment.
107 * @param cfg configuration to update
108 * @param filename name of the configuration file
109 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
112 GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
113 const char *filename);
117 * Serializes the given configuration.
119 * @param cfg configuration to serialize
120 * @param size will be set to the size of the serialized memory block
121 * @return the memory block where the serialized configuration is
122 * present. This memory should be freed by the caller
125 GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
130 * De-serializes configuration
132 * @param cfg configuration to update
133 * @param mem the memory block of serialized configuration
134 * @param size the size of the memory block
135 * @param allow_inline set to the base directory if we recursively load configuration
136 * from inlined configurations; NULL if not and raise warnings
137 * when we come across them
138 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
141 GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
144 const char *basedir);
148 * Write configuration file.
150 * @param cfg configuration to write
151 * @param filename where to write the configuration
152 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
155 GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
156 const char *filename);
160 * Write only configuration entries that have been changed to configuration file
161 * @param cfg_default default configuration
162 * @param cfg_new new configuration
163 * @param filename where to write the configuration diff between default and new
164 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
167 GNUNET_CONFIGURATION_write_diffs (const struct
168 GNUNET_CONFIGURATION_Handle *cfg_default,
170 GNUNET_CONFIGURATION_Handle *cfg_new,
171 const char *filename);
175 * Compute configuration with only entries that have been changed
177 * @param cfg_default original configuration
178 * @param cfg_new new configuration
179 * @return configuration with only the differences, never NULL
181 struct GNUNET_CONFIGURATION_Handle *
182 GNUNET_CONFIGURATION_get_diff (const struct
183 GNUNET_CONFIGURATION_Handle *cfg_default,
185 GNUNET_CONFIGURATION_Handle *cfg_new);
189 * Test if there are configuration options that were
190 * changed since the last save.
192 * @param cfg configuration to inspect
193 * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed)
196 GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
200 * Signature of a function to be run with a configuration.
203 * @param cfg the configuration
204 * @return status code
207 (*GNUNET_CONFIGURATION_Callback)(void *cls,
208 const struct GNUNET_CONFIGURATION_Handle *cfg);
212 * Parse a configuration file @a filename and run the function
213 * @a cb with the resulting configuration object. Then free the
214 * configuration object and return the status value from @a cb.
216 * @param filename configuration to parse, NULL for "default"
217 * @param cb function to run
218 * @param cb_cls closure for @a cb
219 * @return #GNUNET_SYSERR if parsing the configuration failed,
220 * otherwise return value from @a cb.
223 GNUNET_CONFIGURATION_parse_and_run (const char *filename,
224 GNUNET_CONFIGURATION_Callback cb,
229 * Function to iterate over options.
232 * @param section name of the section
233 * @param option name of the option
234 * @param value value of the option
237 (*GNUNET_CONFIGURATION_Iterator) (void *cls,
244 * Function to iterate over section.
247 * @param section name of the section
250 (*GNUNET_CONFIGURATION_Section_Iterator) (void *cls,
251 const char *section);
255 * Iterate over all options in the configuration.
257 * @param cfg configuration to inspect
258 * @param iter function to call on each option
259 * @param iter_cls closure for @a iter
262 GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
263 GNUNET_CONFIGURATION_Iterator iter,
268 * Iterate over all sections in the configuration.
270 * @param cfg configuration to inspect
271 * @param iter function to call on each section
272 * @param iter_cls closure for @a iter
275 GNUNET_CONFIGURATION_iterate_sections (const struct
276 GNUNET_CONFIGURATION_Handle *cfg,
277 GNUNET_CONFIGURATION_Section_Iterator
283 * Remove the given section and all options in it.
285 * @param cfg configuration to inspect
286 * @param section name of the section to remove
289 GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
290 const char *section);
294 * Get a configuration value that should be a number.
296 * @param cfg configuration to inspect
297 * @param section section of interest
298 * @param option option of interest
299 * @param number where to store the numeric value of the option
300 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
303 GNUNET_CONFIGURATION_get_value_number (const struct
304 GNUNET_CONFIGURATION_Handle *cfg,
307 unsigned long long *number);
311 * Get a configuration value that should be a floating point number.
313 * @param cfg configuration to inspect
314 * @param section section of interest
315 * @param option option of interest
316 * @param number where to store the floating value of the option
317 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
320 GNUNET_CONFIGURATION_get_value_float (const struct
321 GNUNET_CONFIGURATION_Handle *cfg,
328 * Get a configuration value that should be a relative time.
330 * @param cfg configuration to inspect
331 * @param section section of interest
332 * @param option option of interest
333 * @param time set to the time value stored in the configuration
334 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
337 GNUNET_CONFIGURATION_get_value_time (const struct
338 GNUNET_CONFIGURATION_Handle *cfg,
341 struct GNUNET_TIME_Relative *time);
345 * Get a configuration value that should be a size in bytes.
347 * @param cfg configuration to inspect
348 * @param section section of interest
349 * @param option option of interest
350 * @param size set to the size in bytes as stored in the configuration
351 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
354 GNUNET_CONFIGURATION_get_value_size (const struct
355 GNUNET_CONFIGURATION_Handle *cfg,
358 unsigned long long *size);
362 * Test if we have a value for a particular option
364 * @param cfg configuration to inspect
365 * @param section section of interest
366 * @param option option of interest
367 * @return #GNUNET_YES if so, #GNUNET_NO if not.
370 GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
376 * Get a configuration value that should be a string.
378 * @param cfg configuration to inspect
379 * @param section section of interest
380 * @param option option of interest
381 * @param value will be set to a freshly allocated configuration
382 * value, or NULL if option is not specified
383 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
386 GNUNET_CONFIGURATION_get_value_string (const struct
387 GNUNET_CONFIGURATION_Handle *cfg,
394 * Get a configuration value that should be the name of a file
397 * @param cfg configuration to inspect
398 * @param section section of interest
399 * @param option option of interest
400 * @param value will be set to a freshly allocated configuration
401 * value, or NULL if option is not specified
402 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
405 GNUNET_CONFIGURATION_get_value_filename (const struct
406 GNUNET_CONFIGURATION_Handle *cfg,
413 * Iterate over the set of filenames stored in a configuration value.
415 * @param cfg configuration to inspect
416 * @param section section of interest
417 * @param option option of interest
418 * @param cb function to call on each filename
419 * @param cb_cls closure for @a cb
420 * @return number of filenames iterated over, -1 on error
423 GNUNET_CONFIGURATION_iterate_value_filenames (const struct
424 GNUNET_CONFIGURATION_Handle *cfg,
427 GNUNET_FileNameCallback cb,
431 * Iterate over values of a section in the configuration.
433 * @param cfg configuration to inspect
434 * @param section the section
435 * @param iter function to call on each option
436 * @param iter_cls closure for @a iter
439 GNUNET_CONFIGURATION_iterate_section_values (const struct
440 GNUNET_CONFIGURATION_Handle *cfg,
442 GNUNET_CONFIGURATION_Iterator iter,
446 * Get a configuration value that should be in a set of
449 * @param cfg configuration to inspect
450 * @param section section of interest
451 * @param option option of interest
452 * @param choices NULL-terminated list of legal values
453 * @param value will be set to an entry in the legal list,
454 * or NULL if option is not specified and no default given
455 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
458 GNUNET_CONFIGURATION_get_value_choice (const struct
459 GNUNET_CONFIGURATION_Handle *cfg,
462 const char *const *choices,
466 * Get a configuration value that should be in a set of
469 * @param cfg configuration to inspect
470 * @param section section of interest
471 * @param option option of interest
472 * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR
475 GNUNET_CONFIGURATION_get_value_yesno (const struct
476 GNUNET_CONFIGURATION_Handle *cfg,
482 * Get Crockford32-encoded fixed-size binary data from a configuration.
484 * @param cfg configuration to access
485 * @param section section to access
486 * @param option option to access
487 * @param buf where to store the decoded binary result
488 * @param buf_size exact number of bytes to store in @a buf
489 * @return #GNUNET_OK on success
490 * #GNUNET_NO is the value does not exist
491 * #GNUNET_SYSERR on decoding error
494 GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg,
502 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
503 * where either in the "PATHS" section or the environtment "FOO" is
504 * set to "DIRECTORY". We also support default expansion,
505 * i.e. ${VARIABLE:-default} will expand to $VARIABLE if VARIABLE is
506 * set in PATHS or the environment, and otherwise to "default". Note
507 * that "default" itself can also be a $-expression, thus
508 * "${VAR1:-{$VAR2}}" will expand to VAR1 and if that is not defined
511 * @param cfg configuration to use for path expansion
512 * @param orig string to $-expand (will be freed!) Note that multiple
513 * $-expressions can be present in this string. They will all be
515 * @return $-expanded string
518 GNUNET_CONFIGURATION_expand_dollar (const struct
519 GNUNET_CONFIGURATION_Handle *cfg,
524 * Set a configuration value that should be a number.
526 * @param cfg configuration to update
527 * @param section section of interest
528 * @param option option of interest
529 * @param number value to set
532 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
535 unsigned long long number);
539 * Set a configuration value that should be a string.
541 * @param cfg configuration to update
542 * @param section section of interest
543 * @param option option of interest
544 * @param value value to set
547 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
554 * Remove a filename from 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 remove
561 * @return #GNUNET_OK on success,
562 * #GNUNET_SYSERR if the filename is not in the list
565 GNUNET_CONFIGURATION_remove_value_filename (struct
566 GNUNET_CONFIGURATION_Handle *cfg,
573 * Append a filename to a configuration value that
574 * represents a list of filenames
576 * @param cfg configuration to update
577 * @param section section of interest
578 * @param option option of interest
579 * @param value filename to append
580 * @return #GNUNET_OK on success,
581 * #GNUNET_SYSERR if the filename already in the list
584 GNUNET_CONFIGURATION_append_value_filename (struct
585 GNUNET_CONFIGURATION_Handle *cfg,
590 #if 0 /* keep Emacsens' auto-indent happy */
599 /** @} */ /* end of group configuration */