GNUnet 0.26.2-125-g53de64302
 
Loading...
Searching...
No Matches
Configuration library

Configuration management. More...

Collaboration diagram for Configuration library:

Data Structures

struct  GNUNET_CONFIGURATION_ConfigSettings
 Closure for GNUNET_CONFIGURATION_config_tool_run() with settings for what should be done with the configuration. More...
 

Macros

#define GNUNET_CONFIGURATION_CONFIG_OPTIONS(cs)
 Macro that expands to a set of GNUNET-getopt directives to initialize a struct GNUNET_CONFIGURATION_ConfigSettings from the command line.
 

Typedefs

typedef enum GNUNET_GenericReturnValue(* GNUNET_CONFIGURATION_Callback) (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Signature of a function to be run with a configuration.
 
typedef void(* GNUNET_CONFIGURATION_Iterator) (void *cls, const char *section, const char *option, const char *value)
 Function to iterate over options.
 
typedef void(* GNUNET_CONFIGURATION_SectionIterator) (void *cls, const char *section)
 Function to iterate over all configuration sections.
 

Functions

struct GNUNET_CONFIGURATION_HandleGNUNET_CONFIGURATION_create (const struct GNUNET_OS_ProjectData *pd)
 Create a new configuration object.
 
struct GNUNET_CONFIGURATION_HandleGNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Duplicate an existing configuration object.
 
void GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
 Destroy configuration object.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
 Load configuration.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d)
 Load default configuration.
 
char * GNUNET_CONFIGURATION_default_filename (const struct GNUNET_OS_ProjectData *pd)
 Return the filename of the default configuration filename that is used when no explicit configuration entry point has been specified.
 
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.
 
char * GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
 Serializes the given configuration.
 
char * GNUNET_CONFIGURATION_serialize_diagnostics (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Serializes the given configuration with diagnostics information.
 
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_write (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
 Write configuration file.
 
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.
 
struct GNUNET_CONFIGURATION_HandleGNUNET_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_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Test if there are configuration options that were changed since the last save.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse_and_run (const struct GNUNET_OS_ProjectData *pd, 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.
 
void GNUNET_CONFIGURATION_enable_diagnostics (struct GNUNET_CONFIGURATION_Handle *cfg)
 Enable extra diagnostics.
 
const struct GNUNET_OS_ProjectDataGNUNET_CONFIGURATION_get_project_data (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Return the project data associated with this configuration.
 
void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
 Iterate over all options in the configuration.
 
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_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
 Remove the given section and all options in it.
 
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_set_value_float (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, float number)
 Set a configuration value that should be a float.
 
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_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_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.
 
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_string (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
 Get a configuration value that should be a string.
 
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.
 
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.
 
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_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_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".
 
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.
 
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 the environment "FOO" is set to "DIRECTORY".
 
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.
 
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_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.
 
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.
 
void GNUNET_CONFIGURATION_config_settings_free (struct GNUNET_CONFIGURATION_ConfigSettings *cs)
 Free resources associated with cs.
 
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 given in cls.
 

Detailed Description

Configuration management.

Macro Definition Documentation

◆ GNUNET_CONFIGURATION_CONFIG_OPTIONS

#define GNUNET_CONFIGURATION_CONFIG_OPTIONS (   cs)

Macro that expands to a set of GNUNET-getopt directives to initialize a struct GNUNET_CONFIGURATION_ConfigSettings from the command line.

Parameters
csconfiguration settings to initialize

Definition at line 764 of file gnunet_configuration_lib.h.

843{
844#endif
845#ifdef __cplusplus
846}
847#endif
848
849#endif
850
/* end of group configuration */
852
/* end of group addition */

Typedef Documentation

◆ GNUNET_CONFIGURATION_Callback

typedef enum GNUNET_GenericReturnValue(* GNUNET_CONFIGURATION_Callback) (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)

Signature of a function to be run with a configuration.

Parameters
clsclosure
cfgthe configuration
Returns
status code

Definition at line 237 of file gnunet_configuration_lib.h.

◆ GNUNET_CONFIGURATION_Iterator

typedef void(* GNUNET_CONFIGURATION_Iterator) (void *cls, const char *section, const char *option, const char *value)

Function to iterate over options.

Parameters
clsclosure
sectionname of the section
optionname of the option
valuevalue of the option

Definition at line 303 of file gnunet_configuration_lib.h.

◆ GNUNET_CONFIGURATION_SectionIterator

typedef void(* GNUNET_CONFIGURATION_SectionIterator) (void *cls, const char *section)

Function to iterate over all configuration sections.

Parameters
clsclosure
sectionname of the section

Definition at line 316 of file gnunet_configuration_lib.h.

Function Documentation

◆ GNUNET_CONFIGURATION_create()

struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create ( const struct GNUNET_OS_ProjectData pd)

Create a new configuration object.

Parameters
pdproject data to use to determine paths
Returns
fresh configuration object

Definition at line 227 of file configuration.c.

228{
230 char *p;
231
233 cfg->pd = pd;
234 /* make certain values from the project data available
235 as PATHS */
238 if (NULL != p)
239 {
241 "PATHS",
242 "DATADIR",
243 p);
244 GNUNET_free (p);
245 }
248 if (NULL != p)
249 {
251 "PATHS",
252 "LIBDIR",
253 p);
254 GNUNET_free (p);
255 }
258 if (NULL != p)
259 {
261 "PATHS",
262 "BINDIR",
263 p);
264 GNUNET_free (p);
265 }
268 if (NULL != p)
269 {
271 "PATHS",
272 "PREFIX",
273 p);
274 GNUNET_free (p);
275 }
278 if (NULL != p)
279 {
281 "PATHS",
282 "LOCALEDIR",
283 p);
284 GNUNET_free (p);
285 }
288 if (NULL != p)
289 {
291 "PATHS",
292 "ICONDIR",
293 p);
294 GNUNET_free (p);
295 }
298 if (NULL != p)
299 {
301 "PATHS",
302 "DOCDIR",
303 p);
304 GNUNET_free (p);
305 }
308 if (NULL != p)
309 {
311 "PATHS",
312 "LIBEXECDIR",
313 p);
314 GNUNET_free (p);
315 }
316 return cfg;
317}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static struct GNUNET_Process * p
Helper process we started.
Definition gnunet-uri.c:38
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.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_OS_installation_get_path(const struct GNUNET_OS_ProjectData *pd, enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
@ GNUNET_OS_IPK_ICONDIR
Return the prefix of the path with application icons (share/icons/).
@ GNUNET_OS_IPK_DATADIR
Return the directory where data is installed (share/gnunet/)
@ GNUNET_OS_IPK_DOCDIR
Return the prefix of the path with documentation files, including the license (share/doc/gnunet/).
@ GNUNET_OS_IPK_LOCALEDIR
Return the directory where translations are installed (share/locale/)
@ GNUNET_OS_IPK_LIBDIR
Return the directory where libraries are installed.
@ GNUNET_OS_IPK_PREFIX
Return the "PREFIX" directory given to configure.
@ GNUNET_OS_IPK_BINDIR
Return the directory where the program binaries are installed.
@ GNUNET_OS_IPK_LIBEXECDIR
Return the directory where helper binaries are installed (lib/gnunet/libexec/)
const struct GNUNET_OS_ProjectData * pd
Project data for this configuration object.

References cfg, GNUNET_CONFIGURATION_set_value_string(), GNUNET_free, GNUNET_new, GNUNET_OS_installation_get_path(), GNUNET_OS_IPK_BINDIR, GNUNET_OS_IPK_DATADIR, GNUNET_OS_IPK_DOCDIR, GNUNET_OS_IPK_ICONDIR, GNUNET_OS_IPK_LIBDIR, GNUNET_OS_IPK_LIBEXECDIR, GNUNET_OS_IPK_LOCALEDIR, GNUNET_OS_IPK_PREFIX, p, and GNUNET_CONFIGURATION_Handle::pd.

Referenced by auto_config_cb(), create_unique_cfgs(), gg_load_configuration(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_dup(), GNUNET_CONFIGURATION_get_diff(), GNUNET_CONFIGURATION_parse_and_run(), GNUNET_PROGRAM_conf_and_options(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), GNUNET_TESTING_get_topo_from_string_(), GNUNET_TRANSPORT_TESTING_start_peer(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(), handle_auto_result(), handle_autoconfig_request(), handle_inline(), iter_check_config(), load_member(), load_member_session(), load_member_session_next(), load_operation(), main(), main(), run(), run(), save_member(), save_member_session(), save_operation(), start_peer_run(), and start_peer_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_dup()

struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup ( const struct GNUNET_CONFIGURATION_Handle cfg)

Duplicate an existing configuration object.

Parameters
cfgconfiguration to duplicate
Returns
duplicate configuration

Definition at line 1652 of file configuration.c.

1654{
1656
1659 &copy_entry,
1660 ret);
1661 return ret;
1662}
static void copy_entry(void *cls, const char *section, const char *option, const char *value)
Copy a configuration value to the given target configuration.
static int ret
Final status code.
Definition gnunet-arm.c:93
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(const struct GNUNET_OS_ProjectData *pd)
Create a new configuration object.
void GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over all options in the configuration.

References cfg, copy_entry(), GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_iterate(), GNUNET_CONFIGURATION_Handle::pd, and ret.

Referenced by auto_config_cb(), create_unique_cfgs(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_NAT_autoconfig_start(), handle_autoconfig_request(), run(), run(), run(), and set_cont().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_destroy()

void GNUNET_CONFIGURATION_destroy ( struct GNUNET_CONFIGURATION_Handle cfg)

Destroy configuration object.

Parameters
cfgconfiguration to destroy

Definition at line 321 of file configuration.c.

322{
323 struct ConfigSection *sec;
324 struct ConfigFile *cf;
325
326 while (NULL != (sec = cfg->sections))
328 while (NULL != (cf = cfg->loaded_files_head))
329 {
334 cf);
335 GNUNET_free (cf);
336 }
339}
void GNUNET_CONFIGURATION_remove_section(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Remove the given section and all options in it.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
char * hint_restrict_section
Was this configuration file parsed via @inline-secret@?
char * source_filename
Source filename.
configuration section
char * name
name of the section
struct ConfigFile * loaded_files_tail
Linked list of loaded files.
struct ConfigSection * sections
Configuration sections.
struct ConfigFile * loaded_files_head
Linked list of loaded files.
char * main_filename
Name of the entry point configuration file.

References cfg, GNUNET_CONFIGURATION_remove_section(), GNUNET_CONTAINER_DLL_remove, GNUNET_free, ConfigFile::hint_restrict_section, GNUNET_CONFIGURATION_Handle::loaded_files_head, GNUNET_CONFIGURATION_Handle::loaded_files_tail, GNUNET_CONFIGURATION_Handle::main_filename, ConfigSection::name, GNUNET_CONFIGURATION_Handle::sections, and ConfigFile::source_filename.

Referenced by auto_config_cb(), clean_node(), conclude_autoconfig_request(), create_unique_cfgs(), do_shutdown(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_parse_and_run(), GNUNET_CONFIGURATION_write_diffs(), GNUNET_NAT_autoconfig_cancel(), GNUNET_PROGRAM_conf_and_options(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), GNUNET_TESTING_get_topo_from_string_(), GNUNET_TRANSPORT_TESTING_start_peer(), GNUNET_TRANSPORT_TESTING_stop_peer(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop(), handle_auto_result(), handle_autoconfig_request(), handle_inline(), load_member(), load_member_session(), load_member_session_next(), load_operation(), main(), next_phase(), save_member(), save_member_session(), save_operation(), shutdown_task(), shutdown_task(), shutdown_task(), start_peer_cleanup(), and start_peer_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_load()

enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load ( struct GNUNET_CONFIGURATION_Handle cfg,
const char *  filename 
)

Load configuration.

This function will first parse the defaults and then parse the specific configuration file to overwrite the defaults.

Parameters
[in,out]cfgconfiguration to update
filenamename of the configuration file, NULL to load defaults
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 2645 of file configuration.c.

2648{
2649 char *baseconfig;
2650 const char *base_config_varname;
2651
2652 if (cfg->load_called)
2653 {
2654 /* FIXME: Make this a GNUNET_assert later */
2655 GNUNET_break (0);
2657 }
2658 cfg->load_called = true;
2659 if (NULL != filename)
2660 {
2663 }
2664
2665 base_config_varname = cfg->pd->base_config_varname;
2666
2667 if ((NULL != base_config_varname)
2668 && (NULL != (baseconfig = getenv (base_config_varname))))
2669 {
2670 baseconfig = GNUNET_strdup (baseconfig);
2671 }
2672 else
2673 {
2674 char *ipath;
2675
2678 if (NULL == ipath)
2679 {
2680 GNUNET_break (0);
2681 return GNUNET_SYSERR;
2682 }
2683 GNUNET_asprintf (&baseconfig,
2684 "%s%s",
2685 ipath,
2686 "config.d");
2687 GNUNET_free (ipath);
2688 }
2689
2690 {
2691 char *dname = GNUNET_STRINGS_filename_expand (baseconfig);
2692
2693 GNUNET_free (baseconfig);
2694
2695 if ((GNUNET_YES ==
2697 GNUNET_YES)) &&
2698 (GNUNET_SYSERR ==
2700 dname)))
2701 {
2703 "Failed to load base configuration from '%s'\n",
2704 filename);
2705 GNUNET_free (dname);
2706 return GNUNET_SYSERR; /* no configuration at all found */
2707 }
2708 GNUNET_free (dname);
2709 }
2710 if ((NULL != filename) &&
2711 (GNUNET_OK !=
2713 filename)))
2714 {
2715 /* specified configuration not found */
2717 "Failed to load configuration from file '%s'\n",
2718 filename);
2719 return GNUNET_SYSERR;
2720 }
2721 if (((GNUNET_YES !=
2723 "PATHS",
2724 "DEFAULTCONFIG"))) &&
2725 (filename != NULL))
2727 "PATHS",
2728 "DEFAULTCONFIG",
2729 filename);
2730 return GNUNET_OK;
2731}
#define LOG(kind,...)
char * getenv()
static char * filename
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_load_from(struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d)
Load default configuration.
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_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition disk.c:466
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition strings.c:525
bool load_called
Was the configuration ever loaded via GNUNET_CONFIGURATION_load?
const char * base_config_varname
Name of an environment variable that can be used to override the location from which default configur...

