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);
346 * Get a configuration value that should be a size in bytes.
348 * @param cfg configuration to inspect
349 * @param section section of interest
350 * @param option option of interest
351 * @param size set to the size in bytes as stored in the configuration
352 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
355 GNUNET_CONFIGURATION_get_value_size (const struct
356 GNUNET_CONFIGURATION_Handle *cfg,
359 unsigned long long *size);
363 * Test if we have a value for a particular option
365 * @param cfg configuration to inspect
366 * @param section section of interest
367 * @param option option of interest
368 * @return #GNUNET_YES if so, #GNUNET_NO if not.
371 GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
377 * Get a configuration value that should be a string.
379 * @param cfg configuration to inspect
380 * @param section section of interest
381 * @param option option of interest
382 * @param value will be set to a freshly allocated configuration
383 * value, or NULL if option is not specified
384 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
387 GNUNET_CONFIGURATION_get_value_string (const struct
388 GNUNET_CONFIGURATION_Handle *cfg,
395 * Get a configuration value that should be the name of a file
398 * @param cfg configuration to inspect
399 * @param section section of interest
400 * @param option option of interest
401 * @param value will be set to a freshly allocated configuration
402 * value, or NULL if option is not specified
403 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
406 GNUNET_CONFIGURATION_get_value_filename (const struct
407 GNUNET_CONFIGURATION_Handle *cfg,
414 * Iterate over the set of filenames stored in a configuration value.
416 * @param cfg configuration to inspect
417 * @param section section of interest
418 * @param option option of interest
419 * @param cb function to call on each filename
420 * @param cb_cls closure for @a cb
421 * @return number of filenames iterated over, -1 on error
424 GNUNET_CONFIGURATION_iterate_value_filenames (const struct
425 GNUNET_CONFIGURATION_Handle *cfg,
428 GNUNET_FileNameCallback cb,
432 * Iterate over values of a section in the configuration.
434 * @param cfg configuration to inspect
435 * @param section the section
436 * @param iter function to call on each option
437 * @param iter_cls closure for @a iter
440 GNUNET_CONFIGURATION_iterate_section_values (const struct
441 GNUNET_CONFIGURATION_Handle *cfg,
443 GNUNET_CONFIGURATION_Iterator iter,
447 * Get a configuration value that should be in a set of
450 * @param cfg configuration to inspect
451 * @param section section of interest
452 * @param option option of interest
453 * @param choices NULL-terminated list of legal values
454 * @param value will be set to an entry in the legal list,
455 * or NULL if option is not specified and no default given
456 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
459 GNUNET_CONFIGURATION_get_value_choice (const struct
460 GNUNET_CONFIGURATION_Handle *cfg,
463 const char *const *choices,
467 * Get a configuration value that should be in a set of
470 * @param cfg configuration to inspect
471 * @param section section of interest
472 * @param option option of interest
473 * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR
476 GNUNET_CONFIGURATION_get_value_yesno (const struct
477 GNUNET_CONFIGURATION_Handle *cfg,
483 * Get Crockford32-encoded fixed-size binary data from a configuration.
485 * @param cfg configuration to access
486 * @param section section to access
487 * @param option option to access
488 * @param buf where to store the decoded binary result
489 * @param buf_size exact number of bytes to store in @a buf
490 * @return #GNUNET_OK on success
491 * #GNUNET_NO is the value does not exist
492 * #GNUNET_SYSERR on decoding error
495 GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg,
503 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
504 * where either in the "PATHS" section or the environtment "FOO" is
505 * set to "DIRECTORY". We also support default expansion,
506 * i.e. ${VARIABLE:-default} will expand to $VARIABLE if VARIABLE is
507 * set in PATHS or the environment, and otherwise to "default". Note
508 * that "default" itself can also be a $-expression, thus
509 * "${VAR1:-{$VAR2}}" will expand to VAR1 and if that is not defined
512 * @param cfg configuration to use for path expansion
513 * @param orig string to $-expand (will be freed!) Note that multiple
514 * $-expressions can be present in this string. They will all be
516 * @return $-expanded string
519 GNUNET_CONFIGURATION_expand_dollar (const struct
520 GNUNET_CONFIGURATION_Handle *cfg,
525 * Set a configuration value that should be a number.
527 * @param cfg configuration to update
528 * @param section section of interest
529 * @param option option of interest
530 * @param number value to set
533 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
536 unsigned long long number);
540 * Set a configuration value that should be a string.
542 * @param cfg configuration to update
543 * @param section section of interest
544 * @param option option of interest
545 * @param value value to set
548 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
555 * Remove a filename from a configuration value that
556 * represents a list of filenames
558 * @param cfg configuration to update
559 * @param section section of interest
560 * @param option option of interest
561 * @param value filename to remove
562 * @return #GNUNET_OK on success,
563 * #GNUNET_SYSERR if the filename is not in the list
566 GNUNET_CONFIGURATION_remove_value_filename (struct
567 GNUNET_CONFIGURATION_Handle *cfg,
574 * Append a filename to a configuration value that
575 * represents a list of filenames
577 * @param cfg configuration to update
578 * @param section section of interest
579 * @param option option of interest
580 * @param value filename to append
581 * @return #GNUNET_OK on success,
582 * #GNUNET_SYSERR if the filename already in the list
585 GNUNET_CONFIGURATION_append_value_filename (struct
586 GNUNET_CONFIGURATION_Handle *cfg,
591 #if 0 /* keep Emacsens' auto-indent happy */
600 /** @} */ /* end of group configuration */