GNUnet 0.24.1-15-gab6ed22f1
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. More...
 

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. More...
 
typedef void(* GNUNET_CONFIGURATION_Iterator) (void *cls, const char *section, const char *option, const char *value)
 Function to iterate over options. More...
 
typedef void(* GNUNET_CONFIGURATION_SectionIterator) (void *cls, const char *section)
 Function to iterate over section. More...
 

Functions

struct GNUNET_CONFIGURATION_HandleGNUNET_CONFIGURATION_create (const struct GNUNET_OS_ProjectData *pd)
 Create a new configuration object. More...
 
struct GNUNET_CONFIGURATION_HandleGNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Duplicate an existing configuration object. More...
 
void GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
 Destroy configuration object. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
 Load configuration. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d)
 Load default configuration. More...
 
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. More...
 
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. More...
 
char * GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
 Serializes the given configuration. More...
 
char * GNUNET_CONFIGURATION_serialize_diagnostics (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Serializes the given configuration with diagnostics information. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *source_filename)
 De-serializes configuration. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
 Write configuration file. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
void GNUNET_CONFIGURATION_enable_diagnostics (struct GNUNET_CONFIGURATION_Handle *cfg)
 Enable extra diagnostics. More...
 
const struct GNUNET_OS_ProjectDataGNUNET_CONFIGURATION_get_project_data (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Return the project data associated with this configuration. More...
 
void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
 Iterate over all options in the configuration. More...
 
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. More...
 
void GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
 Remove the given section and all options in it. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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". More...
 
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. More...
 
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". More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
void GNUNET_CONFIGURATION_config_settings_free (struct GNUNET_CONFIGURATION_ConfigSettings *cs)
 Free resources associated with cs. More...
 
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. More...
 

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.

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

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_OS_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(), run(), save_member(), save_member_session(), save_operation(), 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 1641 of file configuration.c.

1643{
1645
1648 &copy_entry,
1649 ret);
1650 return ret;
1651}
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(), 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
Definition: configuration.c:71
char * name
name of the section
Definition: configuration.c:85
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(), 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 2635 of file configuration.c.

2638{
2639 char *baseconfig;
2640 const char *base_config_varname;
2641
2642 if (cfg->load_called)
2643 {
2644 /* FIXME: Make this a GNUNET_assert later */
2645 GNUNET_break (0);
2647 }
2648 cfg->load_called = true;
2649 if (NULL != filename)
2650 {
2653 }
2654
2655 base_config_varname = cfg->pd->base_config_varname;
2656
2657 if ((NULL != base_config_varname)
2658 && (NULL != (baseconfig = getenv (base_config_varname))))
2659 {
2660 baseconfig = GNUNET_strdup (baseconfig);
2661 }
2662 else
2663 {
2664 char *ipath;
2665
2668 if (NULL == ipath)
2669 {
2670 GNUNET_break (0);
2671 return GNUNET_SYSERR;
2672 }
2673 GNUNET_asprintf (&baseconfig,
2674 "%s%s",
2675 ipath,
2676 "config.d");
2677 GNUNET_free (ipath);
2678 }
2679
2680 {
2681 char *dname = GNUNET_STRINGS_filename_expand (baseconfig);
2682
2683 GNUNET_free (baseconfig);
2684
2685 if ((GNUNET_YES ==
2687 GNUNET_YES)) &&
2688 (GNUNET_SYSERR ==
2690 dname)))
2691 {
2693 "Failed to load base configuration from '%s'\n",
2694 filename);
2695 GNUNET_free (dname);
2696 return GNUNET_SYSERR; /* no configuration at all found */
2697 }
2698 GNUNET_free (dname);
2699 }
2700 if ((NULL != filename) &&
2701 (GNUNET_OK !=
2703 filename)))
2704 {
2705 /* specified configuration not found */
2707 "Failed to load configuration from file '%s'\n",
2708 filename);
2709 return GNUNET_SYSERR;
2710 }
2711 if (((GNUNET_YES !=
2713 "PATHS",
2714 "DEFAULTCONFIG"))) &&
2715 (filename != NULL))
2717 "PATHS",
2718 "DEFAULTCONFIG",
2719 filename);
2720 return GNUNET_OK;
2721}
#define LOG(kind,...)
Definition: configuration.c:30
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:444
@ 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:504
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(), 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 2536 of file configuration.c.

2539{
2540 struct CollectFilesContext files_context = {
2541 .files = NULL,
2542 .files_length = 0,
2543 };
2544 enum GNUNET_GenericReturnValue fun_ret;
2545
2546 if (GNUNET_SYSERR ==
2547 GNUNET_DISK_directory_scan (defaults_d,
2549 &files_context))
2550 return GNUNET_SYSERR; /* no configuration at all found */
2551 qsort (files_context.files,
2552 files_context.files_length,
2553 sizeof (char *),
2554 &pstrcmp);
2555 for (unsigned int i = 0; i < files_context.files_length; i++)
2556 {
2557 char *ext;
2558 const char *filename = files_context.files[i];
2559
2560 /* Examine file extension */
2561 ext = strrchr (filename, '.');
2562 if ( (NULL == ext) ||
2563 (0 != strcmp (ext,
2564 ".conf")) )
2565 {
2567 "Skipping file `%s'\n",
2568 filename);
2569 fun_ret = GNUNET_OK;
2570 continue;
2571 }
2573 filename);
2574 if (fun_ret != GNUNET_OK)
2575 break;
2576 }
2577cleanup:
2578 if (files_context.files_length > 0)
2579 {
2580 for (size_t i = 0; i < files_context.files_length; i++)
2581 GNUNET_free (files_context.files[i]);
2582 GNUNET_array_grow (files_context.files,
2583 files_context.files_length,
2584 0);
2585 }
2586 return fun_ret;
2587}
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.
static void cleanup(void *cls)
Disconnect and shutdown.
Definition: gnunet-did.c:131
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:829
#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, cleanup(), 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 2591 of file configuration.c.

2593{
2594 char *cfg_fn;
2595 const char *xdg = getenv ("XDG_CONFIG_HOME");
2596
2597 if (NULL != xdg)
2598 GNUNET_asprintf (&cfg_fn,
2599 "%s%s%s",
2600 xdg,
2602 pd->config_file);
2603 else
2604 cfg_fn = GNUNET_strdup (pd->user_config_file);
2605
2606 if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2607 return cfg_fn;
2608 GNUNET_free (cfg_fn);
2609
2610 /* Fall back to /etc/ for the default configuration.
2611 Should be okay to use forward slashes here. */
2612
2613 GNUNET_asprintf (&cfg_fn,
2614 "/etc/%s",
2615 pd->config_file);
2616 if (GNUNET_OK ==
2618 return cfg_fn;
2619 GNUNET_free (cfg_fn);
2620
2621 GNUNET_asprintf (&cfg_fn,
2622 "/etc/%s/%s",
2623 pd->project_dirname,
2624 pd->config_file);
2625 if (GNUNET_OK ==
2627 return cfg_fn;
2628
2629 GNUNET_free (cfg_fn);
2630 return NULL;
2631}
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:530
#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 995 of file configuration.c.

997{
998 uint64_t fs64;
999 size_t fs;
1000 char *fn;
1001 char *mem;
1002 int dirty;
1004 ssize_t sret;
1005
1008 "Asked to parse config file `%s'\n",
1009 fn);
1010 if (NULL == fn)
1011 return GNUNET_SYSERR;
1012
1013
1014 /* Check for cycles */
1015 {
1016 unsigned int lvl = cfg->current_nest_level;
1017 struct ConfigFile *cf = cfg->loaded_files_tail;
1018 struct ConfigFile *parent = NULL;
1019
1020
1021 for (; NULL != cf; parent = cf, cf = cf->prev)
1022 {
1023 /* Check parents based on level, skipping children of siblings. */
1024 if (cf->level >= lvl)
1025 continue;
1026 lvl = cf->level;
1027 if ( (NULL == cf->source_filename) ||
1028 (NULL == filename) )
1029 continue;
1030 if (0 == strcmp (cf->source_filename,
1031 filename))
1032 {
1033 if (NULL == parent)
1034 {
1036 "Forbidden direct cyclic configuration import (%s -> %s)\n",
1037 cf->source_filename,
1038 filename);
1039 }
1040 else
1042 "Forbidden indirect cyclic configuration import (%s -> ... -> %s -> %s)\n",
1043 cf->source_filename,
1044 parent->source_filename,
1045 filename);
1046 GNUNET_free (fn);
1047 return GNUNET_SYSERR;
1048 }
1049 }
1050
1051 }
1052
1053 /* Keep track of loaded files.*/
1054 {
1055 struct ConfigFile *cf = GNUNET_new (struct ConfigFile);
1056
1058 cf->source_filename = GNUNET_strdup (filename ? filename : "<input>");
1061 cf);
1062 }
1063
1064 dirty = cfg->dirty; /* back up value! */
1065 if (GNUNET_SYSERR ==
1067 &fs64,
1068 GNUNET_YES,
1069 GNUNET_YES))
1070 {
1072 "Error while determining the file size of `%s'\n",
1073 fn);
1074 GNUNET_free (fn);
1075 return GNUNET_SYSERR;
1076 }
1077 if (fs64 > SIZE_MAX)
1078 {
1079 GNUNET_break (0); /* File size is more than the heap size */
1080 GNUNET_free (fn);
1081 return GNUNET_SYSERR;
1082 }
1083 fs = fs64;
1084 mem = GNUNET_malloc (fs);
1085 sret = GNUNET_DISK_fn_read (fn,
1086 mem,
1087 fs);
1088 if ((sret < 0) || (fs != (size_t) sret))
1089 {
1091 "Error while reading file `%s'\n",
1092 fn);
1093 GNUNET_free (fn);
1094 GNUNET_free (mem);
1095 return GNUNET_SYSERR;
1096 }
1098 "Deserializing contents of file `%s'\n",
1099 fn);
1101 mem,
1102 fs,
1103 fn);
1104 if (GNUNET_SYSERR == ret)
1105 {
1107 _ ("Failed to parse configuration file `%s'\n"),
1108 fn);
1109 }
1110 GNUNET_free (fn);
1111 GNUNET_free (mem);
1112 /* restore dirty flag - anything we set in the meantime
1113 * came from disk */
1114 cfg->dirty = dirty;
1115 return ret;
1116}
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:225
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:677
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
@ 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_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 1162 of file configuration.c.

1164{
1165 char *mem;
1166 char *cbuf;
1167 char *val;
1168 char *pos;
1169 size_t m_size;
1170 size_t c_size;
1171
1172 /* Pass1 : calculate the buffer size required */
1173 m_size = 0;
1174 for (struct ConfigSection *sec = cfg->sections;
1175 NULL != sec;
1176 sec = sec->next)
1177 {
1178 if (sec->inaccessible)
1179 continue;
1180 /* For each section we need to add 3 characters: {'[',']','\n'} */
1181 m_size += strlen (sec->name) + 3;
1182 for (struct ConfigEntry *ent = sec->entries;
1183 NULL != ent;
1184 ent = ent->next)
1185 {
1186 if (do_skip (sec->name,
1187 ent->key))
1188 continue;
1189 if (NULL != ent->val)
1190 {
1191 /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */
1192 pos = ent->val;
1193 while (NULL != (pos = strstr (pos, "\n")))
1194 {
1195 m_size++;
1196 pos++;
1197 }
1198 /* For each key = value pair we need to add 4 characters (2
1199 spaces and 1 equal-to character and 1 new line) */
1200 m_size += strlen (ent->key) + strlen (ent->val) + 4;
1201 }
1202 }
1203 /* A new line after section end */
1204 m_size++;
1205 }
1206
1207 /* Pass2: Allocate memory and write the configuration to it */
1208 mem = GNUNET_malloc (m_size);
1209 c_size = 0;
1210 *size = c_size;
1211 for (struct ConfigSection *sec = cfg->sections;
1212 NULL != sec;
1213 sec = sec->next)
1214 {
1215 int len;
1216
1217 len = GNUNET_asprintf (&cbuf,
1218 "[%s]\n",
1219 sec->name);
1220 GNUNET_assert (0 < len);
1221 GNUNET_memcpy (mem + c_size,
1222 cbuf,
1223 len);
1224 c_size += len;
1225 GNUNET_free (cbuf);
1226 for (struct ConfigEntry *ent = sec->entries;
1227 NULL != ent;
1228 ent = ent->next)
1229 {
1230 if (do_skip (sec->name,
1231 ent->key))
1232 continue;
1233 if (NULL != ent->val)
1234 {
1235 val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1236 strcpy (val, ent->val);
1237 while (NULL != (pos = strstr (val, "\n")))
1238 {
1239 memmove (&pos[2], &pos[1], strlen (&pos[1]));
1240 pos[0] = '\\';
1241 pos[1] = 'n';
1242 }
1243 len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
1244 GNUNET_free (val);
1245 GNUNET_memcpy (mem + c_size, cbuf, len);
1246 c_size += len;
1247 GNUNET_free (cbuf);
1248 }
1249 }
1250 GNUNET_memcpy (mem + c_size, "\n", 1);
1251 c_size++;
1252 }
1253 GNUNET_assert (c_size == m_size);
1254 *size = c_size;
1255 return mem;
1256}
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
Definition: configuration.c:39
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:43
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:75

References cfg, do_skip(), GNUNET_asprintf(), GNUNET_assert, GNUNET_free, GNUNET_malloc, GNUNET_memcpy, ConfigEntry::next, ConfigSection::next, 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 1316 of file configuration.c.