References GNUNET_OS_ProjectData::base_config_varname, cfg, filename, getenv(), GNUNET_asprintf(), GNUNET_break, GNUNET_CONFIGURATION_have_value(), GNUNET_CONFIGURATION_load_from(), GNUNET_CONFIGURATION_parse(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_DISK_directory_test(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_OK, GNUNET_OS_installation_get_path(), GNUNET_OS_IPK_DATADIR, GNUNET_strdup, GNUNET_STRINGS_filename_expand(), GNUNET_SYSERR, GNUNET_YES, GNUNET_CONFIGURATION_Handle::load_called, LOG, GNUNET_CONFIGURATION_Handle::main_filename, and GNUNET_CONFIGURATION_Handle::pd.

Referenced by auto_config_cb(), create_unique_cfgs(), gg_load_configuration(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_parse_and_run(), GNUNET_PROGRAM_conf_and_options(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), GNUNET_TRANSPORT_TESTING_start_peer(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(), iter_check_config(), main(), main(), start_peer_run(), and start_peer_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_load_from()

enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load_from ( struct GNUNET_CONFIGURATION_Handle cfg,
const char *  defaults_d 
)

Load default configuration.

This function will parse the defaults from the given defaults_d directory.

Parameters
cfgconfiguration to update
defaults_ddirectory with the defaults
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 2547 of file configuration.c.

2550{
2551 struct CollectFilesContext files_context = {
2552 .files = NULL,
2553 .files_length = 0,
2554 };
2555 enum GNUNET_GenericReturnValue fun_ret;
2556
2557 if (GNUNET_SYSERR ==
2558 GNUNET_DISK_directory_scan (defaults_d,
2560 &files_context))
2561 return GNUNET_SYSERR; /* no configuration at all found */
2562 qsort (files_context.files,
2563 files_context.files_length,
2564 sizeof (char *),
2565 &pstrcmp);
2566 for (unsigned int i = 0; i < files_context.files_length; i++)
2567 {
2568 const char *ext;
2569 const char *filename = files_context.files[i];
2570
2571 /* Examine file extension */
2572 ext = strrchr (filename, '.');
2573 if ( (NULL == ext) ||
2574 (0 != strcmp (ext,
2575 ".conf")) )
2576 {
2578 "Skipping file `%s'\n",
2579 filename);
2580 fun_ret = GNUNET_OK;
2581 continue;
2582 }
2584 filename);
2585 if (fun_ret != GNUNET_OK)
2586 break;
2587 }
2588 if (files_context.files_length > 0)
2589 {
2590 for (size_t i = 0; i < files_context.files_length; i++)
2591 GNUNET_free (files_context.files[i]);
2592 GNUNET_array_grow (files_context.files,
2593 files_context.files_length,
2594 0);
2595 }
2596 return fun_ret;
2597}
static int pstrcmp(const void *a, const void *b)
static enum GNUNET_GenericReturnValue collect_files_cb(void *cls, const char *filename)
Function called with a filename.
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition disk.c:881
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
Closure to collect_files_cb.
char ** files
Collected files from globbing.
unsigned int files_length
Size of the files array.

References cfg, collect_files_cb(), filename, CollectFilesContext::files, CollectFilesContext::files_length, GNUNET_array_grow, GNUNET_CONFIGURATION_parse(), GNUNET_DISK_directory_scan(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, and pstrcmp().

Referenced by GNUNET_CONFIGURATION_load().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_default_filename()

char * GNUNET_CONFIGURATION_default_filename ( const struct GNUNET_OS_ProjectData pd)

Return the filename of the default configuration filename that is used when no explicit configuration entry point has been specified.

Parameters
pdproject data to use to determine paths
Returns
NULL if no default configuration file can be located, a newly allocated string otherwise

Definition at line 2601 of file configuration.c.

2603{
2604 char *cfg_fn;
2605 const char *xdg = getenv ("XDG_CONFIG_HOME");
2606
2607 if (NULL != xdg)
2608 GNUNET_asprintf (&cfg_fn,
2609 "%s%s%s",
2610 xdg,
2612 pd->config_file);
2613 else
2614 cfg_fn = GNUNET_strdup (pd->user_config_file);
2615
2616 if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2617 return cfg_fn;
2618 GNUNET_free (cfg_fn);
2619
2620 /* Fall back to /etc/ for the default configuration.
2621 Should be okay to use forward slashes here. */
2622
2623 GNUNET_asprintf (&cfg_fn,
2624 "/etc/%s",
2625 pd->config_file);
2626 if (GNUNET_OK ==
2628 return cfg_fn;
2629 GNUNET_free (cfg_fn);
2630
2631 GNUNET_asprintf (&cfg_fn,
2632 "/etc/%s/%s",
2633 pd->project_dirname,
2634 pd->config_file);
2635 if (GNUNET_OK ==
2637 return cfg_fn;
2638
2639 GNUNET_free (cfg_fn);
2640 return NULL;
2641}
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test_read(const char *fil)
Check that fil corresponds to a filename and the file has read permissions.
Definition disk.c:565
#define DIR_SEPARATOR_STR
Definition platform.h:167
const char * project_dirname
Name of the project that is used in the "libexec" prefix, For example, "gnunet".
const char * user_config_file
Configuration file name to use (if $XDG_CONFIG_HOME is not set).
const char * config_file
Configuration file name (in $XDG_CONFIG_HOME) to use.

References GNUNET_OS_ProjectData::config_file, DIR_SEPARATOR_STR, getenv(), GNUNET_asprintf(), GNUNET_DISK_file_test_read(), GNUNET_free, GNUNET_OK, GNUNET_strdup, GNUNET_OS_ProjectData::project_dirname, and GNUNET_OS_ProjectData::user_config_file.

Referenced by GNUNET_PROGRAM_run2(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_parse()

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.

Parameters
cfgconfiguration to update
filenamename of the configuration file
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 998 of file configuration.c.

1000{
1001 uint64_t fs64;
1002 size_t fs;
1003 char *fn;
1004 char *mem;
1005 int dirty;
1007 ssize_t sret;
1008
1011 "Asked to parse config file `%s'\n",
1012 fn);
1013 if (NULL == fn)
1014 return GNUNET_SYSERR;
1015
1016
1017 /* Check for cycles */
1018 {
1019 unsigned int lvl = cfg->current_nest_level;
1020 struct ConfigFile *cf = cfg->loaded_files_tail;
1021 struct ConfigFile *parent = NULL;
1022
1023
1024 for (; NULL != cf; parent = cf, cf = cf->prev)
1025 {
1026 /* Check parents based on level, skipping children of siblings. */
1027 if (cf->level >= lvl)
1028 continue;
1029 lvl = cf->level;
1030 if ( (NULL == cf->source_filename) ||
1031 (NULL == filename) )
1032 continue;
1033 if (0 == strcmp (cf->source_filename,
1034 filename))
1035 {
1036 if (NULL == parent)
1037 {
1039 "Forbidden direct cyclic configuration import (%s -> %s)\n",
1040 cf->source_filename,
1041 filename);
1042 }
1043 else
1045 "Forbidden indirect cyclic configuration import (%s -> ... -> %s -> %s)\n",
1046 cf->source_filename,
1047 parent->source_filename,
1048 filename);
1049 GNUNET_free (fn);
1050 return GNUNET_SYSERR;
1051 }
1052 }
1053
1054 }
1055
1056 /* Keep track of loaded files.*/
1057 {
1058 struct ConfigFile *cf = GNUNET_new (struct ConfigFile);
1059
1061 cf->source_filename = GNUNET_strdup (filename ? filename : "<input>");
1064 cf);
1065 }
1066
1067 dirty = cfg->dirty; /* back up value! */
1068 if (GNUNET_SYSERR ==
1070 &fs64,
1071 GNUNET_NO,
1072 GNUNET_YES))
1073 {
1075 "Error while determining the file size of `%s'\n",
1076 fn);
1077 GNUNET_free (fn);
1078 return GNUNET_SYSERR;
1079 }
1080 if (fs64 > SIZE_MAX)
1081 {
1082 GNUNET_break (0); /* File size is more than the heap size */
1083 GNUNET_free (fn);
1084 return GNUNET_SYSERR;
1085 }
1086 fs = fs64;
1087 mem = GNUNET_malloc (fs);
1088 sret = GNUNET_DISK_fn_read (fn,
1089 mem,
1090 fs);
1091 if ((sret < 0) || (fs != (size_t) sret))
1092 {
1094 "Error while reading file `%s'\n",
1095 fn);
1096 GNUNET_free (fn);
1097 GNUNET_free (mem);
1098 return GNUNET_SYSERR;
1099 }
1101 "Deserializing contents of file `%s'\n",
1102 fn);
1104 mem,
1105 fs,
1106 fn);
1107 if (GNUNET_SYSERR == ret)
1108 {
1110 _ ("Failed to parse configuration file `%s'\n"),
1111 fn);
1112 }
1113 GNUNET_free (fn);
1114 GNUNET_free (mem);
1115 /* restore dirty flag - anything we set in the meantime
1116 * came from disk */
1117 cfg->dirty = dirty;
1118 return ret;
1119}
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition gnunet-fs.c:35
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_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition disk.c:235
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition disk.c:720
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
@ GNUNET_NO
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_malloc(size)
Wrapper around malloc.
#define _(String)
GNU gettext support macro.
Definition platform.h:179
#define SIZE_MAX
Definition platform.h:209
struct ConfigFile * prev
unsigned int level
Level in the tree of loaded config files.
unsigned int current_nest_level
Current nesting level of file loading.
enum GNUNET_GenericReturnValue dirty
Modification indication since last save GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on err...

References _, cfg, GNUNET_CONFIGURATION_Handle::current_nest_level, GNUNET_CONFIGURATION_Handle::dirty, filename, fs, GNUNET_break, GNUNET_CONFIGURATION_deserialize(), GNUNET_CONTAINER_DLL_insert_tail, GNUNET_DISK_file_size(), GNUNET_DISK_fn_read(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_new, GNUNET_NO, GNUNET_strdup, GNUNET_STRINGS_filename_expand(), GNUNET_SYSERR, GNUNET_YES, ConfigFile::level, GNUNET_CONFIGURATION_Handle::loaded_files_head, GNUNET_CONFIGURATION_Handle::loaded_files_tail, LOG, ConfigFile::prev, ret, SIZE_MAX, and ConfigFile::source_filename.

Referenced by GNUNET_CONFIGURATION_load(), GNUNET_CONFIGURATION_load_from(), handle_inline(), load_member(), load_member_session(), load_member_session_next(), load_operation(), main(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_serialize()

char * GNUNET_CONFIGURATION_serialize ( const struct GNUNET_CONFIGURATION_Handle cfg,
size_t *  size 
)

Serializes the given configuration.

Parameters
cfgconfiguration to serialize
sizewill be set to the size of the serialized memory block
Returns
the memory block where the serialized configuration is present. This memory should be freed by the caller

Definition at line 1165 of file configuration.c.

1167{
1168 char *mem;
1169 char *cbuf;
1170 char *val;
1171 char *pos;
1172 size_t m_size;
1173 size_t c_size;
1174
1175 /* Pass1 : calculate the buffer size required */
1176 m_size = 0;
1177 for (struct ConfigSection *sec = cfg->sections;
1178 NULL != sec;
1179 sec = sec->next)
1180 {
1181 if (sec->inaccessible && (NULL == sec->entries))
1182 continue;
1183 /* For each section we need to add 3 characters: {'[',']','\n'} */
1184 m_size += strlen (sec->name) + 3;
1185 for (struct ConfigEntry *ent = sec->entries;
1186 NULL != ent;
1187 ent = ent->next)
1188 {
1189 if (do_skip (sec->name,
1190 ent->key))
1191 continue;
1192 if (NULL != ent->val)
1193 {
1194 /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */
1195 pos = ent->val;
1196 while (NULL != (pos = strstr (pos, "\n")))
1197 {
1198 m_size++;
1199 pos++;
1200 }
1201 /* For each key = value pair we need to add 4 characters (2
1202 spaces and 1 equal-to character and 1 new line) */
1203 m_size += strlen (ent->key) + strlen (ent->val) + 4;
1204 }
1205 }
1206 /* A new line after section end */
1207 m_size++;
1208 }
1209
1210 /* Pass2: Allocate memory and write the configuration to it */
1211 mem = GNUNET_malloc (m_size);
1212 c_size = 0;
1213 *size = c_size;
1214 for (struct ConfigSection *sec = cfg->sections;
1215 NULL != sec;
1216 sec = sec->next)
1217 {
1218 int len;
1219
1220 len = GNUNET_asprintf (&cbuf,
1221 "[%s]\n",
1222 sec->name);
1223 GNUNET_assert (0 < len);
1224 GNUNET_memcpy (mem + c_size,
1225 cbuf,
1226 len);
1227 c_size += len;
1228 GNUNET_free (cbuf);
1229 for (struct ConfigEntry *ent = sec->entries;
1230 NULL != ent;
1231 ent = ent->next)
1232 {
1233 if (do_skip (sec->name,
1234 ent->key))
1235 continue;
1236 if (NULL != ent->val)
1237 {
1238 val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1239 strcpy (val, ent->val);
1240 while (NULL != (pos = strstr (val, "\n")))
1241 {
1242 memmove (&pos[2], &pos[1], strlen (&pos[1]));
1243 pos[0] = '\\';
1244 pos[1] = 'n';
1245 }
1246 len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
1247 GNUNET_free (val);
1248 GNUNET_memcpy (mem + c_size, cbuf, len);
1249 c_size += len;
1250 GNUNET_free (cbuf);
1251 }
1252 }
1253 GNUNET_memcpy (mem + c_size, "\n", 1);
1254 c_size++;
1255 }
1256 GNUNET_assert (c_size == m_size);
1257 *size = c_size;
1258 return mem;
1259}
static bool do_skip(const char *sec, const char *key)
Should we skip this configuration entry when serializing?
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static unsigned int size
Size of the "table".
Definition peer.c:68
configuration entry

References cfg, do_skip(), GNUNET_asprintf(), GNUNET_assert, GNUNET_free, GNUNET_malloc, GNUNET_memcpy, GNUNET_CONFIGURATION_Handle::sections, and size.

Referenced by conclude_autoconfig_request(), GNUNET_CONFIGURATION_write(), and GNUNET_NAT_AUTO_autoconfig_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_serialize_diagnostics()

char * GNUNET_CONFIGURATION_serialize_diagnostics ( const struct GNUNET_CONFIGURATION_Handle cfg)

Serializes the given configuration with diagnostics information.

Diagnostics information will only be available if diagnostics have been enabled before parsing.

Parameters
cfgconfiguration to serialize
Returns
the memory block where the serialized configuration is present. This memory should be freed by the caller

Definition at line 1319 of file configuration.c.

1321{
1322 struct GNUNET_Buffer buf = { 0 };
1323
1325 "#\n# Configuration file diagnostics\n#\n");
1327 "# Entry point: %s\n",
1329 "<none>");
1331 "#\n# Files Loaded:\n");
1332
1333 for (struct ConfigFile *cfil = cfg->loaded_files_head;
1334 NULL != cfil;
1335 cfil = cfil->next)
1336 {
1338 "# ");
1339 for (unsigned int i = 0; i < cfil->level; i++)
1341 "+");
1342 if (0 != cfil->level)
1344 " ");
1345
1347 "%s",
1348 cfil->source_filename);
1349
1350 if (NULL != cfil->hint_restrict_section)
1352 " (%s secret section %s)",
1353 cfil->hint_inaccessible
1354 ? "inaccessible"
1355 : "loaded",
1356 cfil->hint_restrict_section);
1357
1359 "\n");
1360 }
1361
1363 "#\n# Installation paths:\n");
1364
1374
1375
1377 "#\n\n");
1378
1379 for (struct ConfigSection *sec = cfg->sections;
1380 NULL != sec;
1381 sec = sec->next)
1382 {
1383 if (sec->hint_secret_filename)
1385 "# secret section from %s\n# secret file stat %s\n",
1386 sec->hint_secret_filename,
1387 sec->hint_secret_stat);
1388 if (sec->hint_inlined_from_filename)
1389 {
1391 "# inlined from %s:%u\n",
1392 sec->hint_inlined_from_filename,
1393 sec->hint_inlined_from_line);
1394 }
1396 "[%s]\n\n",
1397 sec->name);
1398 if (sec->inaccessible && (NULL == sec->entries))
1399 {
1401 "# <section contents inaccessible>\n\n\n");
1402 continue;
1403 }
1404 for (struct ConfigEntry *ent = sec->entries;
1405 NULL != ent;
1406 ent = ent->next)
1407 {
1408 if (do_skip (sec->name,
1409 ent->key))
1410 continue;
1411 if (NULL != ent->val)
1412 {
1413 char *pos;
1414 char *val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1415 strcpy (val, ent->val);
1416 while (NULL != (pos = strstr (val, "\n")))
1417 {
1418 memmove (&pos[2], &pos[1], strlen (&pos[1]));
1419 pos[0] = '\\';
1420 pos[1] = 'n';
1421 }
1422 if (NULL != ent->hint_filename)
1423 {
1425 "# %s:%u\n",
1426 ent->hint_filename,
1427 ent->hint_lineno);
1428 }
1430 "%s = %s\n",
1431 ent->key,
1432 val);
1433 GNUNET_free (val);
1434 }
1435 GNUNET_buffer_write_str (&buf, "\n");
1436 }
1437 if (sec->inaccessible)
1438 {
1440 "# <additional section contents inaccessible>\n\n\n");
1441 continue;
1442 }
1443
1444 GNUNET_buffer_write_str (&buf, "\n");
1445 }
1446 return GNUNET_buffer_reap_str (&buf);
1447}
static void dump_os_ipk(const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_Buffer *buf, enum GNUNET_OS_InstallationPathKind ipk)
Dump an os installation path to a buffer.
char * GNUNET_buffer_reap_str(struct GNUNET_Buffer *buf)
Clear the buffer and return the string it contained.
Definition buffer.c:89
void GNUNET_buffer_write_fstr(struct GNUNET_Buffer *buf, const char *fmt,...) __attribute__((format(printf
Write a 0-terminated formatted string to a buffer, excluding the 0-terminator.
void GNUNET_buffer_write_str(struct GNUNET_Buffer *buf, const char *str)
Write a 0-terminated string to a buffer, excluding the 0-terminator.
Definition buffer.c:77
@ GNUNET_OS_IPK_SELF_PREFIX
Return the installation directory of this application, not the one of the overall GNUnet installation...
Dynamically growing buffer.

References cfg, do_skip(), dump_os_ipk(), GNUNET_buffer_reap_str(), GNUNET_buffer_write_fstr(), GNUNET_buffer_write_str(), GNUNET_free, GNUNET_malloc, GNUNET_OS_IPK_BINDIR, GNUNET_OS_IPK_DATADIR, GNUNET_OS_IPK_DOCDIR, GNUNET_OS_IPK_ICONDIR, GNUNET_OS_IPK_LIBDIR, GNUNET_OS_IPK_LIBEXECDIR, GNUNET_OS_IPK_LOCALEDIR, GNUNET_OS_IPK_PREFIX, GNUNET_OS_IPK_SELF_PREFIX, GNUNET_CONFIGURATION_Handle::loaded_files_head, GNUNET_CONFIGURATION_Handle::main_filename, and GNUNET_CONFIGURATION_Handle::sections.

Referenced by GNUNET_CONFIGURATION_config_tool_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_deserialize()

enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize ( struct GNUNET_CONFIGURATION_Handle cfg,
const char *  mem,
size_t  size,
const char *  source_filename 
)

De-serializes configuration.

Parameters
cfgconfiguration to update
memthe memory block of serialized configuration
sizethe size of the memory block
source_filenamesource filename, will be used to resolve relative @INLINE@ statements
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 733 of file configuration.c.

737{
738 size_t line_size;
739 unsigned int nr;
740 size_t r_bytes;
741 size_t to_read;
743 char *section;
744 char *eq;
745 char *tag;
746 char *value;
747 char *line_orig = NULL;
748
749 ret = GNUNET_OK;
750 section = NULL;
751 nr = 0;
752 r_bytes = 0;
753 while (r_bytes < size)
754 {
755 const char *pos;
756 char *line;
757 bool emptyline;
758
759 GNUNET_free (line_orig);
760 /* fgets-like behaviour on buffer */
761 to_read = size - r_bytes;
762 pos = memchr (&mem[r_bytes], '\n', to_read);
763 if (NULL == pos)
764 {
765 line_orig = GNUNET_strndup (&mem[r_bytes],
766 line_size = to_read);
767 r_bytes += line_size;
768 }
769 else
770 {
771 line_orig = GNUNET_strndup (&mem[r_bytes],
772 line_size = (pos - &mem[r_bytes]));
773 r_bytes += line_size + 1;
774 }
775 line = line_orig;
776 /* increment line number */
777 nr++;
778 /* tabs and '\r' are whitespace */
779 emptyline = GNUNET_YES;
780 for (size_t i = 0; i < line_size; i++)
781 {
782 if (line[i] == '\t')
783 line[i] = ' ';
784 if (line[i] == '\r')
785 line[i] = ' ';
786 if (' ' != line[i])
787 emptyline = GNUNET_NO;
788 }
789 /* ignore empty lines */
790 if (GNUNET_YES == emptyline)
791 continue;
792
793 /* remove tailing whitespace */
794 for (size_t i = line_size - 1;
795 (i >= 1) && (isspace ((unsigned char) line[i]));
796 i--)
797 line[i] = '\0';
798
799 /* remove leading whitespace */
800 for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++)
801 ;
802
803 /* ignore comments */
804 if ( ('#' == line[0]) ||
805 ('%' == line[0]) )
806 continue;
807
808 /* Handle special directives. */
809 if ('@' == line[0])
810 {
811 char *end = strchr (line + 1, '@');
812 char *directive;
813 enum GNUNET_GenericReturnValue directive_ret;
814
815 if (NULL != cfg->restrict_section)
816 {
818 "Illegal directive in line %u (parsing restricted section %s)\n",
819 nr,
822 break;
823 }
824
825 if (NULL == end)
826 {
828 "Bad directive in line %u\n",
829 nr);
831 break;
832 }
833 *end = '\0';
834 directive = line + 1;
835
836 if (0 == strcasecmp (directive,
837 "INLINE"))
838 {
839 const char *path = end + 1;
840
841 /* Skip space before path */
842 for (; isspace (*path); path++)
843 ;
844
845 directive_ret = handle_inline (cfg,
846 path,
847 false,
848 NULL,
849 source_filename,
850 nr);
851 }
852 else if (0 == strcasecmp (directive,
853 "INLINE-MATCHING"))
854 {
855 const char *path = end + 1;
856
857 /* Skip space before path */
858 for (; isspace (*path); path++)
859 ;
860
861 directive_ret = handle_inline (cfg,
862 path,
863 true,
864 NULL,
865 source_filename,
866 nr);
867 }
868 else if (0 == strcasecmp (directive,
869 "INLINE-SECRET"))
870 {
871 char *secname = end + 1;
872 char *secname_end;
873 const char *path;
874
875 /* Skip space before secname */
876 for (; isspace (*secname); secname++)
877 ;
878
879 secname_end = strchr (secname, ' ');
880
881 if (NULL == secname_end)
882 {
884 "Bad inline-secret directive in line %u\n",
885 nr);
887 break;
888 }
889 *secname_end = '\0';
890 path = secname_end + 1;
891
892 /* Skip space before path */
893 for (; isspace (*path); path++)
894 ;
895
896 directive_ret = handle_inline (cfg,
897 path,
898 false,
899 secname,
900 source_filename,
901 nr);
902 }
903 else
904 {
906 "Unknown or malformed directive '%s' in line %u\n",
907 directive,
908 nr);
910 break;
911 }
912 if (GNUNET_OK != directive_ret)
913 {
914 ret = directive_ret;
915 break;
916 }
917 continue;
918 }
919 if ( ('[' == line[0]) &&
920 (']' == line[line_size - 1]) )
921 {
922 /* [value] */
923 line[line_size - 1] = '\0';
924 value = &line[1];
925 GNUNET_free (section);
926 section = GNUNET_strdup (value);
927 continue;
928 }
929 if (NULL != (eq = strchr (line, '=')))
930 {
931
932 if (NULL == section)
933 {
935 "Syntax error while deserializing in line %u (option without section)\n",
936 nr);
938 break;
939 }
940
941 /* tag = value */
942 tag = GNUNET_strndup (line, eq - line);
943 /* remove tailing whitespace */
944 for (int i = strlen (tag) - 1;
945 (i >= 1) && (isspace ((unsigned char) tag[i]));
946 i--)
947 tag[i] = '\0';
948
949 /* Strip whitespace */
950 value = eq + 1;
951 while (isspace ((unsigned char) value[0]))
952 value++;
953 for (int i = strlen (value) - 1;
954 (i >= 1) && (isspace ((unsigned char) value[i]));
955 i--)
956 value[i] = '\0';
957
958 /* remove quotes */
959 if ( ('"' == value[0]) &&
960 ('"' == value[strlen (value) - 1]) )
961 {
962 value[strlen (value) - 1] = '\0';
963 value++;
964 }
966 section,
967 tag,
968 value);
969 if (cfg->diagnostics)
970 {
972 section,
973 tag,
974 source_filename
975 ? source_filename
976 : "<input>",
977 nr);
978 }
979 GNUNET_free (tag);
980 continue;
981 }
982 /* parse error */
984 "Syntax error while deserializing in line %u\n",
985 nr);
987 break;
988 }
989 GNUNET_free (line_orig);
990 GNUNET_free (section);
991 GNUNET_assert ( (GNUNET_OK != ret) ||
992 (r_bytes == size) );
993 return ret;
994}
static enum GNUNET_GenericReturnValue handle_inline(struct GNUNET_CONFIGURATION_Handle *cfg, const char *path_or_glob, bool path_is_glob, const char *restrict_section, const char *source_filename, unsigned int source_lineno)
Handle an inline directive.
static void set_entry_hint(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *hint_filename, unsigned int hint_line)
Set a configuration hint.
static int end
Set if we are to shutdown all services (including ARM).
Definition gnunet-arm.c:33
static char * line
Desired phone line (string to be converted to a hash).
static char * value
Value of the record to add/remove.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
bool diagnostics
Enable diagnostics.
const char * restrict_section
When parsing into this configuration, and this value is non-NULL, only parse sections of the same nam...

References cfg, GNUNET_CONFIGURATION_Handle::diagnostics, end, GNUNET_assert, GNUNET_CONFIGURATION_set_value_string(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_NO, GNUNET_OK, GNUNET_strdup, GNUNET_strndup, GNUNET_SYSERR, GNUNET_YES, handle_inline(), line, LOG, GNUNET_CONFIGURATION_Handle::restrict_section, ret, set_entry_hint(), size, and value.

Referenced by GNUNET_CONFIGURATION_parse(), GNUNET_TESTING_get_topo_from_string_(), handle_auto_result(), handle_autoconfig_request(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_write()

enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write ( struct GNUNET_CONFIGURATION_Handle cfg,
const char *  filename 
)

Write configuration file.

Parameters
cfgconfiguration to write
filenamewhere to write the configuration
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 1451 of file configuration.c.

1454{
1455 char *fn;
1456 char *cfg_buf;
1457 size_t size;
1458
1460 if (fn == NULL)
1461 return GNUNET_SYSERR;
1463 {
1464 GNUNET_free (fn);
1465 return GNUNET_SYSERR;
1466 }
1468 &size);
1469 {
1470 struct GNUNET_DISK_FileHandle *h;
1471
1480 if (NULL == h)
1481 {
1482 GNUNET_free (fn);
1483 GNUNET_free (cfg_buf);
1484 return GNUNET_SYSERR;
1485 }
1486 if (((ssize_t) size) !=
1488 cfg_buf,
1489 size))
1490 {
1492 "write",
1493 fn);
1495 (void) GNUNET_DISK_directory_remove (fn);
1496 GNUNET_free (fn);
1497 GNUNET_free (cfg_buf);
1498 cfg->dirty = GNUNET_SYSERR; /* last write failed */
1499 return GNUNET_SYSERR;
1500 }
1503 }
1504 GNUNET_free (fn);
1505 GNUNET_free (cfg_buf);
1506 cfg->dirty = GNUNET_NO; /* last write succeeded */
1507 return GNUNET_OK;
1508}
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition gnunet-arm.c:98
char * GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
Serializes the given configuration.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition disk.c:1308
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition disk.c:745
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition disk.c:1140
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition disk.c:1386
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition disk.c:664
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_OPEN_TRUNCATE
Truncate file if it exists.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_GROUP_READ
Group can read.
@ GNUNET_DISK_PERM_GROUP_WRITE
Group can write.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
Handle used to access files (and pipes).

References cfg, GNUNET_CONFIGURATION_Handle::dirty, filename, GNUNET_assert, GNUNET_CONFIGURATION_serialize(), GNUNET_DISK_directory_create_for_file(), GNUNET_DISK_directory_remove(), GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_write(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_TRUNCATE, GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_GROUP_READ, GNUNET_DISK_PERM_GROUP_WRITE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log_strerror_file, GNUNET_NO, GNUNET_OK, GNUNET_STRINGS_filename_expand(), GNUNET_SYSERR, h, and size.

Referenced by create_unique_cfgs(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_write_diffs(), handle_delete_message(), handle_rename_message(), save_member(), save_member_session(), save_operation(), set_cont(), and start_peer_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_write_diffs()

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.

Parameters
cfg_defaultdefault configuration
cfg_newnew configuration
filenamewhere to write the configuration diff between default and new
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 1713 of file configuration.c.

1717{
1718 int ret;
1719 struct GNUNET_CONFIGURATION_Handle *diff;
1720
1721 diff = GNUNET_CONFIGURATION_get_diff (cfg_default, cfg_new);
1724 return ret;
1725}
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
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_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.

References filename, GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_get_diff(), GNUNET_CONFIGURATION_write(), and ret.

Referenced by auto_config_cb(), GNUNET_CONFIGURATION_config_tool_run(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_diff()

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.

Parameters
cfg_defaultoriginal configuration
cfg_newnew configuration
Returns
configuration with only the differences, never NULL

Definition at line 1696 of file configuration.c.

1699{
1700 struct DiffHandle diffHandle;
1701
1702 GNUNET_break (cfg_default->pd == cfg_new->pd);
1703 diffHandle.cfgDiff = GNUNET_CONFIGURATION_create (cfg_new->pd);
1704 diffHandle.cfg_default = cfg_default;
1707 &diffHandle);
1708 return diffHandle.cfgDiff;
1709}
static void compare_entries(void *cls, const char *section, const char *option, const char *value)
A callback function, compares entries from two configurations (default against a new configuration) a...
Used for diffing a configuration object against the default one.
const struct GNUNET_CONFIGURATION_Handle * cfg_default

References DiffHandle::cfg_default, DiffHandle::cfgDiff, compare_entries(), GNUNET_break, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_iterate(), and GNUNET_CONFIGURATION_Handle::pd.

Referenced by conclude_autoconfig_request(), GNUNET_CONFIGURATION_write_diffs(), and next_phase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_is_dirty()

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.

Parameters
cfgconfiguration to inspect
Returns
GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error (i.e. last save failed)

Definition at line 1123 of file configuration.c.

1124{
1125 return cfg->dirty;
1126}

References cfg, and GNUNET_CONFIGURATION_Handle::dirty.

Referenced by auto_config_cb().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_parse_and_run()

enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse_and_run ( const struct GNUNET_OS_ProjectData pd,
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.

Then free the configuration object and return the status value from cb.

Parameters
pdproject data to use to determine paths
filenameconfiguration to parse, NULL for "default"
cbfunction to run
cb_clsclosure for cb
Returns
GNUNET_SYSERR if parsing the configuration failed, otherwise return value from cb.

Definition at line 343 of file configuration.c.

347{
350
352 if (GNUNET_OK !=
354 filename))
355 {
356 GNUNET_break (0);
358 return GNUNET_SYSERR;
359 }
360 ret = cb (cb_cls,
361 cfg);
363 return ret;
364}
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.

References cfg, filename, GNUNET_break, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_load(), GNUNET_OK, GNUNET_SYSERR, GNUNET_CONFIGURATION_Handle::pd, and ret.

Referenced by GNUNET_DISK_purge_cfg_dir().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_enable_diagnostics()

void GNUNET_CONFIGURATION_enable_diagnostics ( struct GNUNET_CONFIGURATION_Handle cfg)

Enable extra diagnostics.

Will produce more log output and allocate more memory.

Parameters
cfgconfiguration handle

Definition at line 219 of file configuration.c.

221{
222 cfg->diagnostics = true;
223}

References cfg, and GNUNET_CONFIGURATION_Handle::diagnostics.

Referenced by GNUNET_CONFIGURATION_config_tool_run().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_project_data()

const struct GNUNET_OS_ProjectData * GNUNET_CONFIGURATION_get_project_data ( const struct GNUNET_CONFIGURATION_Handle cfg)

Return the project data associated with this configuration.

Parameters
cfga configuration
Returns
associated project data, never NULL

Definition at line 3015 of file configuration.c.

3017{
3018 return cfg->pd;
3019}

References cfg, and GNUNET_CONFIGURATION_Handle::pd.

Referenced by GNUNET_BLOCK_context_create(), and GNUNET_DATACACHE_create().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_iterate()

void GNUNET_CONFIGURATION_iterate ( const struct GNUNET_CONFIGURATION_Handle cfg,
GNUNET_CONFIGURATION_Iterator  iter,
void *  iter_cls 
)

Iterate over all options in the configuration.

Parameters
cfgconfiguration to inspect
iterfunction to call on each option
iter_clsclosure for iter

Definition at line 1512 of file configuration.c.

1516{
1517 for (struct ConfigSection *spos = cfg->sections;
1518 NULL != spos;
1519 spos = spos->next)
1520 for (struct ConfigEntry *epos = spos->entries;
1521 NULL != epos;
1522 epos = epos->next)
1523 if (NULL != epos->val)
1524 iter (iter_cls,
1525 spos->name,
1526 epos->key,
1527 epos->val);
1528}

References cfg, and GNUNET_CONFIGURATION_Handle::sections.

Referenced by get_cont(), GNUNET_CONFIGURATION_dup(), GNUNET_CONFIGURATION_get_diff(), and GNUNET_TESTBED_configuration_create().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_iterate_sections()

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.

Parameters
cfgconfiguration to inspect
iterfunction to call on each section
iter_clsclosure for iter

Definition at line 1565 of file configuration.c.

1569{
1570 struct ConfigSection *spos;
1571 struct ConfigSection *next;
1572
1573 next = cfg->sections;
1574 while (NULL != next)
1575 {
1576 spos = next;
1577 next = spos->next;
1578 if (spos->inaccessible && (NULL == spos->entries))
1579 continue;
1580 iter (iter_cls,
1581 spos->name);
1582 }
1583}
struct ConfigEntry * entries
entries in the section
bool inaccessible
Is the configuration section marked as inaccessible?
struct ConfigSection * next
This is a linked list.

References cfg, ConfigSection::entries, ConfigSection::inaccessible, ConfigSection::name, ConfigSection::next, and GNUNET_CONFIGURATION_Handle::sections.

Referenced by GNUNET_CONFIGURATION_config_tool_run(), GNUNET_TESTBED_configuration_create(), handle_delete_message(), handle_rename_message(), pid_change_cb(), run(), and run().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_remove_section()

void GNUNET_CONFIGURATION_remove_section ( struct GNUNET_CONFIGURATION_Handle cfg,
const char *  section 
)

Remove the given section and all options in it.

Parameters
cfgconfiguration to inspect
sectionname of the section to remove

Definition at line 1587 of file configuration.c.

1589{
1590 struct ConfigSection *spos;
1591 struct ConfigSection *prev;
1592 struct ConfigEntry *ent;
1593
1594 prev = NULL;
1595 spos = cfg->sections;
1596 while (NULL != spos)
1597 {
1598 if (0 == strcasecmp (section,
1599 spos->name))
1600 {
1601 if (NULL == prev)
1602 cfg->sections = spos->next;
1603 else
1604 prev->next = spos->next;
1605 while (NULL != (ent = spos->entries))
1606 {
1607 spos->entries = ent->next;
1608 GNUNET_free (ent->key);
1609 GNUNET_free (ent->val);
1611 GNUNET_free (ent);
1612 cfg->dirty = GNUNET_YES;
1613 }
1614 GNUNET_free (spos->name);
1618 GNUNET_free (spos);
1619 return;
1620 }
1621 prev = spos;
1622 spos = spos->next;
1623 }
1624}
char * hint_filename
Diagnostics information for the filename.
struct ConfigEntry * next
This is a linked list.
char * key
key for this entry
char * val
current, committed value
char * hint_inlined_from_filename
For secret sections: Where was this inlined from?
char * hint_secret_filename
Diagnostics hint for the secret file.
char * hint_secret_stat
Extra information regarding permissions of the secret file.

References cfg, GNUNET_CONFIGURATION_Handle::dirty, ConfigSection::entries, GNUNET_free, GNUNET_YES, ConfigEntry::hint_filename, ConfigSection::hint_inlined_from_filename, ConfigSection::hint_secret_filename, ConfigSection::hint_secret_stat, ConfigEntry::key, ConfigSection::name, ConfigEntry::next, ConfigSection::next, GNUNET_CONFIGURATION_Handle::sections, and ConfigEntry::val.

Referenced by GNUNET_CONFIGURATION_destroy().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_value_number()

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.

Parameters
cfgconfiguration to inspect
sectionsection of interest
optionoption of interest
numberwhere to store the numeric value of the option
Returns
GNUNET_OK on success, GNUNET_NO if option is not set GNUNET_SYSERR on error (value is malformed)

Definition at line 1791 of file configuration.c.

1796{
1797 struct ConfigEntry *e;
1798 char dummy[2];
1799
1800 if (NULL == (e = find_entry (cfg,
1801 section,
1802 option)))
1803 return GNUNET_NO;
1804 if (NULL == e->val)
1805 return GNUNET_NO;
1806 if (1 != sscanf (e->val,
1807 "%llu%1s",
1808 number,
1809 dummy))
1810 return GNUNET_SYSERR;
1811 return GNUNET_OK;
1812}
static struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
uint32_t number

References cfg, dummy, find_entry(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, number, and ConfigEntry::val.

Referenced by create_service(), create_subnets(), DHTU_ip_init(), GCD_init(), GCO_init(), GDS_NEIGHBOURS_init(), get_server_addresses(), get_server_addresses(), GNUNET_CLIENT_connect(), GNUNET_CLIENT_test(), GNUNET_HOSTLIST_server_start(), GNUNET_NAT_AUTO_test_start(), GNUNET_PROGRAM_run2(), GNUNET_REVOCATION_revoke(), GNUNET_SERVICE_run_(), GNUNET_SOCKS_do_connect(), GNUNET_TESTING_get_topo_from_string_(), GNUNET_TRANSPORT_communicator_connect(), GSF_cadet_start_server(), GSF_pending_request_init_(), libgnunet_plugin_block_revocation_init(), libgnunet_plugin_datastore_heap_init(), load_member_session(), load_operation(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), setup_exit_helper_args(), test_service_configuration(), test_stun(), and update_config().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_set_value_float()

void GNUNET_CONFIGURATION_set_value_float ( struct GNUNET_CONFIGURATION_Handle cfg,
const char *  section,
const char *  option,
float  number 
)

Set a configuration value that should be a float.

Note that this possibly truncates your float value.

Parameters
cfgconfiguration to update
sectionsection of interest
optionoption of interest
numbervalue to set

Definition at line 1816 of file configuration.c.

1820{
1821 char s[64];
1822
1823 /* See: #9369 */
1824 const locale_t cl = newlocale (LC_NUMERIC_MASK,
1825 "C",
1826 (locale_t) 0);
1827 locale_t old_locale = uselocale (cl);
1828 GNUNET_snprintf (s,
1829 64,
1830 "%f",
1831 (double) number);
1832 uselocale (old_locale);
1834 section,
1835 option,
1836 s);
1837}
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.

References cfg, GNUNET_CONFIGURATION_set_value_string(), GNUNET_snprintf(), and number.

Here is the call graph for this function:

◆ GNUNET_CONFIGURATION_get_value_float()

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.

Parameters
cfgconfiguration to inspect
sectionsection of interest
optionoption of interest
numberwhere to store the floating value of the option
Returns
GNUNET_OK on success, GNUNET_NO if option is not set GNUNET_SYSERR on error (value is malformed)

Definition at line 1841 of file configuration.c.

1846{
1847 struct ConfigEntry *e;
1848 char dummy[2];
1849
1850 if (NULL == (e = find_entry (cfg,
1851 section,
1852 option)))
1853 return GNUNET_NO;
1854 if (NULL == e->val)
1855 return GNUNET_NO;
1856 /* See #9369 */
1857 {
1858 const locale_t cl = newlocale (LC_NUMERIC_MASK,
1859 "C",
1860 (locale_t) 0);
1861 locale_t old_locale = uselocale (cl);
1862
1863 if (1 != sscanf (e->val,
1864 "%f%1s",
1865 number,
1866 dummy))
1867 return GNUNET_SYSERR;
1868 uselocale (old_locale);
1869 }
1870 return GNUNET_OK;
1871}

References cfg, dummy, find_entry(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, number, and ConfigEntry::val.

Referenced by GNUNET_RPS_connect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_value_time()

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.

Parameters
cfgconfiguration to inspect
sectionsection of interest
optionoption of interest
timeset to the time value stored in the configuration
Returns
GNUNET_OK on success, GNUNET_NO if option is not set GNUNET_SYSERR on error (value is malformed)

Definition at line 1875 of file configuration.c.

1880{
1881 struct ConfigEntry *e;
1882 int ret;
1883
1884 if (NULL == (e = find_entry (cfg,
1885 section,
1886 option)))
1887 return GNUNET_NO;
1888 if (NULL == e->val)
1889 return GNUNET_NO;
1891 time);
1892 if (GNUNET_OK != ret)
1894 section,
1895 option,
1896 _ ("Not a valid relative time specification"));
1897 return ret;
1898}
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_time_to_relative(const char *fancy_time, struct GNUNET_TIME_Relative *rtime)
Convert a given fancy human-readable time to our internal representation.
Definition strings.c:259

References _, cfg, find_entry(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log_config_invalid(), GNUNET_NO, GNUNET_OK, GNUNET_STRINGS_fancy_time_to_relative(), ret, and ConfigEntry::val.

Referenced by GCD_init(), GNUNET_REVOCATION_revoke(), GNUNET_SPEEDUP_start_(), GSF_push_init_(), libgnunet_plugin_block_revocation_init(), RECLAIM_TICKETS_init(), REST_openid_init(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), and token_endpoint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_value_size()

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.

Parameters
cfgconfiguration to inspect
sectionsection of interest
optionoption of interest
sizeset to the size in bytes as stored in the configuration
Returns
GNUNET_OK on success, GNUNET_NO if option is not set GNUNET_SYSERR on error (value is malformed)

Definition at line 1902 of file configuration.c.

1907{
1908 struct ConfigEntry *e;
1909
1910 if (NULL == (e = find_entry (cfg,
1911 section,
1912 option)))
1913 return GNUNET_NO;
1914 if (NULL == e->val)
1915 return GNUNET_NO;
1917 size);
1918}
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_size_to_bytes(const char *fancy_size, unsigned long long *size)
Convert a given fancy human-readable size to bytes.
Definition strings.c:235

References cfg, find_entry(), GNUNET_NO, GNUNET_STRINGS_fancy_size_to_bytes(), size, and ConfigEntry::val.

Referenced by GNUNET_DATACACHE_create(), run(), run(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_have_value()

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.

Parameters
cfgconfiguration to inspect
sectionsection of interest
optionoption of interest
Returns
GNUNET_YES if so, GNUNET_NO if not.

Definition at line 2025 of file configuration.c.

2028{
2029 struct ConfigEntry *e;
2030
2031 if ( (NULL == (e = find_entry (cfg,
2032 section,
2033 option))) ||
2034 (NULL == e->val) )
2035 return GNUNET_NO;
2036 return GNUNET_YES;
2037}

References cfg, find_entry(), GNUNET_NO, GNUNET_YES, and ConfigEntry::val.

Referenced by check_config(), get_server_addresses(), GNUNET_CLIENT_connect(), GNUNET_CLIENT_test(), GNUNET_CONFIGURATION_load(), GNUNET_HOSTLIST_server_start(), GNUNET_PROGRAM_run2(), GNUNET_SOCKS_check_service(), process_acl4(), process_acl6(), run(), setup_service(), start_arm_service(), test_service_configuration(), and update_config_sections().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_value_string()

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.

Parameters
cfgconfiguration to inspect
sectionsection of interest
optionoption of interest
valuewill be set to a freshly allocated configuration value, or NULL if option is not specified
Returns
GNUNET_OK on success, GNUNET_NO if option is not set GNUNET_SYSERR on error (value is malformed)
Parameters
cfgconfiguration to inspect
sectionsection of interest
optionoption of interest
valuewill be set to a freshly allocated configuration value, or NULL if option is not specified
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 1932 of file configuration.c.

1937{
1938 struct ConfigEntry *e;
1939
1940 if ( (NULL == (e = find_entry (cfg,
1941 section,
1942 option))) ||
1943 (NULL == e->val) )
1944 {
1945 *value = NULL;
1946 return GNUNET_NO;
1947 }
1948 *value = GNUNET_strdup (e->val);
1949 return GNUNET_OK;
1950}

References cfg, find_entry(), GNUNET_NO, GNUNET_OK, GNUNET_strdup, ConfigEntry::val, and value.

Referenced by advertise_dns_exit(), check_authorization(), check_config(), client_connect_cb(), communicator_start(), DHTU_ip_init(), expand_dollar(), get_bootstrap_server(), get_server_addresses(), get_server_addresses(), gg_load_configuration(), GNUNET_CLIENT_connect(), GNUNET_CLIENT_test(), GNUNET_CONFIGURATION_append_value_filename(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_get_data(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_iterate_value_filenames(), GNUNET_CONFIGURATION_remove_value_filename(), GNUNET_CONVERSATION_phone_create(), GNUNET_DATACACHE_create(), GNUNET_FS_unindex_do_extract_keywords_(), GNUNET_GNS_lookup_with_tld(), GNUNET_HOSTLIST_client_start(), GNUNET_HOSTLIST_server_start(), GNUNET_OS_get_suid_binary_path(), GNUNET_PQ_connect_with_cfg2(), GNUNET_SOCKS_do_connect(), GNUNET_TESTING_get_topo_from_string_(), handle_ego_delete(), handle_ego_rename(), handle_register(), handle_uri(), identity_continuation(), load_member_session(), load_member_session_next(), login_redirect(), mq_init(), mq_init(), process_acl4(), process_acl6(), read_service_conf(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), setup_exit_helper_args(), setup_service(), sock_read(), sock_read(), start_arm_service(), start_peer_run(), start_process(), test_icmp_client(), test_icmp_server(), test_service_configuration(), token_endpoint(), and update_config_sections().

Here is the call graph for this function:

◆ GNUNET_CONFIGURATION_get_value_filename()

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.

Parameters
cfgconfiguration to inspect
sectionsection of interest
optionoption of interest
valuewill be set to a freshly allocated configuration value, or NULL if option is not specified
Returns
GNUNET_OK on success, GNUNET_NO if option is not set GNUNET_SYSERR on error (value is malformed)

Definition at line 2236 of file configuration.c.

2241{
2242 char *tmp;
2244
2246 section,
2247 option,
2248 &tmp);
2249 if (GNUNET_OK != ret)
2250 {
2252 "Failed to retrieve filename\n");
2253 *value = NULL;
2254 return ret;
2255 }
2257 tmp);
2259 GNUNET_free (tmp);
2260 if (*value == NULL)
2261 return GNUNET_SYSERR;
2262 return GNUNET_OK;
2263}
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.
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...

References cfg, GNUNET_CONFIGURATION_expand_dollar(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_OK, GNUNET_STRINGS_filename_expand(), GNUNET_SYSERR, LOG, ret, and value.

Referenced by create_service(), database_connect(), database_setup(), database_setup(), database_setup(), database_setup(), database_setup(), get_oidc_dir_path(), get_pid_file_name(), get_serialization_file_name(), get_serialization_file_name_in_dir(), get_server_addresses(), get_server_addresses(), get_update_information_directory(), get_user_name(), GNUNET_CLIENT_test(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CRYPTO_eddsa_key_create_from_configuration(), GNUNET_HOSTLIST_client_start(), GNUNET_PILS_create_key_ring(), GNUNET_PQ_connect_with_cfg2(), GNUNET_TIME_absolute_get_monotonic(), load(), load_hostlist_file(), load_ikm(), load_ikm(), new_sub(), print_filename_option(), purge_cfg_dir(), read_index_list(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), save(), save_hostlist_file(), setup_service(), start_arm_service(), start_peer_run(), test_service_configuration(), try_unixpath(), write_index_list(), and write_proof().

Here is the call graph for this function:

◆ GNUNET_CONFIGURATION_iterate_value_filenames()

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.

Parameters
cfgconfiguration to inspect
sectionsection of interest
optionoption of interest
cbfunction to call on each filename
cb_clsclosure for cb
Returns
number of filenames iterated over, -1 on error

Definition at line 2295 of file configuration.c.

2301{
2302 char *list;
2303 char *pos;
2304 char *end;
2305 char old;
2306 int ret;
2307
2308 if (GNUNET_OK !=
2310 section,
2311 option,
2312 &list))
2313 return 0;
2314 GNUNET_assert (list != NULL);
2315 ret = 0;
2316 pos = list;
2317 while (1)
2318 {
2319 while (pos[0] == ' ')
2320 pos++;
2321 if (strlen (pos) == 0)
2322 break;
2323 end = pos + 1;
2324 while ((end[0] != ' ') && (end[0] != '\0'))
2325 {
2326 if (end[0] == '\\')
2327 {
2328 switch (end[1])
2329 {
2330 case '\\':
2331 case ' ':
2332 memmove (end, &end[1], strlen (&end[1]) + 1);
2333
2334 case '\0':
2335 /* illegal, but just keep it */
2336 break;
2337
2338 default:
2339 /* illegal, but just ignore that there was a '/' */
2340 break;
2341 }
2342 }
2343 end++;
2344 }
2345 old = end[0];
2346 end[0] = '\0';
2347 if (strlen (pos) > 0)
2348 {
2349 ret++;
2350 if ( (NULL != cb) &&
2351 (GNUNET_OK != cb (cb_cls,
2352 pos)))
2353 {
2355 break;
2356 }
2357 }
2358 if (old == '\0')
2359 break;
2360 pos = end + 1;
2361 }
2362 GNUNET_free (list);
2363 return ret;
2364}
static int list
Set if we should print a list of currently running services.
Definition gnunet-arm.c:68

References cfg, end, GNUNET_assert, GNUNET_CONFIGURATION_get_value_string(), GNUNET_free, GNUNET_OK, GNUNET_SYSERR, list, and ret.

Referenced by GNUNET_CONFIGURATION_append_value_filename().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_iterate_section_values()

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.

Parameters
cfgconfiguration to inspect
sectionthe section
iterfunction to call on each option
iter_clsclosure for iter

Definition at line 1532 of file configuration.c.

1537{
1538 struct ConfigSection *spos;
1539
1540 spos = cfg->sections;
1541 while ((spos != NULL) && (0 != strcasecmp (spos->name, section)))
1542 spos = spos->next;
1543 if (NULL == spos)
1544 return;
1545 for (struct ConfigEntry *epos = spos->entries;
1546 NULL != epos;
1547 epos = epos->next)
1548 if (NULL != epos->val)
1549 iter (iter_cls,
1550 spos->name,
1551 epos->key,
1552 epos->val);
1553 if (spos->inaccessible)
1554 {
1556 "Section '%s' is marked as inaccessible, because a configuration "
1557 "file that contains the section can't be read.\n",
1558 section);
1559 return;
1560 }
1561}

References cfg, ConfigSection::entries, GNUNET_ERROR_TYPE_WARNING, ConfigSection::inaccessible, LOG, ConfigSection::name, ConfigSection::next, and GNUNET_CONFIGURATION_Handle::sections.

Referenced by authorize_endpoint(), auto_config_cb(), get_cont(), GNUNET_CONFIGURATION_config_tool_run(), and run().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_value_choice()

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.

Parameters
cfgconfiguration to inspect
sectionsection of interest
optionoption of interest
choicesNULL-terminated list of legal values
valuewill be set to an entry in the legal list, or NULL if option is not specified and no default given
Returns
GNUNET_OK on success, GNUNET_NO if option is not set GNUNET_SYSERR on error (value not in choices)

Definition at line 1954 of file configuration.c.

1960{
1961 struct ConfigEntry *e;
1962 unsigned int i;
1963
1964 if (NULL == (e = find_entry (cfg,
1965 section,
1966 option)))
1967 return GNUNET_NO;
1968 for (i = 0; NULL != choices[i]; i++)
1969 if (0 == strcasecmp (choices[i], e->val))
1970 break;
1971 if (NULL == choices[i])
1972 {
1974 _ ("Configuration value '%s' for '%s'"
1975 " in section '%s' is not in set of legal choices\n"),
1976 e->val,
1977 option,
1978 section);
1979 return GNUNET_SYSERR;
1980 }
1981 *value = choices[i];
1982 return GNUNET_OK;
1983}

References _, cfg, find_entry(), GNUNET_ERROR_TYPE_ERROR, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, LOG, ConfigEntry::val, and value.

Referenced by GNUNET_CONFIGURATION_get_value_yesno(), run(), and start_process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_value_yesno()

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".

Parameters
cfgconfiguration to inspect
sectionsection of interest
optionoption of interest
Returns
GNUNET_OK if option is set to "YES" GNUNET_NO if option is not set or "NO" GNUNET_SYSERR on error (neither YES nor NO)

Definition at line 2267 of file configuration.c.

2271{
2272 static const char *yesno[] = {
2273 "YES",
2274 "NO",
2275 NULL
2276 };
2277 const char *val;
2279
2280 ret =
2282 section,
2283 option,
2284 yesno,
2285 &val);
2286 if (GNUNET_OK != ret)
2287 return ret;
2288 if (val == yesno[0])
2289 return GNUNET_YES;
2290 return GNUNET_NO;
2291}
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.

References cfg, GNUNET_CONFIGURATION_get_value_choice(), GNUNET_NO, GNUNET_OK, GNUNET_YES, ret, and ConfigEntry::val.

Referenced by advertise_dns_exit(), create_handle(), create_listen_socket(), create_service(), database_connect(), database_connect(), GDS_NEIGHBOURS_init(), get_server_addresses(), get_server_addresses(), gg_load_configuration(), GNS_resolver_init(), GNUNET_DATACACHE_create(), GNUNET_STATISTICS_create(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(), GSF_pending_request_init_(), GSF_push_init_(), libgnunet_plugin_datacache_sqlite_init(), load_underlay(), main_init(), parse_ip_options(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), setup_service(), setup_service(), start_arm_service(), start_process(), test_icmp_client(), test_icmp_server(), test_master(), udp_address_to_sockaddr(), and update_config().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_data()

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.

Parameters
cfgconfiguration to access
sectionsection to access
optionoption to access
bufwhere to store the decoded binary result
buf_sizeexact number of bytes to store in buf
Returns
GNUNET_OK on success GNUNET_NO is the value does not exist GNUNET_SYSERR on decoding error

Definition at line 1987 of file configuration.c.

1992{
1993 char *enc;
1994 int res;
1995 size_t data_size;
1996
1997 if (GNUNET_OK !=
1998 (res =
2000 section,
2001 option,
2002 &enc)))
2003 return res;
2004 data_size = (strlen (enc) * 5) / 8;
2005 if (data_size != buf_size)
2006 {
2007 GNUNET_free (enc);
2008 return GNUNET_SYSERR;
2009 }
2010 if (GNUNET_OK !=
2012 strlen (enc),
2013 buf,
2014 buf_size))
2015 {
2016 GNUNET_free (enc);
2017 return GNUNET_SYSERR;
2018 }
2019 GNUNET_free (enc);
2020 return GNUNET_OK;
2021}
static OpusEncoder * enc
OPUS encoder.
static char * res
Currently read line or NULL on EOF.
static size_t data_size
Number of bytes in data.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition strings.c:837

References cfg, data_size, enc, GNUNET_CONFIGURATION_get_value_string(), GNUNET_free, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, and res.

Referenced by load_member(), load_member_session_next(), and load_operation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_expand_dollar()

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 the environment "FOO" is set to "DIRECTORY".

We also support default expansion, i.e. ${VARIABLE:-default} will expand to $VARIABLE if VARIABLE is set in PATHS or the environment, and otherwise to "default". Note that "default" itself can also be a $-expression, thus "${VAR1:-{$VAR2}}" will expand to VAR1 and if that is not defined to VAR2.

Parameters
cfgconfiguration to use for path expansion
origstring to $-expand (will be freed!) Note that multiple $-expressions can be present in this string. They will all be $-expanded.
Returns
$-expanded string

Definition at line 2211 of file configuration.c.

2214{
2215 char *dup;
2216 size_t i;
2217 size_t len;
2218
2219 for (i = 0; '\0' != orig[i]; i++)
2220 {
2221 if ('$' != orig[i])
2222 continue;
2223 dup = GNUNET_strdup (orig + i);
2224 dup = expand_dollar (cfg, dup, 0);
2225 GNUNET_assert (NULL != dup); /* make compiler happy */
2226 len = strlen (dup) + 1;
2227 orig = GNUNET_realloc (orig, i + len);
2228 GNUNET_memcpy (orig + i, dup, len);
2229 GNUNET_free (dup);
2230 }
2231 return orig;
2232}
static char * expand_dollar(const struct GNUNET_CONFIGURATION_Handle *cfg, char *orig, unsigned int depth)
Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" where either in the "PATHS" section or...
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.

References cfg, expand_dollar(), GNUNET_assert, GNUNET_free, GNUNET_memcpy, GNUNET_realloc, and GNUNET_strdup.

Referenced by expand_dollar(), GNUNET_CONFIGURATION_get_value_filename(), run(), start_arm_service(), and start_process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_set_value_number()

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.

Parameters
cfgconfiguration to update
sectionsection of interest
optionoption of interest
numbervalue to set

Definition at line 1772 of file configuration.c.

1776{
1777 char s[64];
1778
1779 GNUNET_snprintf (s,
1780 64,
1781 "%llu",
1782 number);
1784 section,
1785 option,
1786 s);
1787}

References cfg, GNUNET_CONFIGURATION_set_value_string(), GNUNET_snprintf(), and number.

Referenced by next_phase(), run(), run(), save_member_session(), save_operation(), and set_value().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_set_value_string()

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.

Parameters
cfgconfiguration to update
sectionsection of interest
optionoption of interest
valuevalue to set

Definition at line 1729 of file configuration.c.

1734{
1735 struct ConfigSection *sec;
1736 struct ConfigEntry *e;
1737 char *nv;
1738
1739 e = find_entry (cfg, section, option);
1740 if (NULL != e)
1741 {
1742 if (NULL == value)
1743 {
1744 GNUNET_free (e->val);
1745 e->val = NULL;
1746 }
1747 else
1748 {
1749 nv = GNUNET_strdup (value);
1750 GNUNET_free (e->val);
1751 e->val = nv;
1752 }
1753 return;
1754 }
1755 sec = find_section (cfg, section);
1756 if (sec == NULL)
1757 {
1758 sec = GNUNET_new (struct ConfigSection);
1759 sec->name = GNUNET_strdup (section);
1760 sec->next = cfg->sections;
1761 cfg->sections = sec;
1762 }
1763 e = GNUNET_new (struct ConfigEntry);
1764 e->key = GNUNET_strdup (option);
1765 e->val = GNUNET_strdup (value);
1766 e->next = sec->entries;
1767 sec->entries = e;
1768}
static struct ConfigSection * find_section(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Find a section entry from a configuration.

References cfg, ConfigSection::entries, find_entry(), find_section(), GNUNET_free, GNUNET_new, GNUNET_strdup, ConfigEntry::key, ConfigSection::name, ConfigEntry::next, ConfigSection::next, GNUNET_CONFIGURATION_Handle::sections, ConfigEntry::val, and value.

Referenced by auto_conf_iter(), auto_config_cb(), compare_entries(), copy_entry(), GNUNET_CONFIGURATION_append_value_filename(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_deserialize(), GNUNET_CONFIGURATION_load(), GNUNET_CONFIGURATION_remove_value_filename(), GNUNET_CONFIGURATION_set_value_float(), GNUNET_CONFIGURATION_set_value_number(), GNUNET_NAT_autoconfig_start(), GNUNET_PROGRAM_run2(), GNUNET_TESTBED_configuration_create(), handle_ego_delete(), handle_ego_rename(), handle_inline(), identity_cb(), next_phase(), process_if(), result_callback(), run(), run(), save_member(), save_member_session(), save_operation(), set_external_ipv4(), set_value(), start_peer_run(), test_local_ip(), test_upnpc(), update_config(), update_config_sections(), and update_enable_upnpc_option().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_remove_value_filename()

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.

Parameters
cfgconfiguration to update
sectionsection of interest
optionoption of interest
valuefilename to remove
Returns
GNUNET_OK on success, GNUNET_SYSERR if the filename is not in the list

Definition at line 2463 of file configuration.c.

2468{
2469 char *list;
2470 char *pos;
2471 char *end;
2472 char *match;
2473 char old;
2474
2475 if (GNUNET_OK !=
2477 section,
2478 option,
2479 &list))
2480 return GNUNET_NO;
2481 match = escape_name (value);
2482 pos = list;
2483 while (1)
2484 {
2485 while (pos[0] == ' ')
2486 pos++;
2487 if (strlen (pos) == 0)
2488 break;
2489 end = pos + 1;
2490 while ((end[0] != ' ') && (end[0] != '\0'))
2491 {
2492 if (end[0] == '\\')
2493 {
2494 switch (end[1])
2495 {
2496 case '\\':
2497 case ' ':
2498 end++;
2499 break;
2500
2501 case '\0':
2502 /* illegal, but just keep it */
2503 break;
2504
2505 default:
2506 /* illegal, but just ignore that there was a '/' */
2507 break;
2508 }
2509 }
2510 end++;
2511 }
2512 old = end[0];
2513 end[0] = '\0';
2514 if (0 == strcmp (pos, match))
2515 {
2516 if (old != '\0')
2517 memmove (pos,
2518 &end[1],
2519 strlen (&end[1]) + 1);
2520 else
2521 {
2522 if (pos != list)
2523 pos[-1] = '\0';
2524 else
2525 pos[0] = '\0';
2526 }
2528 section,
2529 option,
2530 list);
2531 GNUNET_free (list);
2532 GNUNET_free (match);
2533 return GNUNET_OK;
2534 }
2535 if (old == '\0')
2536 break;
2537 end[0] = old;
2538 pos = end + 1;
2539 }
2540 GNUNET_free (list);
2541 GNUNET_free (match);
2542 return GNUNET_NO;
2543}
static char * escape_name(const char *value)
FIXME.

References cfg, end, escape_name(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_free, GNUNET_NO, GNUNET_OK, list, and value.

Here is the call graph for this function:

◆ GNUNET_CONFIGURATION_append_value_filename()

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.

Parameters
cfgconfiguration to update
sectionsection of interest
optionoption of interest
valuefilename to append
Returns
GNUNET_OK on success, GNUNET_SYSERR if the filename already in the list

Definition at line 2425 of file configuration.c.

2430{
2431 char *escaped;
2432 char *old;
2433 char *nw;
2434
2435 if (GNUNET_SYSERR ==
2437 section,
2438 option,
2439 &test_match,
2440 (void *) value))
2441 return GNUNET_NO; /* already exists */
2442 if (GNUNET_OK !=
2443 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
2444 old = GNUNET_strdup ("");
2445 escaped = escape_name (value);
2446 nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2);
2447 strcpy (nw, old);
2448 if (strlen (old) > 0)
2449 strcat (nw, " ");
2450 strcat (nw, escaped);
2452 section,
2453 option,
2454 nw);
2455 GNUNET_free (old);
2456 GNUNET_free (nw);
2457 GNUNET_free (escaped);
2458 return GNUNET_OK;
2459}
static enum GNUNET_GenericReturnValue test_match(void *cls, const char *fn)
FIXME.
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.

References cfg, escape_name(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_iterate_value_filenames(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_free, GNUNET_malloc, GNUNET_NO, GNUNET_OK, GNUNET_strdup, GNUNET_SYSERR, test_match(), and value.

Here is the call graph for this function:

◆ GNUNET_CONFIGURATION_config_settings_free()

void GNUNET_CONFIGURATION_config_settings_free ( struct GNUNET_CONFIGURATION_ConfigSettings cs)

Free resources associated with cs.

Parameters
[in]cssettings to free (actual memory of cs itself is not released)

Definition at line 3005 of file configuration.c.

3007{
3008 GNUNET_free (cs->option);
3009 GNUNET_free (cs->section);
3010 GNUNET_free (cs->value);
3011}

References GNUNET_free, GNUNET_CONFIGURATION_ConfigSettings::option, GNUNET_CONFIGURATION_ConfigSettings::section, and GNUNET_CONFIGURATION_ConfigSettings::value.

Referenced by main().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_config_tool_run()

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 given in cls.

Parameters
clsclosure with the struct GNUNET_CONFIGURATION_ConfigSettings
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cfgconfiguration

Definition at line 2813 of file configuration.c.

2818{
2819 struct GNUNET_CONFIGURATION_ConfigSettings *cs = cls;
2820 struct GNUNET_CONFIGURATION_Handle *out = NULL;
2821 struct GNUNET_CONFIGURATION_Handle *ncfg = NULL;
2822
2823 (void) args;
2824 if (cs->diagnostics)
2825 {
2826 /* Re-parse the configuration with diagnostics enabled. */
2829 if (GNUNET_OK !=
2831 cfgfile))
2832 {
2833 fprintf (stderr,
2834 _ ("Failed to load config file `%s'"),
2835 cfgfile);
2836 return;
2837 }
2838 cfg = ncfg;
2839 }
2840
2841 if (cs->full)
2842 cs->rewrite = GNUNET_YES;
2843 if (cs->list_sections)
2844 {
2845 fprintf (stderr,
2846 _ ("The following sections are available:\n"));
2849 NULL);
2850 return;
2851 }
2852 if ( (! cs->rewrite) &&
2853 (NULL == cs->section) )
2854 {
2855 char *serialization;
2856
2857 if (! cs->diagnostics)
2858 {
2859 fprintf (stderr,
2860 _ ("%s, %s or %s argument is required\n"),
2861 "--section",
2862 "--list-sections",
2863 "--diagnostics");
2865 return;
2866 }
2868 fprintf (stdout,
2869 "%s",
2870 serialization);
2871 GNUNET_free (serialization);
2872 }
2873 else if ( (NULL != cs->section) &&
2874 (NULL == cs->value) )
2875 {
2876 if (NULL == cs->option)
2877 {
2879 cfg,
2880 cs->section,
2881 cs->is_filename
2883 : &print_option,
2884 (void *) cfg);
2885 }
2886 else
2887 {
2888 char *value;
2889
2890 if (cs->is_filename)
2891 {
2892 if (GNUNET_OK !=
2894 cs->section,
2895 cs->option,
2896 &value))
2897 {
2899 cs->section,
2900 cs->option);
2902 return;
2903 }
2904 }
2905 else
2906 {
2907 if (GNUNET_OK !=
2909 cs->section,
2910 cs->option,
2911 &value))
2912 {
2914 cs->section,
2915 cs->option);
2917 return;
2918 }
2919 }
2920 fprintf (stdout,
2921 "%s\n",
2922 value);
2924 }
2925 }
2926 else if (NULL != cs->section)
2927 {
2928 if (NULL == cs->option)
2929 {
2930 fprintf (stderr,
2931 _ ("--option argument required to set value\n"));
2933 return;
2934 }
2937 cs->section,
2938 cs->option,
2939 cs->value);
2940 cs->rewrite = GNUNET_YES;
2941 }
2942 if (cs->rewrite)
2943 {
2944 char *cfg_fn = NULL;
2945
2946 if (NULL == out)
2948
2949 if (NULL == cfgfile)
2950 {
2951 const char *xdg = getenv ("XDG_CONFIG_HOME");
2952
2953 if (NULL != xdg)
2954 GNUNET_asprintf (&cfg_fn,
2955 "%s%s%s",
2956 xdg,
2958 cfg->pd->config_file);
2959 else
2960 cfg_fn = GNUNET_strdup (cfg->pd->user_config_file);
2961 cfgfile = cfg_fn;
2962 }
2963
2964 if (! cs->full)
2965 {
2966 struct GNUNET_CONFIGURATION_Handle *def;
2967
2969 if (GNUNET_OK !=
2971 NULL))
2972 {
2973 fprintf (stderr,
2974 _ ("failed to load configuration defaults"));
2975 cs->global_ret = 1;
2978 GNUNET_free (cfg_fn);
2979 return;
2980 }
2981 if (GNUNET_OK !=
2983 out,
2984 cfgfile))
2985 cs->global_ret = 2;
2987 }
2988 else
2989 {
2990 if (GNUNET_OK !=
2992 cfgfile))
2993 cs->global_ret = 2;
2994 }
2995 GNUNET_free (cfg_fn);
2996 }
2997 if (NULL != out)
2999 if (NULL != ncfg)
3001}
static void print_filename_option(void *cls, const char *section, const char *option, const char *value)
Print each option in a given section as a filename.
static void print_section_name(void *cls, const char *section)
Print out given section name.
static void print_option(void *cls, const char *section, const char *option, const char *value)
Print each option in a given section.
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.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
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_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.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define EXIT_INVALIDARGUMENT
Definition platform.h:254
#define EXIT_NOTCONFIGURED
Definition platform.h:270
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.

References _, cfg, GNUNET_OS_ProjectData::config_file, GNUNET_CONFIGURATION_ConfigSettings::diagnostics, DIR_SEPARATOR_STR, EXIT_INVALIDARGUMENT, EXIT_NOTCONFIGURED, GNUNET_CONFIGURATION_ConfigSettings::full, getenv(), GNUNET_CONFIGURATION_ConfigSettings::global_ret, GNUNET_asprintf(), GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_dup(), GNUNET_CONFIGURATION_enable_diagnostics(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_iterate_section_values(), GNUNET_CONFIGURATION_iterate_sections(), GNUNET_CONFIGURATION_load(), GNUNET_CONFIGURATION_serialize_diagnostics(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_CONFIGURATION_write(), GNUNET_CONFIGURATION_write_diffs(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_config_missing(), GNUNET_OK, GNUNET_strdup, GNUNET_YES, GNUNET_CONFIGURATION_ConfigSettings::is_filename, GNUNET_CONFIGURATION_ConfigSettings::list_sections, GNUNET_CONFIGURATION_ConfigSettings::option, GNUNET_CONFIGURATION_Handle::pd, print_filename_option(), print_option(), print_section_name(), GNUNET_CONFIGURATION_ConfigSettings::rewrite, GNUNET_CONFIGURATION_ConfigSettings::section, GNUNET_OS_ProjectData::user_config_file, value, and GNUNET_CONFIGURATION_ConfigSettings::value.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function: