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 GNUNET_CONFIGURATION_Handle *cfg_default,
168 const struct GNUNET_CONFIGURATION_Handle *cfg_new,
169 const char *filename);
173 * Compute configuration with only entries that have been changed
175 * @param cfg_default original configuration
176 * @param cfg_new new configuration
177 * @return configuration with only the differences, never NULL
179 struct GNUNET_CONFIGURATION_Handle *
180 GNUNET_CONFIGURATION_get_diff (const struct GNUNET_CONFIGURATION_Handle *cfg_default,
181 const struct GNUNET_CONFIGURATION_Handle *cfg_new);
185 * Test if there are configuration options that were
186 * changed since the last save.
188 * @param cfg configuration to inspect
189 * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed)
192 GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
196 * Signature of a function to be run with a configuration.
199 * @param cfg the configuration
200 * @return status code
203 (*GNUNET_CONFIGURATION_Callback)(void *cls,
204 const struct GNUNET_CONFIGURATION_Handle *cfg);
208 * Parse a configuration file @a filename and run the function
209 * @a cb with the resulting configuration object. Then free the
210 * configuration object and return the status value from @a cb.
212 * @param filename configuration to parse, NULL for "default"
213 * @param cb function to run
214 * @param cb_cls closure for @a cb
215 * @return #GNUNET_SYSERR if parsing the configuration failed,
216 * otherwise return value from @a cb.
219 GNUNET_CONFIGURATION_parse_and_run (const char *filename,
220 GNUNET_CONFIGURATION_Callback cb,
225 * Function to iterate over options.
228 * @param section name of the section
229 * @param option name of the option
230 * @param value value of the option
233 (*GNUNET_CONFIGURATION_Iterator) (void *cls,
240 * Function to iterate over section.
243 * @param section name of the section
246 (*GNUNET_CONFIGURATION_Section_Iterator) (void *cls,
247 const char *section);
251 * Iterate over all options in the configuration.
253 * @param cfg configuration to inspect
254 * @param iter function to call on each option
255 * @param iter_cls closure for @a iter
258 GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
259 GNUNET_CONFIGURATION_Iterator iter,
264 * Iterate over all sections in the configuration.
266 * @param cfg configuration to inspect
267 * @param iter function to call on each section
268 * @param iter_cls closure for @a iter
271 GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle *cfg,
272 GNUNET_CONFIGURATION_Section_Iterator iter,
277 * Remove the given section and all options in it.
279 * @param cfg configuration to inspect
280 * @param section name of the section to remove
283 GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
284 const char *section);
288 * Get a configuration value that should be a number.
290 * @param cfg configuration to inspect
291 * @param section section of interest
292 * @param option option of interest
293 * @param number where to store the numeric value of the option
294 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
297 GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle *cfg,
300 unsigned long long *number);
304 * Get a configuration value that should be a floating point number.
306 * @param cfg configuration to inspect
307 * @param section section of interest
308 * @param option option of interest
309 * @param number where to store the floating value of the option
310 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
313 GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle *cfg,
320 * Get a configuration value that should be a relative time.
322 * @param cfg configuration to inspect
323 * @param section section of interest
324 * @param option option of interest
325 * @param time set to the time value stored in the configuration
326 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
329 GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle *cfg,
332 struct GNUNET_TIME_Relative *time);
337 * Get a configuration value that should be a size in bytes.
339 * @param cfg configuration to inspect
340 * @param section section of interest
341 * @param option option of interest
342 * @param size set to the size in bytes as stored in the configuration
343 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
346 GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle *cfg,
349 unsigned long long *size);
353 * Test if we have a value for a particular option
355 * @param cfg configuration to inspect
356 * @param section section of interest
357 * @param option option of interest
358 * @return #GNUNET_YES if so, #GNUNET_NO if not.
361 GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
367 * Get a configuration value that should be a string.
369 * @param cfg configuration to inspect
370 * @param section section of interest
371 * @param option option of interest
372 * @param value will be set to a freshly allocated configuration
373 * value, or NULL if option is not specified
374 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
377 GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
384 * Get a configuration value that should be the name of a file
387 * @param cfg configuration to inspect
388 * @param section section of interest
389 * @param option option of interest
390 * @param value will be set to a freshly allocated configuration
391 * value, or NULL if option is not specified
392 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
395 GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
402 * Iterate over the set of filenames stored in a configuration value.
404 * @param cfg configuration to inspect
405 * @param section section of interest
406 * @param option option of interest
407 * @param cb function to call on each filename
408 * @param cb_cls closure for @a cb
409 * @return number of filenames iterated over, -1 on error
412 GNUNET_CONFIGURATION_iterate_value_filenames (const struct GNUNET_CONFIGURATION_Handle *cfg,
415 GNUNET_FileNameCallback cb,
419 * Iterate over values of a section in the configuration.
421 * @param cfg configuration to inspect
422 * @param section the section
423 * @param iter function to call on each option
424 * @param iter_cls closure for @a iter
427 GNUNET_CONFIGURATION_iterate_section_values (const struct GNUNET_CONFIGURATION_Handle *cfg,
429 GNUNET_CONFIGURATION_Iterator iter,
433 * Get a configuration value that should be in a set of
436 * @param cfg configuration to inspect
437 * @param section section of interest
438 * @param option option of interest
439 * @param choices NULL-terminated list of legal values
440 * @param value will be set to an entry in the legal list,
441 * or NULL if option is not specified and no default given
442 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
445 GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle *cfg,
448 const char *const *choices,
452 * Get a configuration value that should be in a set of
455 * @param cfg configuration to inspect
456 * @param section section of interest
457 * @param option option of interest
458 * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR
461 GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle *cfg,
467 * Get Crockford32-encoded fixed-size binary data from a configuration.
469 * @param cfg configuration to access
470 * @param section section to access
471 * @param option option to access
472 * @param buf where to store the decoded binary result
473 * @param buf_size exact number of bytes to store in @a buf
474 * @return #GNUNET_OK on success
475 * #GNUNET_NO is the value does not exist
476 * #GNUNET_SYSERR on decoding error
479 GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg,
487 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
488 * where either in the "PATHS" section or the environtment "FOO" is
489 * set to "DIRECTORY". We also support default expansion,
490 * i.e. ${VARIABLE:-default} will expand to $VARIABLE if VARIABLE is
491 * set in PATHS or the environment, and otherwise to "default". Note
492 * that "default" itself can also be a $-expression, thus
493 * "${VAR1:-{$VAR2}}" will expand to VAR1 and if that is not defined
496 * @param cfg configuration to use for path expansion
497 * @param orig string to $-expand (will be freed!) Note that multiple
498 * $-expressions can be present in this string. They will all be
500 * @return $-expanded string
503 GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
508 * Set a configuration value that should be a number.
510 * @param cfg configuration to update
511 * @param section section of interest
512 * @param option option of interest
513 * @param number value to set
516 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
519 unsigned long long number);
523 * Set a configuration value that should be a string.
525 * @param cfg configuration to update
526 * @param section section of interest
527 * @param option option of interest
528 * @param value value to set
531 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
538 * Remove a filename from a configuration value that
539 * represents a list of filenames
541 * @param cfg configuration to update
542 * @param section section of interest
543 * @param option option of interest
544 * @param value filename to remove
545 * @return #GNUNET_OK on success,
546 * #GNUNET_SYSERR if the filename is not in the list
549 GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg,
556 * Append a filename to a configuration value that
557 * represents a list of filenames
559 * @param cfg configuration to update
560 * @param section section of interest
561 * @param option option of interest
562 * @param value filename to append
563 * @return #GNUNET_OK on success,
564 * #GNUNET_SYSERR if the filename already in the list
567 GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg,
572 #if 0 /* keep Emacsens' auto-indent happy */
581 /** @} */ /* end of group configuration */