1318{
1319 struct GNUNET_Buffer buf = { 0 };
1320
1322 "#\n# Configuration file diagnostics\n#\n");
1324 "# Entry point: %s\n",
1326 "<none>");
1328 "#\n# Files Loaded:\n");
1329
1330 for (struct ConfigFile *cfil = cfg->loaded_files_head;
1331 NULL != cfil;
1332 cfil = cfil->next)
1333 {
1335 "# ");
1336 for (unsigned int i = 0; i < cfil->level; i++)
1338 "+");
1339 if (0 != cfil->level)
1341 " ");
1342
1344 "%s",
1345 cfil->source_filename);
1346
1347 if (NULL != cfil->hint_restrict_section)
1349 " (%s secret section %s)",
1350 cfil->hint_inaccessible
1351 ? "inaccessible"
1352 : "loaded",
1353 cfil->hint_restrict_section);
1354
1356 "\n");
1357 }
1358
1360 "#\n# Installation paths:\n");
1361
1371
1372
1374 "#\n\n");
1375
1376 for (struct ConfigSection *sec = cfg->sections;
1377 NULL != sec;
1378 sec = sec->next)
1379 {
1380 if (sec->hint_secret_filename)
1382 "# secret section from %s\n# secret file stat %s\n",
1383 sec->hint_secret_filename,
1384 sec->hint_secret_stat);
1385 if (sec->hint_inlined_from_filename)
1386 {
1388 "# inlined from %s:%u\n",
1389 sec->hint_inlined_from_filename,
1390 sec->hint_inlined_from_line);
1391 }
1393 "[%s]\n\n",
1394 sec->name);
1395 if (sec->inaccessible)
1396 {
1398 "# <section contents inaccessible>\n\n\n");
1399 continue;
1400 }
1401 for (struct ConfigEntry *ent = sec->entries;
1402 NULL != ent;
1403 ent = ent->next)
1404 {
1405 if (do_skip (sec->name,
1406 ent->key))
1407 continue;
1408 if (NULL != ent->val)
1409 {
1410 char *pos;
1411 char *val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1412 strcpy (val, ent->val);
1413 while (NULL != (pos = strstr (val, "\n")))
1414 {
1415 memmove (&pos[2], &pos[1], strlen (&pos[1]));
1416 pos[0] = '\\';
1417 pos[1] = 'n';
1418 }
1419 if (NULL != ent->hint_filename)
1420 {
1422 "# %s:%u\n",
1423 ent->hint_filename,
1424 ent->hint_lineno);
1425 }
1427 "%s = %s\n",
1428 ent->key,
1429 val);
1430 GNUNET_free (val);
1431 }
1432 GNUNET_buffer_write_str (&buf, "\n");
1433 }
1434 GNUNET_buffer_write_str (&buf, "\n");
1435 }
1436 return GNUNET_buffer_reap_str (&buf);
1437}
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:123
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:103
@ GNUNET_OS_IPK_SELF_PREFIX
Return the installation directory of this application, not the one of the overall GNUnet installation...
struct ConfigFile * next
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, ConfigEntry::next, ConfigSection::next, ConfigFile::next, 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 730 of file configuration.c.

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

1444{
1445 char *fn;
1446 char *cfg_buf;
1447 size_t size;
1448
1450 if (fn == NULL)
1451 return GNUNET_SYSERR;
1453 {
1454 GNUNET_free (fn);
1455 return GNUNET_SYSERR;
1456 }
1458 &size);
1459 {
1460 struct GNUNET_DISK_FileHandle *h;
1461
1470 if (NULL == h)
1471 {
1472 GNUNET_free (fn);
1473 GNUNET_free (cfg_buf);
1474 return GNUNET_SYSERR;
1475 }
1476 if (((ssize_t) size) !=
1478 cfg_buf,
1479 size))
1480 {
1482 "write",
1483 fn);
1485 (void) GNUNET_DISK_directory_remove (fn);
1486 GNUNET_free (fn);
1487 GNUNET_free (cfg_buf);
1488 cfg->dirty = GNUNET_SYSERR; /* last write failed */
1489 return GNUNET_SYSERR;
1490 }
1493 }
1494 GNUNET_free (fn);
1495 GNUNET_free (cfg_buf);
1496 cfg->dirty = GNUNET_NO; /* last write succeeded */
1497 return GNUNET_OK;
1498}
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:1248
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:700
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1088
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1322
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:623
@ 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 1702 of file configuration.c.

1706{
1707 int ret;
1708 struct GNUNET_CONFIGURATION_Handle *diff;
1709
1710 diff = GNUNET_CONFIGURATION_get_diff (cfg_default, cfg_new);
1713 return ret;
1714}
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 1685 of file configuration.c.

1688{
1689 struct DiffHandle diffHandle;
1690
1691 GNUNET_break (cfg_default->pd == cfg_new->pd);
1692 diffHandle.cfgDiff = GNUNET_CONFIGURATION_create (cfg_new->pd);
1693 diffHandle.cfg_default = cfg_default;
1696 &diffHandle);
1697 return diffHandle.cfgDiff;
1698}
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 1120 of file configuration.c.

1121{
1122 return cfg->dirty;
1123}

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 3005 of file configuration.c.

3007{
3008 return cfg->pd;
3009}

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 1502 of file configuration.c.

1506{
1507 for (struct ConfigSection *spos = cfg->sections;
1508 NULL != spos;
1509 spos = spos->next)
1510 for (struct ConfigEntry *epos = spos->entries;
1511 NULL != epos;
1512 epos = epos->next)
1513 if (NULL != epos->val)
1514 iter (iter_cls,
1515 spos->name,
1516 epos->key,
1517 epos->val);
1518}

References cfg, ConfigEntry::next, ConfigSection::next, 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 1555 of file configuration.c.

1559{
1560 struct ConfigSection *spos;
1561 struct ConfigSection *next;
1562
1563 next = cfg->sections;
1564 while (next != NULL)
1565 {
1566 spos = next;
1567 next = spos->next;
1568 if (! spos->inaccessible)
1569 iter (iter_cls,
1570 spos->name);
1571 }
1572}
bool inaccessible
Is the configuration section marked as inaccessible?
Definition: configuration.c:93

References cfg, 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(), 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 1576 of file configuration.c.

1578{
1579 struct ConfigSection *spos;
1580 struct ConfigSection *prev;
1581 struct ConfigEntry *ent;
1582
1583 prev = NULL;
1584 spos = cfg->sections;
1585 while (NULL != spos)
1586 {
1587 if (0 == strcasecmp (section,
1588 spos->name))
1589 {
1590 if (NULL == prev)
1591 cfg->sections = spos->next;
1592 else
1593 prev->next = spos->next;
1594 while (NULL != (ent = spos->entries))
1595 {
1596 spos->entries = ent->next;
1597 GNUNET_free (ent->key);
1598 GNUNET_free (ent->val);
1600 GNUNET_free (ent);
1601 cfg->dirty = GNUNET_YES;
1602 }
1603 GNUNET_free (spos->name);
1607 GNUNET_free (spos);
1608 return;
1609 }
1610 prev = spos;
1611 spos = spos->next;
1612 }
1613}
char * hint_filename
Diagnostics information for the filename.
Definition: configuration.c:58
char * key
key for this entry
Definition: configuration.c:48
char * val
current, committed value
Definition: configuration.c:53
char * hint_inlined_from_filename
For secret sections: Where was this inlined from?
struct ConfigEntry * entries
entries in the section
Definition: configuration.c:80
char * hint_secret_filename
Diagnostics hint for the secret file.
Definition: configuration.c:98
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 1780 of file configuration.c.

1785{
1786 struct ConfigEntry *e;
1787 char dummy[2];
1788
1789 if (NULL == (e = find_entry (cfg,
1790 section,
1791 option)))
1792 return GNUNET_NO;
1793 if (NULL == e->val)
1794 return GNUNET_NO;
1795 if (1 != sscanf (e->val,
1796 "%llu%1s",
1797 number,
1798 dummy))
1799 return GNUNET_SYSERR;
1800 return GNUNET_OK;
1801}
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(), 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(), 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 1805 of file configuration.c.

1809{
1810 char s[64];
1811
1812 /* See: #9369 */
1813 const locale_t cl = newlocale (LC_NUMERIC_MASK,
1814 "C",
1815 (locale_t) 0);
1816 locale_t old_locale = uselocale (cl);
1817 GNUNET_snprintf (s,
1818 64,
1819 "%f",
1820 (double) number);
1821 uselocale (old_locale);
1823 section,
1824 option,
1825 s);
1826}
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 1830 of file configuration.c.

1835{
1836 struct ConfigEntry *e;
1837 char dummy[2];
1838
1839 if (NULL == (e = find_entry (cfg,
1840 section,
1841 option)))
1842 return GNUNET_NO;
1843 if (NULL == e->val)
1844 return GNUNET_NO;
1845 /* See #9369 */
1846 {
1847 const locale_t cl = newlocale (LC_NUMERIC_MASK,
1848 "C",
1849 (locale_t) 0);
1850 locale_t old_locale = uselocale (cl);
1851
1852 if (1 != sscanf (e->val,
1853 "%f%1s",
1854 number,
1855 dummy))
1856 return GNUNET_SYSERR;
1857 uselocale (old_locale);
1858 }
1859 return GNUNET_OK;
1860}

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 1864 of file configuration.c.

1869{
1870 struct ConfigEntry *e;
1871 int ret;
1872
1873 if (NULL == (e = find_entry (cfg,
1874 section,
1875 option)))
1876 return GNUNET_NO;
1877 if (NULL == e->val)
1878 return GNUNET_NO;
1880 time);
1881 if (GNUNET_OK != ret)
1883 section,
1884 option,
1885 _ ("Not a valid relative time specification"));
1886 return ret;
1887}
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(), 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 1891 of file configuration.c.

1896{
1897 struct ConfigEntry *e;
1898
1899 if (NULL == (e = find_entry (cfg,
1900 section,
1901 option)))
1902 return GNUNET_NO;
1903 if (NULL == e->val)
1904 return GNUNET_NO;
1906 size);
1907}
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(), 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 2014 of file configuration.c.

2017{
2018 struct ConfigEntry *e;
2019
2020 if ( (NULL == (e = find_entry (cfg,
2021 section,
2022 option))) ||
2023 (NULL == e->val) )
2024 return GNUNET_NO;
2025 return GNUNET_YES;
2026}

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 1921 of file configuration.c.

