GNUnet 0.22.0
gnunet_configuration_lib.h
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2006, 2008, 2009, 2018, 2024 GNUnet e.V.
4
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.
9
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.
14
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
35#ifndef GNUNET_CONFIGURATION_LIB_H
36#define GNUNET_CONFIGURATION_LIB_H
37
38
39#include "gnunet_time_lib.h"
40
41#ifdef __cplusplus
42extern "C"
43{
44#if 0 /* keep Emacsens' auto-indent happy */
45}
46#endif
47#endif
48
53
60
61
70 const struct GNUNET_CONFIGURATION_Handle *cfg);
71
72
78void
81
82
95 const char *filename);
96
97
109 const char *defaults_d);
110
111
122
123
132char *
134
135
147 const char *filename);
148
149
158char *
160 const struct GNUNET_CONFIGURATION_Handle *cfg,
161 size_t *size);
162
163
173char *
175 const struct GNUNET_CONFIGURATION_Handle *cfg);
176
177
191 const char *mem,
192 size_t size,
193 const char *source_filename);
194
195
206 const char *filename);
207
208
219 const struct GNUNET_CONFIGURATION_Handle *cfg_default,
220 const struct GNUNET_CONFIGURATION_Handle *cfg_new,
221 const char *filename);
222
223
233 const struct GNUNET_CONFIGURATION_Handle *cfg_default,
234 const struct GNUNET_CONFIGURATION_Handle *cfg_new);
235
236
246 const struct GNUNET_CONFIGURATION_Handle *cfg);
247
248
256typedef enum GNUNET_GenericReturnValue
258 void *cls,
259 const struct GNUNET_CONFIGURATION_Handle *cfg);
260
261
275 const char *filename,
277 void *cb_cls);
278
285void
288
289
298typedef void
300 const char *section,
301 const char *option,
302 const char *value);
303
304
311typedef void
313 const char *section);
314
315
323void
325 const struct GNUNET_CONFIGURATION_Handle *cfg,
327 void *iter_cls);
328
329
337void
339 const struct GNUNET_CONFIGURATION_Handle *cfg,
341 void *iter_cls);
342
343
350void
353 const char *section);
354
355
369 const struct GNUNET_CONFIGURATION_Handle *cfg,
370 const char *section,
371 const char *option,
372 unsigned long long *number);
373
374
388 const struct GNUNET_CONFIGURATION_Handle *cfg,
389 const char *section,
390 const char *option,
391 float *number);
392
393
407 const struct GNUNET_CONFIGURATION_Handle *cfg,
408 const char *section,
409 const char *option,
410 struct GNUNET_TIME_Relative *time);
411
412
426 const struct GNUNET_CONFIGURATION_Handle *cfg,
427 const char *section,
428 const char *option,
429 unsigned long long *size);
430
431
442 const char *section,
443 const char *option);
444
445
460 const struct GNUNET_CONFIGURATION_Handle *cfg,
461 const char *section,
462 const char *option,
463 char **value);
464
465
481 const struct GNUNET_CONFIGURATION_Handle *cfg,
482 const char *section,
483 const char *option,
484 char **value);
485
486
497int
499 const struct GNUNET_CONFIGURATION_Handle *cfg,
500 const char *section,
501 const char *option,
503 void *cb_cls);
504
505
514void
516 const struct GNUNET_CONFIGURATION_Handle *cfg,
517 const char *section,
519 void *iter_cls);
520
521
538 const struct GNUNET_CONFIGURATION_Handle *cfg,
539 const char *section,
540 const char *option,
541 const char *const *choices,
542 const char **value);
543
544
558 const struct GNUNET_CONFIGURATION_Handle *cfg,
559 const char *section,
560 const char *option);
561
562
577 const char *section,
578 const char *option,
579 void *buf,
580 size_t buf_size);
581
582
599char *
601 const struct GNUNET_CONFIGURATION_Handle *cfg,
602 char *orig);
603
604
613void
616 const char *section,
617 const char *option,
618 unsigned long long number);
619
620
629void
632 const char *section,
633 const char *option,
634 const char *value);
635
636
651 const char *section,
652 const char *option,
653 const char *value);
654
655
670 const char *section,
671 const char *option,
672 const char *value);
673
674
681{
682
687 unsigned int api_version;
688
692 char *section;
693
697 char *option;
698
702 char *value;
703
708
713
718
723
727 int full;
728
734
735};
736
737
745#define GNUNET_CONFIGURATION_CONFIG_OPTIONS(cs) \
746 GNUNET_GETOPT_option_flag ( \
747 'F', \
748 "full", \
749 gettext_noop ( \
750 "write the full configuration file, including default values"), \
751 &(cs)->full), \
752 GNUNET_GETOPT_option_flag ( \
753 'f', \
754 "filename", \
755 gettext_noop ( \
756 "interpret option value as a filename (with $-expansion)"), \
757 &(cs)->is_filename), \
758 GNUNET_GETOPT_option_string ('o', \
759 "option", \
760 "OPTION", \
761 gettext_noop ( \
762 "name of the option to access"), \
763 &(cs)->option), \
764 GNUNET_GETOPT_option_flag ( \
765 'r', \
766 "rewrite", \
767 gettext_noop ( \
768 "rewrite the configuration file, even if nothing changed"), \
769 &(cs)->rewrite), \
770 GNUNET_GETOPT_option_flag ( \
771 'd', \
772 "diagnostics", \
773 gettext_noop ( \
774 "output extra diagnostics"), \
775 &(cs)->diagnostics), \
776 GNUNET_GETOPT_option_flag ('S', \
777 "list-sections", \
778 gettext_noop ( \
779 "print available configuration sections"), \
780 &(cs)->list_sections), \
781 GNUNET_GETOPT_option_string ('s', \
782 "section", \
783 "SECTION", \
784 gettext_noop ( \
785 "name of the section to access"), \
786 &(cs)->section), \
787 GNUNET_GETOPT_option_string ('V', \
788 "value", \
789 "VALUE", \
790 gettext_noop ("value to set"), \
791 &(cs)->value)
792
793
800void
803
804
816void
818 void *cls,
819 char *const *args,
820 const char *cfgfile,
821 const struct GNUNET_CONFIGURATION_Handle *cfg);
822
823
824#if 0 /* keep Emacsens' auto-indent happy */
825{
826#endif
827#ifdef __cplusplus
828}
829#endif
830
831#endif
832 /* end of group configuration */
834 /* end of group addition */
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static char * filename
static char * value
Value of the record to add/remove.
Functions related to time.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_data(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, void *buf, size_t buf_size)
Get Crockford32-encoded fixed-size binary data from a configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_is_dirty(const struct GNUNET_CONFIGURATION_Handle *cfg)
Test if there are configuration options that were changed since the last save.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_append_value_filename(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Append a filename to a configuration value that represents a list of filenames.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
void GNUNET_CONFIGURATION_remove_section(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Remove the given section and all options in it.
enum GNUNET_GenericReturnValue(* GNUNET_CONFIGURATION_Callback)(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Signature of a function to be run with a configuration.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
void GNUNET_CONFIGURATION_iterate_sections(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_SectionIterator iter, void *iter_cls)
Iterate over all sections in the configuration.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
void GNUNET_CONFIGURATION_config_settings_free(struct GNUNET_CONFIGURATION_ConfigSettings *cs)
Free resources associated with cs.
void GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over all options in the configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_remove_value_filename(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Remove a filename from a configuration value that represents a list of filenames.
void GNUNET_CONFIGURATION_config_tool_run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main task to run to perform operations typical for gnunet-config as per the configuration settings gi...
void(* GNUNET_CONFIGURATION_SectionIterator)(void *cls, const char *section)
Function to iterate over section.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *source_filename)
De-serializes configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_size(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *size)
Get a configuration value that should be a size in bytes.
char * GNUNET_CONFIGURATION_default_filename(void)
Return the filename of the default configuration filename that is used when no explicit configuration...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
char * GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
Serializes the given configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
void GNUNET_CONFIGURATION_set_value_number(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long number)
Set a configuration value that should be a number.
char * GNUNET_CONFIGURATION_expand_dollar(const struct GNUNET_CONFIGURATION_Handle *cfg, char *orig)
Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" where either in the "PATHS" section or...
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_default(void)
Return GNUnet's default configuration.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_get_diff(const struct GNUNET_CONFIGURATION_Handle *cfg_default, const struct GNUNET_CONFIGURATION_Handle *cfg_new)
Compute configuration with only entries that have been changed.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Parse a configuration file, add all of the options in the file to the configuration environment.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_float(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, float *number)
Get a configuration value that should be a floating point number.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load_from(struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d)
Load default configuration.
int GNUNET_CONFIGURATION_iterate_value_filenames(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, GNUNET_FileNameCallback cb, void *cb_cls)
Iterate over the set of filenames stored in a configuration value.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse_and_run(const char *filename, GNUNET_CONFIGURATION_Callback cb, void *cb_cls)
Parse a configuration file filename and run the function cb with the resulting configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_choice(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *const *choices, const char **value)
Get a configuration value that should be in a set of predefined strings.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
void(* GNUNET_CONFIGURATION_Iterator)(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
void GNUNET_CONFIGURATION_iterate_section_values(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over values of a section in the configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write_diffs(const struct GNUNET_CONFIGURATION_Handle *cfg_default, const struct GNUNET_CONFIGURATION_Handle *cfg_new, const char *filename)
Write only configuration entries that have been changed to configuration file.
char * GNUNET_CONFIGURATION_serialize_diagnostics(const struct GNUNET_CONFIGURATION_Handle *cfg)
Serializes the given configuration with diagnostics information.
void GNUNET_CONFIGURATION_enable_diagnostics(struct GNUNET_CONFIGURATION_Handle *cfg)
Enable extra diagnostics.
enum GNUNET_GenericReturnValue(* GNUNET_FileNameCallback)(void *cls, const char *filename)
Function called with a filename.
GNUNET_GenericReturnValue
Named constants for return values.
static unsigned int size
Size of the "table".
Definition: peer.c:68
uint32_t number
Closure for GNUNET_CONFIGURATION_config_tool_run() with settings for what should be done with the con...
int full
Should the generated configuration file contain the whole configuration?
int global_ret
Return value from the operation, to be returned from 'main'.
int diagnostics
Should we give extra diagnostics?
int list_sections
Whether to show the sections.
int rewrite
Should we write out the configuration file, even if no value was changed?
int is_filename
Treat option as a filename.
unsigned int api_version
Must be set to the API version, i.e.
Time for relative time used by GNUnet, in microseconds.