1926{
1927 struct ConfigEntry *e;
1928
1929 if ( (NULL == (e = find_entry (cfg,
1930 section,
1931 option))) ||
1932 (NULL == e->val) )
1933 {
1934 *value = NULL;
1935 return GNUNET_NO;
1936 }
1937 *value = GNUNET_strdup (e->val);
1938 return GNUNET_OK;
1939}

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(), 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(), process_acl4(), process_acl6(), read_service_conf(), run(), setup_exit_helper_args(), setup_service(), 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 2225 of file configuration.c.

2230{
2231 char *tmp;
2233
2235 section,
2236 option,
2237 &tmp);
2238 if (GNUNET_OK != ret)
2239 {
2241 "Failed to retrieve filename\n");
2242 *value = NULL;
2243 return ret;
2244 }
2246 tmp);
2248 GNUNET_free (tmp);
2249 if (*value == NULL)
2250 return GNUNET_SYSERR;
2251 return GNUNET_OK;
2252}
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(), get_oidc_dir_path(), get_pid_file_name(), get_serialization_file_name(), get_serialization_file_name_in_dir(), 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_PQ_connect_with_cfg2(), GNUNET_TIME_absolute_get_monotonic(), load(), load_hostlist_file(), main_init(), new_sub(), print_filename_option(), purge_cfg_dir(), read_index_list(), 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:
Here is the caller 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 2284 of file configuration.c.

2290{
2291 char *list;
2292 char *pos;
2293 char *end;
2294 char old;
2295 int ret;
2296
2297 if (GNUNET_OK !=
2299 section,
2300 option,
2301 &list))
2302 return 0;
2303 GNUNET_assert (list != NULL);
2304 ret = 0;
2305 pos = list;
2306 while (1)
2307 {
2308 while (pos[0] == ' ')
2309 pos++;
2310 if (strlen (pos) == 0)
2311 break;
2312 end = pos + 1;
2313 while ((end[0] != ' ') && (end[0] != '\0'))
2314 {
2315 if (end[0] == '\\')
2316 {
2317 switch (end[1])
2318 {
2319 case '\\':
2320 case ' ':
2321 memmove (end, &end[1], strlen (&end[1]) + 1);
2322
2323 case '\0':
2324 /* illegal, but just keep it */
2325 break;
2326
2327 default:
2328 /* illegal, but just ignore that there was a '/' */
2329 break;
2330 }
2331 }
2332 end++;
2333 }
2334 old = end[0];
2335 end[0] = '\0';
2336 if (strlen (pos) > 0)
2337 {
2338 ret++;
2339 if ( (NULL != cb) &&
2340 (GNUNET_OK != cb (cb_cls,
2341 pos)))
2342 {
2344 break;
2345 }
2346 }
2347 if (old == '\0')
2348 break;
2349 pos = end + 1;
2350 }
2351 GNUNET_free (list);
2352 return ret;
2353}
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 1522 of file configuration.c.

1527{
1528 struct ConfigSection *spos;
1529
1530 spos = cfg->sections;
1531 while ((spos != NULL) && (0 != strcasecmp (spos->name, section)))
1532 spos = spos->next;
1533 if (NULL == spos)
1534 return;
1535 if (spos->inaccessible)
1536 {
1538 "Section '%s' is marked as inaccessible, because the configuration "
1539 "file that contains the section can't be read.\n",
1540 section);
1541 return;
1542 }
1543 for (struct ConfigEntry *epos = spos->entries;
1544 NULL != epos;
1545 epos = epos->next)
1546 if (NULL != epos->val)
1547 iter (iter_cls,
1548 spos->name,
1549 epos->key,
1550 epos->val);
1551}

References cfg, ConfigSection::entries, GNUNET_ERROR_TYPE_WARNING, ConfigSection::inaccessible, LOG, ConfigSection::name, ConfigEntry::next, 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 1943 of file configuration.c.

1949{
1950 struct ConfigEntry *e;
1951 unsigned int i;
1952
1953 if (NULL == (e = find_entry (cfg,
1954 section,
1955 option)))
1956 return GNUNET_NO;
1957 for (i = 0; NULL != choices[i]; i++)
1958 if (0 == strcasecmp (choices[i], e->val))
1959 break;
1960 if (NULL == choices[i])
1961 {
1963 _ ("Configuration value '%s' for '%s'"
1964 " in section '%s' is not in set of legal choices\n"),
1965 e->val,
1966 option,
1967 section);
1968 return GNUNET_SYSERR;
1969 }
1970 *value = choices[i];
1971 return GNUNET_OK;
1972}

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

Referenced by GNUNET_CONFIGURATION_get_value_yesno(), 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 2256 of file configuration.c.

2260{
2261 static const char *yesno[] = {
2262 "YES",
2263 "NO",
2264 NULL
2265 };
2266 const char *val;
2268
2269 ret =
2271 section,
2272 option,
2273 yesno,
2274 &val);
2275 if (GNUNET_OK != ret)
2276 return ret;
2277 if (val == yesno[0])
2278 return GNUNET_YES;
2279 return GNUNET_NO;
2280}
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_listen_socket(), create_service(), database_connect(), GDS_NEIGHBOURS_init(), 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(), setup_service(), sign_ephemeral_key(), 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 1976 of file configuration.c.

1981{
1982 char *enc;
1983 int res;
1984 size_t data_size;
1985
1986 if (GNUNET_OK !=
1987 (res =
1989 section,
1990 option,
1991 &enc)))
1992 return res;
1993 data_size = (strlen (enc) * 5) / 8;
1994 if (data_size != buf_size)
1995 {
1996 GNUNET_free (enc);
1997 return GNUNET_SYSERR;
1998 }
1999 if (GNUNET_OK !=
2001 strlen (enc),
2002 buf,
2003 buf_size))
2004 {
2005 GNUNET_free (enc);
2006 return GNUNET_SYSERR;
2007 }
2008 GNUNET_free (enc);
2009 return GNUNET_OK;
2010}
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:816

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 2200 of file configuration.c.

2203{
2204 char *dup;
2205 size_t i;
2206 size_t len;
2207
2208 for (i = 0; '\0' != orig[i]; i++)
2209 {
2210 if ('$' != orig[i])
2211 continue;
2212 dup = GNUNET_strdup (orig + i);
2213 dup = expand_dollar (cfg, dup, 0);
2214 GNUNET_assert (NULL != dup); /* make compiler happy */
2215 len = strlen (dup) + 1;
2216 orig = GNUNET_realloc (orig, i + len);
2217 GNUNET_memcpy (orig + i, dup, len);
2218 GNUNET_free (dup);
2219 }
2220 return orig;
2221}
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 1761 of file configuration.c.

1765{
1766 char s[64];
1767
1768 GNUNET_snprintf (s,
1769 64,
1770 "%llu",
1771 number);
1773 section,
1774 option,
1775 s);
1776}

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

Referenced by next_phase(), 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 1718 of file configuration.c.

1723{
1724 struct ConfigSection *sec;
1725 struct ConfigEntry *e;
1726 char *nv;
1727
1728 e = find_entry (cfg, section, option);
1729 if (NULL != e)
1730 {
1731 if (NULL == value)
1732 {
1733 GNUNET_free (e->val);
1734 e->val = NULL;
1735 }
1736 else
1737 {
1738 nv = GNUNET_strdup (value);
1739 GNUNET_free (e->val);
1740 e->val = nv;
1741 }
1742 return;
1743 }
1744 sec = find_section (cfg, section);
1745 if (sec == NULL)
1746 {
1747 sec = GNUNET_new (struct ConfigSection);
1748 sec->name = GNUNET_strdup (section);
1749 sec->next = cfg->sections;
1750 cfg->sections = sec;
1751 }
1752 e = GNUNET_new (struct ConfigEntry);
1753 e->key = GNUNET_strdup (option);
1754 e->val = GNUNET_strdup (value);
1755 e->next = sec->entries;
1756 sec->entries = e;
1757}
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(), 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 2452 of file configuration.c.

2457{
2458 char *list;
2459 char *pos;
2460 char *end;
2461 char *match;
2462 char old;
2463
2464 if (GNUNET_OK !=
2466 section,
2467 option,
2468 &list))
2469 return GNUNET_NO;
2470 match = escape_name (value);
2471 pos = list;
2472 while (1)
2473 {
2474 while (pos[0] == ' ')
2475 pos++;
2476 if (strlen (pos) == 0)
2477 break;
2478 end = pos + 1;
2479 while ((end[0] != ' ') && (end[0] != '\0'))
2480 {
2481 if (end[0] == '\\')
2482 {
2483 switch (end[1])
2484 {
2485 case '\\':
2486 case ' ':
2487 end++;
2488 break;
2489
2490 case '\0':
2491 /* illegal, but just keep it */
2492 break;
2493
2494 default:
2495 /* illegal, but just ignore that there was a '/' */
2496 break;
2497 }
2498 }
2499 end++;
2500 }
2501 old = end[0];
2502 end[0] = '\0';
2503 if (0 == strcmp (pos, match))
2504 {
2505 if (old != '\0')
2506 memmove (pos,
2507 &end[1],
2508 strlen (&end[1]) + 1);
2509 else
2510 {
2511 if (pos != list)
2512 pos[-1] = '\0';
2513 else
2514 pos[0] = '\0';
2515 }
2517 section,
2518 option,
2519 list);
2520 GNUNET_free (list);
2521 GNUNET_free (match);
2522 return GNUNET_OK;
2523 }
2524 if (old == '\0')
2525 break;
2526 end[0] = old;
2527 pos = end + 1;
2528 }
2529 GNUNET_free (list);
2530 GNUNET_free (match);
2531 return GNUNET_NO;
2532}
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 2414 of file configuration.c.

2419{
2420 char *escaped;
2421 char *old;
2422 char *nw;
2423
2424 if (GNUNET_SYSERR ==
2426 section,
2427 option,
2428 &test_match,
2429 (void *) value))
2430 return GNUNET_NO; /* already exists */
2431 if (GNUNET_OK !=
2432 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
2433 old = GNUNET_strdup ("");
2434 escaped = escape_name (value);
2435 nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2);
2436 strcpy (nw, old);
2437 if (strlen (old) > 0)
2438 strcat (nw, " ");
2439 strcat (nw, escaped);
2441 section,
2442 option,
2443 nw);
2444 GNUNET_free (old);
2445 GNUNET_free (nw);
2446 GNUNET_free (escaped);
2447 return GNUNET_OK;
2448}
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 2995 of file configuration.c.

2997{
2998 GNUNET_free (cs->option);
2999 GNUNET_free (cs->section);
3000 GNUNET_free (cs->value);
3001}

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 2803 of file configuration.c.

2808{
2809 struct GNUNET_CONFIGURATION_ConfigSettings *cs = cls;
2810 struct GNUNET_CONFIGURATION_Handle *out = NULL;
2811 struct GNUNET_CONFIGURATION_Handle *ncfg = NULL;
2812
2813 (void) args;
2814 if (cs->diagnostics)
2815 {
2816 /* Re-parse the configuration with diagnostics enabled. */
2819 if (GNUNET_OK !=
2821 cfgfile))
2822 {
2823 fprintf (stderr,
2824 _ ("Failed to load config file `%s'"),
2825 cfgfile);
2826 return;
2827 }
2828 cfg = ncfg;
2829 }
2830
2831 if (cs->full)
2832 cs->rewrite = GNUNET_YES;
2833 if (cs->list_sections)
2834 {
2835 fprintf (stderr,
2836 _ ("The following sections are available:\n"));
2839 NULL);
2840 return;
2841 }
2842 if ( (! cs->rewrite) &&
2843 (NULL == cs->section) )
2844 {
2845 char *serialization;
2846
2847 if (! cs->diagnostics)
2848 {
2849 fprintf (stderr,
2850 _ ("%s, %s or %s argument is required\n"),
2851 "--section",
2852 "--list-sections",
2853 "--diagnostics");
2855 return;
2856 }
2858 fprintf (stdout,
2859 "%s",
2860 serialization);
2861 GNUNET_free (serialization);
2862 }
2863 else if ( (NULL != cs->section) &&
2864 (NULL == cs->value) )
2865 {
2866 if (NULL == cs->option)
2867 {
2869 cfg,
2870 cs->section,
2871 cs->is_filename
2873 : &print_option,
2874 (void *) cfg);
2875 }
2876 else
2877 {
2878 char *value;
2879
2880 if (cs->is_filename)
2881 {
2882 if (GNUNET_OK !=
2884 cs->section,
2885 cs->option,
2886 &value))
2887 {
2889 cs->section,
2890 cs->option);
2892 return;
2893 }
2894 }
2895 else
2896 {
2897 if (GNUNET_OK !=
2899 cs->section,
2900 cs->option,
2901 &value))
2902 {
2904 cs->section,
2905 cs->option);
2907 return;
2908 }
2909 }
2910 fprintf (stdout,
2911 "%s\n",
2912 value);
2914 }
2915 }
2916 else if (NULL != cs->section)
2917 {
2918 if (NULL == cs->option)
2919 {
2920 fprintf (stderr,
2921 _ ("--option argument required to set value\n"));
2923 return;
2924 }
2927 cs->section,
2928 cs->option,
2929 cs->value);
2930 cs->rewrite = GNUNET_YES;
2931 }
2932 if (cs->rewrite)
2933 {
2934 char *cfg_fn = NULL;
2935
2936 if (NULL == out)
2938
2939 if (NULL == cfgfile)
2940 {
2941 const char *xdg = getenv ("XDG_CONFIG_HOME");
2942
2943 if (NULL != xdg)
2944 GNUNET_asprintf (&cfg_fn,
2945 "%s%s%s",
2946 xdg,
2948 cfg->pd->config_file);
2949 else
2950 cfg_fn = GNUNET_strdup (cfg->pd->user_config_file);
2951 cfgfile = cfg_fn;
2952 }
2953
2954 if (! cs->full)
2955 {
2956 struct GNUNET_CONFIGURATION_Handle *def;
2957
2959 if (GNUNET_OK !=
2961 NULL))
2962 {
2963 fprintf (stderr,
2964 _ ("failed to load configuration defaults"));
2965 cs->global_ret = 1;
2968 GNUNET_free (cfg_fn);
2969 return;
2970 }
2971 if (GNUNET_OK !=
2973 out,
2974 cfgfile))
2975 cs->global_ret = 2;
2977 }
2978 else
2979 {
2980 if (GNUNET_OK !=
2982 cfgfile))
2983 cs->global_ret = 2;
2984 }
2985 GNUNET_free (cfg_fn);
2986 }
2987 if (NULL != out)
2989 if (NULL != ncfg)
2991}
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 _, warningfilter::args, 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: