GNUnet 0.29.1-dev.1-3-g346358e26
 
Loading...
Searching...
No Matches
Configuration library

Configuration management. More...

Collaboration diagram for Configuration library:

Data Structures

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

Macros

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

Typedefs

typedef void(* GNUNET_CONFIGURATION_CleanCallback) (void *cls, const char *section, const char *option, unsigned int line)
 Function called for each duplicate definition removed by GNUNET_CONFIGURATION_clean_file().
 
typedef enum GNUNET_GenericReturnValue(* GNUNET_CONFIGURATION_Callback) (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Signature of a function to be run with a configuration.
 
typedef void(* GNUNET_CONFIGURATION_Iterator) (void *cls, const char *section, const char *option, const char *value)
 Function to iterate over options.
 
typedef void(* GNUNET_CONFIGURATION_SectionIterator) (void *cls, const char *section)
 Function to iterate over all configuration sections.
 

Functions

struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create (const struct GNUNET_OS_ProjectData *pd)
 Create a new configuration object.
 
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Duplicate an existing configuration object.
 
void GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
 Destroy configuration object.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
 Load configuration.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d)
 Load default configuration.
 
char * GNUNET_CONFIGURATION_default_filename (const struct GNUNET_OS_ProjectData *pd)
 Return the filename of the default configuration filename that is used when no explicit configuration entry point has been specified.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
 Parse a configuration file, add all of the options in the file to the configuration environment.
 
char * GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
 Serializes the given configuration.
 
char * GNUNET_CONFIGURATION_serialize_diagnostics (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Serializes the given configuration with diagnostics information.
 
char * GNUNET_CONFIGURATION_serialize_diagnostics_verbose (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Serializes the given configuration with verbose diagnostics information, including all source definitions of each value.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_clean_file (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename, GNUNET_CONFIGURATION_CleanCallback cb, void *cb_cls, unsigned int *removed)
 Remove redundant option definitions from a parsed configuration file.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *source_filename)
 De-serializes configuration.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
 Write configuration file.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle *cfg_default, const struct GNUNET_CONFIGURATION_Handle *cfg_new, const char *filename)
 Write only configuration entries that have been changed to configuration file.
 
struct GNUNET_CONFIGURATION_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_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Test if there are configuration options that were changed since the last save.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse_and_run (const struct GNUNET_OS_ProjectData *pd, const char *filename, GNUNET_CONFIGURATION_Callback cb, void *cb_cls)
 Parse a configuration file filename and run the function cb with the resulting configuration object.
 
void GNUNET_CONFIGURATION_enable_diagnostics (struct GNUNET_CONFIGURATION_Handle *cfg)
 Enable extra diagnostics.
 
const struct GNUNET_OS_ProjectData * GNUNET_CONFIGURATION_get_project_data (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Return the project data associated with this configuration.
 
void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
 Iterate over all options in the configuration.
 
void GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_SectionIterator iter, void *iter_cls)
 Iterate over all sections in the configuration.
 
void GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
 Remove the given section and all options in it.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
 Get a configuration value that should be a number.
 
void GNUNET_CONFIGURATION_set_value_float (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, float number)
 Set a configuration value that should be a float.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, float *number)
 Get a configuration value that should be a floating point number.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
 Get a configuration value that should be a relative time.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *size)
 Get a configuration value that should be a size in bytes.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
 Test if we have a value for a particular option.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
 Get a configuration value that should be a string.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
 Get a configuration value that should be the name of a file or directory.
 
int GNUNET_CONFIGURATION_iterate_value_filenames (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, GNUNET_FileNameCallback cb, void *cb_cls)
 Iterate over the set of filenames stored in a configuration value.
 
void GNUNET_CONFIGURATION_iterate_section_values (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
 Iterate over values of a section in the configuration.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *const *choices, const char **value)
 Get a configuration value that should be in a set of predefined strings.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
 Get a configuration value that should be in a set of "YES" or "NO".
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, void *buf, size_t buf_size)
 Get Crockford32-encoded fixed-size binary data from a configuration.
 
char * GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, char *orig)
 Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" where either in the "PATHS" section or the environment "FOO" is set to "DIRECTORY".
 
void GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long number)
 Set a configuration value that should be a number.
 
void GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
 Set a configuration value that should be a string.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
 Remove a filename from a configuration value that represents a list of filenames.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
 Append a filename to a configuration value that represents a list of filenames.
 
void GNUNET_CONFIGURATION_config_settings_free (struct GNUNET_CONFIGURATION_ConfigSettings *cs)
 Free resources associated with cs.
 
void GNUNET_CONFIGURATION_config_tool_run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main task to run to perform operations typical for gnunet-config as per the configuration settings given in cls.
 
char * GNUNET_CONFIGURATION_get_suid_binary_path (const struct GNUNET_OS_ProjectData *pd, const struct GNUNET_CONFIGURATION_Handle *cfg, const char *progname)
 Given the name of a helper, service or daemon binary construct the full path to the binary using the SUID_BINARY_PATH in the PATHS section of the configuration.
 

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 818 of file gnunet_configuration_lib.h.

918{
919#endif
920#ifdef __cplusplus
921}
922#endif
923
924#endif
925
/* end of group configuration */
927
/* end of group addition */

Typedef Documentation

◆ GNUNET_CONFIGURATION_CleanCallback

typedef void(* GNUNET_CONFIGURATION_CleanCallback) (void *cls, const char *section, const char *option, unsigned int line)

Function called for each duplicate definition removed by GNUNET_CONFIGURATION_clean_file().

Parameters
clsclosure
sectionconfiguration section
optionconfiguration option
lineline removed from the target file

Definition at line 193 of file gnunet_configuration_lib.h.

◆ 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 290 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 356 of file gnunet_configuration_lib.h.

◆ GNUNET_CONFIGURATION_SectionIterator

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

Function to iterate over all configuration sections.

Parameters
clsclosure
sectionname of the section

Definition at line 369 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 259 of file configuration.c.

260{
262 char *p;
263
265 cfg->pd = pd;
266 /* make certain values from the project data available
267 as PATHS */
270 if (NULL != p)
271 {
273 "PATHS",
274 "DATADIR",
275 p);
276 GNUNET_free (p);
277 }
280 if (NULL != p)
281 {
283 "PATHS",
284 "LIBDIR",
285 p);
286 GNUNET_free (p);
287 }
290 if (NULL != p)
291 {
293 "PATHS",
294 "BINDIR",
295 p);
296 GNUNET_free (p);
297 }
300 if (NULL != p)
301 {
303 "PATHS",
304 "PREFIX",
305 p);
306 GNUNET_free (p);
307 }
310 if (NULL != p)
311 {
313 "PATHS",
314 "LOCALEDIR",
315 p);
316 GNUNET_free (p);
317 }
320 if (NULL != p)
321 {
323 "PATHS",
324 "ICONDIR",
325 p);
326 GNUNET_free (p);
327 }
330 if (NULL != p)
331 {
333 "PATHS",
334 "DOCDIR",
335 p);
336 GNUNET_free (p);
337 }
340 if (NULL != p)
341 {
343 "PATHS",
344 "LIBEXECDIR",
345 p);
346 GNUNET_free (p);
347 }
348 return cfg;
349}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static struct GNUNET_Process * p
Helper process we started.
Definition gnunet-uri.c:38
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_OS_installation_get_path(const struct GNUNET_OS_ProjectData *pd, enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
@ GNUNET_OS_IPK_ICONDIR
Return the prefix of the path with application icons (share/icons/).
@ GNUNET_OS_IPK_DATADIR
Return the directory where data is installed (share/gnunet/)
@ GNUNET_OS_IPK_DOCDIR
Return the prefix of the path with documentation files, including the license (share/doc/gnunet/).
@ GNUNET_OS_IPK_LOCALEDIR
Return the directory where translations are installed (share/locale/)
@ GNUNET_OS_IPK_LIBDIR
Return the directory where libraries are installed.
@ GNUNET_OS_IPK_PREFIX
Return the "PREFIX" directory given to configure.
@ GNUNET_OS_IPK_BINDIR
Return the directory where the program binaries are installed.
@ GNUNET_OS_IPK_LIBEXECDIR
Return the directory where helper binaries are installed (lib/gnunet/libexec/)
const struct GNUNET_OS_ProjectData * pd
Project data for this configuration object.

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

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

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

◆ GNUNET_CONFIGURATION_dup()

struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup ( const struct GNUNET_CONFIGURATION_Handle *  cfg)

Duplicate an existing configuration object.

Parameters
cfgconfiguration to duplicate
Returns
duplicate configuration

Definition at line 2295 of file configuration.c.

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

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

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

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

◆ GNUNET_CONFIGURATION_destroy()

void GNUNET_CONFIGURATION_destroy ( struct GNUNET_CONFIGURATION_Handle *  cfg)

Destroy configuration object.

Parameters
cfgconfiguration to destroy

Definition at line 353 of file configuration.c.

354{
355 struct ConfigSection *sec;
356 struct ConfigFile *cf;
357
358 while (NULL != (sec = cfg->sections))
360 while (NULL != (cf = cfg->loaded_files_head))
361 {
366 cf);
367 GNUNET_free (cf);
368 }
371}
void GNUNET_CONFIGURATION_remove_section(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Remove the given section and all options in it.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
char * hint_restrict_section
Was this configuration file parsed via @inline-secret@?
char * source_filename
Source filename.
configuration section
char * name
name of the section
struct ConfigFile * loaded_files_tail
Linked list of loaded files.
struct ConfigSection * sections
Configuration sections.
struct ConfigFile * loaded_files_head
Linked list of loaded files.
char * main_filename
Name of the entry point configuration file.

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

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

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

◆ GNUNET_CONFIGURATION_load()

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

Load configuration.

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

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

Definition at line 3288 of file configuration.c.

3291{
3292 char *baseconfig;
3293 const char *base_config_varname;
3294
3295 if (cfg->load_called)
3296 {
3297 /* FIXME: Make this a GNUNET_assert later */
3298 GNUNET_break (0);
3300 }
3301 cfg->load_called = true;
3302 if (NULL != filename)
3303 {
3306 }
3307
3308 base_config_varname = cfg->pd->base_config_varname;
3309
3310 if ((NULL != base_config_varname)
3311 && (NULL != (baseconfig = getenv (base_config_varname))))
3312 {
3313 baseconfig = GNUNET_strdup (baseconfig);
3314 }
3315 else
3316 {
3317 char *ipath;
3318
3321 if (NULL == ipath)
3322 {
3323 GNUNET_break (0);
3324 return GNUNET_SYSERR;
3325 }
3326 GNUNET_asprintf (&baseconfig,
3327 "%s%s",
3328 ipath,
3329 "config.d");
3330 GNUNET_free (ipath);
3331 }
3332
3333 {
3334 char *dname = GNUNET_STRINGS_filename_expand (baseconfig);
3335
3336 GNUNET_free (baseconfig);
3337
3338 if ((GNUNET_YES ==
3340 GNUNET_YES)) &&
3341 (GNUNET_SYSERR ==
3343 dname)))
3344 {
3346 "Failed to load base configuration from '%s'\n",
3347 filename);
3348 GNUNET_free (dname);
3349 return GNUNET_SYSERR; /* no configuration at all found */
3350 }
3351 GNUNET_free (dname);
3352 }
3353 if ((NULL != filename) &&
3354 (GNUNET_OK !=
3356 filename)))
3357 {
3358 /* specified configuration not found */
3360 "Failed to load configuration from file '%s'\n",
3361 filename);
3362 return GNUNET_SYSERR;
3363 }
3364 if (((GNUNET_YES !=
3366 "PATHS",
3367 "DEFAULTCONFIG"))) &&
3368 (filename != NULL))
3370 "PATHS",
3371 "DEFAULTCONFIG",
3372 filename);
3373 return GNUNET_OK;
3374}
#define LOG(kind,...)
char * getenv()
static char * filename
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Parse a configuration file, add all of the options in the file to the configuration environment.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load_from(struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d)
Load default configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition disk.c:466
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition strings.c:531
bool load_called
Was the configuration ever loaded via GNUNET_CONFIGURATION_load?
const char * base_config_varname
Name of an environment variable that can be used to override the location from which default configur...

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

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

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

◆ GNUNET_CONFIGURATION_load_from()

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

Load default configuration.

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

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

Definition at line 3190 of file configuration.c.

3193{
3194 struct CollectFilesContext files_context = {
3195 .files = NULL,
3196 .files_length = 0,
3197 };
3198 enum GNUNET_GenericReturnValue fun_ret = GNUNET_NO;
3199
3200 if (GNUNET_SYSERR ==
3201 GNUNET_DISK_directory_scan (defaults_d,
3203 &files_context))
3204 return GNUNET_SYSERR; /* no configuration at all found */
3205 qsort (files_context.files,
3206 files_context.files_length,
3207 sizeof (char *),
3208 &pstrcmp);
3209 for (unsigned int i = 0; i < files_context.files_length; i++)
3210 {
3211 const char *ext;
3212 const char *filename = files_context.files[i];
3213
3214 /* Examine file extension */
3215 ext = strrchr (filename, '.');
3216 if ( (NULL == ext) ||
3217 (0 != strcmp (ext,
3218 ".conf")) )
3219 {
3221 "Skipping file `%s'\n",
3222 filename);
3223 fun_ret = GNUNET_OK;
3224 continue;
3225 }
3227 filename);
3228 if (fun_ret != GNUNET_OK)
3229 break;
3230 }
3231 if (files_context.files_length > 0)
3232 {
3233 for (size_t i = 0; i < files_context.files_length; i++)
3234 GNUNET_free (files_context.files[i]);
3235 GNUNET_array_grow (files_context.files,
3236 files_context.files_length,
3237 0);
3238 }
3239 return fun_ret;
3240}
static int pstrcmp(const void *a, const void *b)
static enum GNUNET_GenericReturnValue collect_files_cb(void *cls, const char *filename)
Function called with a filename.
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition disk.c:881
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_NO
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
Closure to collect_files_cb.
char ** files
Collected files from globbing.
unsigned int files_length
Size of the files array.

References cfg, collect_files_cb(), filename, CollectFilesContext::files, CollectFilesContext::files_length, GNUNET_array_grow, GNUNET_CONFIGURATION_parse(), GNUNET_DISK_directory_scan(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_NO, 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 3244 of file configuration.c.

3246{
3247 char *cfg_fn;
3248 const char *xdg = getenv ("XDG_CONFIG_HOME");
3249
3250 if (NULL != xdg)
3251 GNUNET_asprintf (&cfg_fn,
3252 "%s%s%s",
3253 xdg,
3255 pd->config_file);
3256 else
3257 cfg_fn = GNUNET_strdup (pd->user_config_file);
3258
3259 if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
3260 return cfg_fn;
3261 GNUNET_free (cfg_fn);
3262
3263 /* Fall back to /etc/ for the default configuration.
3264 Should be okay to use forward slashes here. */
3265
3266 GNUNET_asprintf (&cfg_fn,
3267 "/etc/%s",
3268 pd->config_file);
3269 if (GNUNET_OK ==
3271 return cfg_fn;
3272 GNUNET_free (cfg_fn);
3273
3274 GNUNET_asprintf (&cfg_fn,
3275 "/etc/%s/%s",
3276 pd->project_dirname,
3277 pd->config_file);
3278 if (GNUNET_OK ==
3280 return cfg_fn;
3281
3282 GNUNET_free (cfg_fn);
3283 return NULL;
3284}
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test_read(const char *fil)
Check that fil corresponds to a filename and the file has read permissions.
Definition disk.c:565
#define DIR_SEPARATOR_STR
Definition platform.h:167
const char * project_dirname
Name of the project that is used in the "libexec" prefix, For example, "gnunet".
const char * user_config_file
Configuration file name to use (if $XDG_CONFIG_HOME is not set).
const char * config_file
Configuration file name (in $XDG_CONFIG_HOME) to use.

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

Referenced by GNUNET_PROGRAM_run2(), and main().

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

◆ GNUNET_CONFIGURATION_parse()

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

Parse a configuration file, add all of the options in the file to the configuration environment.

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

Definition at line 1097 of file configuration.c.

1099{
1100 struct ConfigFile *loaded_file;
1101 uint64_t fs64;
1102 size_t fs;
1103 char *fn;
1104 char *mem;
1105 int dirty;
1107 ssize_t sret;
1108
1111 "Asked to parse config file `%s'\n",
1112 fn);
1113 if (NULL == fn)
1114 return GNUNET_SYSERR;
1115
1116
1117 /* Check for cycles */
1118 {
1119 unsigned int lvl = cfg->current_nest_level;
1120 struct ConfigFile *cf = cfg->loaded_files_tail;
1121 struct ConfigFile *parent = NULL;
1122
1123
1124 for (; NULL != cf; parent = cf, cf = cf->prev)
1125 {
1126 /* Check parents based on level, skipping children of siblings. */
1127 if (cf->level >= lvl)
1128 continue;
1129 lvl = cf->level;
1130 if ( (NULL == cf->source_filename) ||
1131 (NULL == filename) )
1132 continue;
1133 if (0 == strcmp (cf->source_filename,
1134 filename))
1135 {
1136 if (NULL == parent)
1137 {
1139 "Forbidden direct cyclic configuration import (%s -> %s)\n",
1140 cf->source_filename,
1141 filename);
1142 }
1143 else
1145 "Forbidden indirect cyclic configuration import (%s -> ... -> %s -> %s)\n",
1146 cf->source_filename,
1147 parent->source_filename,
1148 filename);
1149 GNUNET_free (fn);
1150 return GNUNET_SYSERR;
1151 }
1152 }
1153
1154 }
1155
1156 /* Keep track of loaded files.*/
1157 {
1158 loaded_file = GNUNET_new (struct ConfigFile);
1159
1160 loaded_file->level = cfg->current_nest_level;
1161 loaded_file->source_filename = GNUNET_strdup (filename
1162 ? filename
1163 : "<input>");
1166 loaded_file);
1167 }
1168
1169 dirty = cfg->dirty; /* back up value! */
1170 if (GNUNET_SYSERR ==
1172 &fs64,
1173 GNUNET_NO,
1174 GNUNET_YES))
1175 {
1177 "Error while determining the file size of `%s'\n",
1178 fn);
1179 GNUNET_free (fn);
1180 return GNUNET_SYSERR;
1181 }
1182 if (fs64 > SIZE_MAX)
1183 {
1184 GNUNET_break (0); /* File size is more than the heap size */
1185 GNUNET_free (fn);
1186 return GNUNET_SYSERR;
1187 }
1188 fs = fs64;
1189 mem = GNUNET_malloc (fs);
1190 sret = GNUNET_DISK_fn_read (fn,
1191 mem,
1192 fs);
1193 if ((sret < 0) || (fs != (size_t) sret))
1194 {
1196 "Error while reading file `%s'\n",
1197 fn);
1198 GNUNET_free (fn);
1199 GNUNET_free (mem);
1200 return GNUNET_SYSERR;
1201 }
1202 if (cfg->diagnostics)
1203 {
1204 GNUNET_CRYPTO_hash (mem,
1205 fs,
1206 &loaded_file->content_hash);
1207 }
1209 "Deserializing contents of file `%s'\n",
1210 fn);
1212 mem,
1213 fs,
1214 fn);
1215 if (GNUNET_SYSERR == ret)
1216 {
1218 _ ("Failed to parse configuration file `%s'\n"),
1219 fn);
1220 }
1221 else if (cfg->diagnostics)
1222 {
1223 loaded_file->have_content_hash = true;
1224 }
1225 GNUNET_free (fn);
1226 GNUNET_free (mem);
1227 /* restore dirty flag - anything we set in the meantime
1228 * came from disk */
1229 cfg->dirty = dirty;
1230 return ret;
1231}
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition gnunet-fs.c:35
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *source_filename)
De-serializes configuration.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition disk.c:235
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition disk.c:720
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:40
@ 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:213
struct ConfigFile * prev
bool have_content_hash
Whether content_hash is available.
unsigned int level
Level in the tree of loaded config files.
struct GNUNET_HashCode content_hash
Hash of the file contents seen while parsing.
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...
bool diagnostics
Enable diagnostics.

References _, cfg, ConfigFile::content_hash, GNUNET_CONFIGURATION_Handle::current_nest_level, GNUNET_CONFIGURATION_Handle::diagnostics, GNUNET_CONFIGURATION_Handle::dirty, filename, fs, GNUNET_break, GNUNET_CONFIGURATION_deserialize(), GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CRYPTO_hash(), GNUNET_DISK_file_size(), GNUNET_DISK_fn_read(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_new, GNUNET_NO, GNUNET_strdup, GNUNET_STRINGS_filename_expand(), GNUNET_SYSERR, GNUNET_YES, ConfigFile::have_content_hash, 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 1277 of file configuration.c.

1279{
1280 char *mem;
1281 char *cbuf;
1282 char *val;
1283 char *pos;
1284 size_t m_size;
1285 size_t c_size;
1286
1287 /* Pass1 : calculate the buffer size required */
1288 m_size = 0;
1289 for (struct ConfigSection *sec = cfg->sections;
1290 NULL != sec;
1291 sec = sec->next)
1292 {
1293 if (sec->inaccessible && (NULL == sec->entries))
1294 continue;
1295 /* For each section we need to add 3 characters: {'[',']','\n'} */
1296 m_size += strlen (sec->name) + 3;
1297 for (struct ConfigEntry *ent = sec->entries;
1298 NULL != ent;
1299 ent = ent->next)
1300 {
1301 if (do_skip (sec->name,
1302 ent->key))
1303 continue;
1304 if (NULL != ent->val)
1305 {
1306 /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */
1307 pos = ent->val;
1308 while (NULL != (pos = strstr (pos, "\n")))
1309 {
1310 m_size++;
1311 pos++;
1312 }
1313 /* For each key = value pair we need to add 4 characters (2
1314 spaces and 1 equal-to character and 1 new line) */
1315 m_size += strlen (ent->key) + strlen (ent->val) + 4;
1316 }
1317 }
1318 /* A new line after section end */
1319 m_size++;
1320 }
1321
1322 /* Pass2: Allocate memory and write the configuration to it */
1323 mem = GNUNET_malloc (m_size);
1324 c_size = 0;
1325 *size = c_size;
1326 for (struct ConfigSection *sec = cfg->sections;
1327 NULL != sec;
1328 sec = sec->next)
1329 {
1330 int len;
1331
1332 len = GNUNET_asprintf (&cbuf,
1333 "[%s]\n",
1334 sec->name);
1335 GNUNET_assert (0 < len);
1336 GNUNET_memcpy (mem + c_size,
1337 cbuf,
1338 len);
1339 c_size += len;
1340 GNUNET_free (cbuf);
1341 for (struct ConfigEntry *ent = sec->entries;
1342 NULL != ent;
1343 ent = ent->next)
1344 {
1345 if (do_skip (sec->name,
1346 ent->key))
1347 continue;
1348 if (NULL != ent->val)
1349 {
1350 val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1351 strcpy (val, ent->val);
1352 while (NULL != (pos = strstr (val, "\n")))
1353 {
1354 memmove (&pos[2], &pos[1], strlen (&pos[1]));
1355 pos[0] = '\\';
1356 pos[1] = 'n';
1357 }
1358 len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
1359 GNUNET_free (val);
1360 GNUNET_memcpy (mem + c_size, cbuf, len);
1361 c_size += len;
1362 GNUNET_free (cbuf);
1363 }
1364 }
1365 GNUNET_memcpy (mem + c_size, "\n", 1);
1366 c_size++;
1367 }
1368 GNUNET_assert (c_size == m_size);
1369 *size = c_size;
1370 return mem;
1371}
static bool do_skip(const char *sec, const char *key)
Should we skip this configuration entry when serializing?
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static unsigned int size
Size of the "table".
Definition peer.c:68
configuration entry

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

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

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

◆ GNUNET_CONFIGURATION_serialize_diagnostics()

char * GNUNET_CONFIGURATION_serialize_diagnostics ( const struct GNUNET_CONFIGURATION_Handle *  cfg)

Serializes the given configuration with diagnostics information.

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

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

Definition at line 1600 of file configuration.c.

1602{
1603 return serialize_diagnostics (cfg,
1604 false);
1605}
static char * serialize_diagnostics(const struct GNUNET_CONFIGURATION_Handle *cfg, bool verbose)
Serialize configuration diagnostics.

References cfg, and serialize_diagnostics().

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_serialize_diagnostics_verbose()

char * GNUNET_CONFIGURATION_serialize_diagnostics_verbose ( const struct GNUNET_CONFIGURATION_Handle *  cfg)

Serializes the given configuration with verbose diagnostics information, including all source definitions of each value.

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

1611{
1612 return serialize_diagnostics (cfg,
1613 true);
1614}

References cfg, and serialize_diagnostics().

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_clean_file()

enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_clean_file ( const struct GNUNET_CONFIGURATION_Handle *  cfg,
const char *  filename,
GNUNET_CONFIGURATION_CleanCallback  cb,
void *  cb_cls,
unsigned int *  removed 
)

Remove redundant option definitions from a parsed configuration file.

Only complete assignment lines in filename are removed; formatting, comments and directives otherwise remain byte-for-byte unchanged. The configuration must have had diagnostics enabled before it was loaded. The operation fails if the file changed since it was parsed.

Parameters
cfgparsed configuration
filenametarget configuration file
cbcallback invoked after a successful update, may be NULL
cb_clsclosure for cb
removedset to the number of removed definitions, may be NULL
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 1909 of file configuration.c.

1915{
1916 struct CleanLine *lines = NULL;
1917 unsigned int lines_length = 0;
1918 const struct ConfigFile *parsed_file = NULL;
1919 char *target;
1920 char *contents = NULL;
1921 char *cleaned = NULL;
1922 size_t size;
1923 size_t cleaned_size = 0;
1925
1926 if (NULL != removed)
1927 *removed = 0;
1928 if ( (! cfg->diagnostics) ||
1929 (NULL == filename) )
1930 return GNUNET_SYSERR;
1932 if (NULL == target)
1933 return GNUNET_SYSERR;
1934
1935 for (const struct ConfigFile *cf = cfg->loaded_files_head;
1936 NULL != cf;
1937 cf = cf->next)
1938 {
1939 char *source;
1940
1941 if (! cf->have_content_hash)
1942 continue;
1943 source = GNUNET_STRINGS_filename_expand (cf->source_filename);
1944 if ( (NULL != source) &&
1945 (0 == strcmp (source,
1946 target)) )
1947 parsed_file = cf;
1949 }
1950 if (NULL == parsed_file)
1951 {
1953 "Configuration file `%s' was not parsed with diagnostics enabled\n",
1954 target);
1955 goto cleanup;
1956 }
1957 if (GNUNET_OK != read_file (target,
1958 &contents,
1959 &size))
1960 {
1962 "Configuration file `%s' changed since it was parsed\n",
1963 target);
1964 goto cleanup;
1965 }
1966 {
1967 struct GNUNET_HashCode actual;
1968
1969 GNUNET_CRYPTO_hash (contents,
1970 size,
1971 &actual);
1972 if (0 != GNUNET_memcmp (&actual,
1973 &parsed_file->content_hash))
1974 {
1976 "Configuration file `%s' changed since it was parsed\n",
1977 target);
1978 goto cleanup;
1979 }
1980 }
1981
1982 /* First mark every target definition that has an exact duplicate at a
1983 distinct source location. */
1984 for (const struct ConfigSection *sec = cfg->sections;
1985 NULL != sec;
1986 sec = sec->next)
1987 for (const struct ConfigEntry *ent = sec->entries;
1988 NULL != ent;
1989 ent = ent->next)
1990 for (const struct ConfigSource *source = ent->sources;
1991 NULL != source;
1992 source = source->next)
1993 {
1994 bool duplicate = false;
1995 struct CleanLine line;
1996
1997 if (0 != strcmp (source->filename,
1998 target))
1999 continue;
2000 for (const struct ConfigSource *other = ent->sources;
2001 NULL != other;
2002 other = other->next)
2003 {
2004 if ( (0 == strcmp (source->value,
2005 other->value)) &&
2006 ( (source->lineno != other->lineno) ||
2007 (0 != strcmp (source->filename,
2008 other->filename)) ) )
2009 {
2010 duplicate = true;
2011 break;
2012 }
2013 }
2014 if ( (! duplicate) ||
2015 (NULL != find_clean_line (lines,
2016 lines_length,
2017 source->lineno)) )
2018 continue;
2019 line.section = sec->name;
2020 line.option = ent->key;
2021 line.line = source->lineno;
2022 line.remove = true;
2023 GNUNET_array_append (lines,
2024 lines_length,
2025 line);
2026 }
2027
2028 /* Keep the highest-precedence target duplicate needed to preserve every
2029 effective value after all of the tentative removals. */
2030 for (const struct ConfigSection *sec = cfg->sections;
2031 NULL != sec;
2032 sec = sec->next)
2033 for (const struct ConfigEntry *ent = sec->entries;
2034 NULL != ent;
2035 ent = ent->next)
2036 {
2037 const struct ConfigSource *survivor = NULL;
2038
2039 for (const struct ConfigSource *source = ent->sources;
2040 NULL != source;
2041 source = source->next)
2043 target,
2044 lines,
2045 lines_length))
2046 {
2047 survivor = source;
2048 break;
2049 }
2050 if ( (NULL != survivor) &&
2051 (0 == strcmp (survivor->value,
2052 ent->val)) )
2053 continue;
2054 for (const struct ConfigSource *source = ent->sources;
2055 NULL != source;
2056 source = source->next)
2057 {
2058 struct CleanLine *line;
2059
2060 if ( (0 != strcmp (source->filename,
2061 target)) ||
2062 (0 != strcmp (source->value,
2063 ent->val)) )
2064 continue;
2065 line = find_clean_line (lines,
2066 lines_length,
2067 source->lineno);
2068 if ( (NULL != line) && line->remove)
2069 {
2070 line->remove = false;
2071 break;
2072 }
2073 }
2074 }
2075
2076 if (lines_length > 1)
2077 qsort (lines,
2078 lines_length,
2079 sizeof (*lines),
2081 {
2082 unsigned int remove_count = 0;
2083
2084 for (unsigned int i = 0; i < lines_length; i++)
2085 if (lines[i].remove)
2086 remove_count++;
2087 if (0 == remove_count)
2088 {
2089 if (NULL != removed)
2090 *removed = 0;
2091 ret = GNUNET_OK;
2092 goto cleanup;
2093 }
2094
2095 cleaned = GNUNET_malloc (size);
2096 for (size_t offset = 0, line_number = 1; offset < size; line_number++)
2097 {
2098 size_t end = offset;
2099 struct CleanLine *line;
2100
2101 while ( (end < size) && ('\n' != contents[end]) )
2102 end++;
2103 if (end < size)
2104 end++;
2105 line = find_clean_line (lines,
2106 lines_length,
2107 (unsigned int) line_number);
2108 if ( (NULL == line) || (! line->remove) )
2109 {
2110 GNUNET_memcpy (&cleaned[cleaned_size],
2111 &contents[offset],
2112 end - offset);
2113 cleaned_size += end - offset;
2114 }
2115 offset = end;
2116 }
2117 if (GNUNET_OK !=
2118 write_buffer_atomic (target,
2119 cleaned,
2120 cleaned_size,
2121 &parsed_file->content_hash))
2122 goto cleanup;
2123 if (NULL != removed)
2124 *removed = remove_count;
2125 if (NULL != cb)
2126 for (unsigned int i = 0; i < lines_length; i++)
2127 if (lines[i].remove)
2128 cb (cb_cls,
2129 lines[i].section,
2130 lines[i].option,
2131 lines[i].line);
2132 ret = GNUNET_OK;
2133 }
2134
2135cleanup:
2136 GNUNET_free (cleaned);
2137 GNUNET_free (contents);
2138 GNUNET_array_grow (lines,
2139 lines_length,
2140 0);
2141 GNUNET_free (target);
2142 return ret;
2143}
static bool source_is_removed(const struct ConfigSource *source, const char *target, struct CleanLine *lines, unsigned int lines_length)
Return whether a source is a target line currently marked for removal.
static struct CleanLine * find_clean_line(struct CleanLine *lines, unsigned int lines_length, unsigned int line)
Find a cleanup record for a physical line.
static int clean_line_cmp(const void *a, const void *b)
Sort cleanup records by source line.
static enum GNUNET_GenericReturnValue read_file(const char *filename, char **contents, size_t *size)
static enum GNUNET_GenericReturnValue write_buffer_atomic(const char *filename, const char *contents, size_t size, const struct GNUNET_HashCode *expected_hash)
Atomically replace a file with the given bytes.
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 GstElement * source
Appsrc instance into which we write data for the pipeline.
static void cleanup()
Cleanup task.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
One physical assignment line considered for removal.
const char * option
const char * section
source location of a configuration value
char * value
Value as normalized by the configuration parser.
A 512-bit hashcode.

References cfg, clean_line_cmp(), cleanup(), ConfigFile::content_hash, GNUNET_CONFIGURATION_Handle::diagnostics, end, filename, find_clean_line(), GNUNET_array_append, GNUNET_array_grow, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_malloc, GNUNET_memcmp, GNUNET_memcpy, GNUNET_OK, GNUNET_STRINGS_filename_expand(), GNUNET_SYSERR, line, GNUNET_CONFIGURATION_Handle::loaded_files_head, LOG, CleanLine::option, read_file(), CleanLine::remove, ret, CleanLine::section, GNUNET_CONFIGURATION_Handle::sections, size, source, source_is_removed(), ConfigSource::value, and write_buffer_atomic().

Referenced by main().

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

835{
836 size_t line_size;
837 unsigned int nr;
838 size_t r_bytes;
839 size_t to_read;
841 char *section;
842 char *eq;
843 char *tag;
844 char *value;
845 char *line_orig = NULL;
846
847 ret = GNUNET_OK;
848 section = NULL;
849 nr = 0;
850 r_bytes = 0;
851 while (r_bytes < size)
852 {
853 const char *pos;
854 char *line;
855 bool emptyline;
856
857 GNUNET_free (line_orig);
858 /* fgets-like behaviour on buffer */
859 to_read = size - r_bytes;
860 pos = memchr (&mem[r_bytes], '\n', to_read);
861 if (NULL == pos)
862 {
863 line_orig = GNUNET_strndup (&mem[r_bytes],
864 line_size = to_read);
865 r_bytes += line_size;
866 }
867 else
868 {
869 line_orig = GNUNET_strndup (&mem[r_bytes],
870 line_size = (pos - &mem[r_bytes]));
871 r_bytes += line_size + 1;
872 }
873 line = line_orig;
874 /* increment line number */
875 nr++;
876 /* tabs and '\r' are whitespace */
877 emptyline = GNUNET_YES;
878 for (size_t i = 0; i < line_size; i++)
879 {
880 if (line[i] == '\t')
881 line[i] = ' ';
882 if (line[i] == '\r')
883 line[i] = ' ';
884 if (' ' != line[i])
885 emptyline = GNUNET_NO;
886 }
887 /* ignore empty lines */
888 if (GNUNET_YES == emptyline)
889 continue;
890
891 /* remove tailing whitespace */
892 for (size_t i = line_size - 1;
893 (i >= 1) && (isspace ((unsigned char) line[i]));
894 i--)
895 line[i] = '\0';
896
897 /* remove leading whitespace */
898 for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++)
899 ;
900
901 /* ignore comments */
902 if ( ('#' == line[0]) ||
903 ('%' == line[0]) )
904 continue;
905
906 /* Handle special directives. */
907 if ('@' == line[0])
908 {
909 char *end = strchr (line + 1, '@');
910 char *directive;
911 enum GNUNET_GenericReturnValue directive_ret;
912
913 if (NULL != cfg->restrict_section)
914 {
916 "Illegal directive in line %u (parsing restricted section %s)\n",
917 nr,
920 break;
921 }
922
923 if (NULL == end)
924 {
926 "Bad directive in line %u\n",
927 nr);
929 break;
930 }
931 *end = '\0';
932 directive = line + 1;
933
934 if (0 == strcasecmp (directive,
935 "INLINE"))
936 {
937 const char *path = end + 1;
938
939 /* Skip space before path */
940 for (; isspace (*path); path++)
941 ;
942
943 directive_ret = handle_inline (cfg,
944 path,
945 false,
946 NULL,
947 source_filename,
948 nr);
949 }
950 else if (0 == strcasecmp (directive,
951 "INLINE-MATCHING"))
952 {
953 const char *path = end + 1;
954
955 /* Skip space before path */
956 for (; isspace (*path); path++)
957 ;
958
959 directive_ret = handle_inline (cfg,
960 path,
961 true,
962 NULL,
963 source_filename,
964 nr);
965 }
966 else if (0 == strcasecmp (directive,
967 "INLINE-SECRET"))
968 {
969 char *secname = end + 1;
970 char *secname_end;
971 const char *path;
972
973 /* Skip space before secname */
974 for (; isspace (*secname); secname++)
975 ;
976
977 secname_end = strchr (secname, ' ');
978
979 if (NULL == secname_end)
980 {
982 "Bad inline-secret directive in line %u\n",
983 nr);
985 break;
986 }
987 *secname_end = '\0';
988 path = secname_end + 1;
989
990 /* Skip space before path */
991 for (; isspace (*path); path++)
992 ;
993
994 directive_ret = handle_inline (cfg,
995 path,
996 false,
997 secname,
998 source_filename,
999 nr);
1000 }
1001 else
1002 {
1004 "Unknown or malformed directive '%s' in line %u\n",
1005 directive,
1006 nr);
1008 break;
1009 }
1010 if (GNUNET_OK != directive_ret)
1011 {
1012 ret = directive_ret;
1013 break;
1014 }
1015 continue;
1016 }
1017 if ( ('[' == line[0]) &&
1018 (']' == line[line_size - 1]) )
1019 {
1020 /* [value] */
1021 line[line_size - 1] = '\0';
1022 value = &line[1];
1023 GNUNET_free (section);
1024 section = GNUNET_strdup (value);
1025 continue;
1026 }
1027 if (NULL != (eq = strchr (line, '=')))
1028 {
1029
1030 if (NULL == section)
1031 {
1033 "Syntax error while deserializing in line %u (option without section)\n",
1034 nr);
1036 break;
1037 }
1038
1039 /* tag = value */
1040 tag = GNUNET_strndup (line, eq - line);
1041 /* remove tailing whitespace */
1042 for (int i = strlen (tag) - 1;
1043 (i >= 1) && (isspace ((unsigned char) tag[i]));
1044 i--)
1045 tag[i] = '\0';
1046
1047 /* Strip whitespace */
1048 value = eq + 1;
1049 while (isspace ((unsigned char) value[0]))
1050 value++;
1051 for (int i = strlen (value) - 1;
1052 (i >= 1) && (isspace ((unsigned char) value[i]));
1053 i--)
1054 value[i] = '\0';
1055
1056 /* remove quotes */
1057 if ( ('"' == value[0]) &&
1058 ('"' == value[strlen (value) - 1]) )
1059 {
1060 value[strlen (value) - 1] = '\0';
1061 value++;
1062 }
1064 section,
1065 tag,
1066 value);
1067 if (cfg->diagnostics)
1068 {
1070 section,
1071 tag,
1072 value,
1073 source_filename
1074 ? source_filename
1075 : "<input>",
1076 nr);
1077 }
1078 GNUNET_free (tag);
1079 continue;
1080 }
1081 /* parse error */
1083 "Syntax error while deserializing in line %u\n",
1084 nr);
1086 break;
1087 }
1088 GNUNET_free (line_orig);
1089 GNUNET_free (section);
1090 GNUNET_assert ( (GNUNET_OK != ret) ||
1091 (r_bytes == size) );
1092 return ret;
1093}
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 add_entry_source(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value, const char *filename, unsigned int line)
Record the source of a configuration value.
static char * value
Value of the record to add/remove.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
const char * restrict_section
When parsing into this configuration, and this value is non-NULL, only parse sections of the same nam...

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

1825{
1827 char *cfg_buf;
1828 size_t size;
1829
1831 &size);
1833 cfg_buf,
1834 size,
1835 NULL);
1836 GNUNET_free (cfg_buf);
1838 return ret;
1839}
char * GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
Serializes the given configuration.

References cfg, GNUNET_CONFIGURATION_Handle::dirty, filename, GNUNET_CONFIGURATION_serialize(), GNUNET_free, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, ret, size, and write_buffer_atomic().

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

2360{
2361 int ret;
2362 struct GNUNET_CONFIGURATION_Handle *diff;
2363
2364 diff = GNUNET_CONFIGURATION_get_diff (cfg_default, cfg_new);
2367 return ret;
2368}
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 2339 of file configuration.c.

2342{
2343 struct DiffHandle diffHandle;
2344
2345 GNUNET_break (cfg_default->pd == cfg_new->pd);
2346 diffHandle.cfgDiff = GNUNET_CONFIGURATION_create (cfg_new->pd);
2347 diffHandle.cfg_default = cfg_default;
2350 &diffHandle);
2351 return diffHandle.cfgDiff;
2352}
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 1235 of file configuration.c.

1236{
1237 return cfg->dirty;
1238}

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

379{
382
384 if (GNUNET_OK !=
386 filename))
387 {
388 GNUNET_break (0);
390 return GNUNET_SYSERR;
391 }
392 ret = cb (cb_cls,
393 cfg);
395 return ret;
396}
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_OS_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 251 of file configuration.c.

253{
254 cfg->diagnostics = true;
255}

References cfg, and GNUNET_CONFIGURATION_Handle::diagnostics.

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

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

3663{
3664 return cfg->pd;
3665}

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

2151{
2152 for (struct ConfigSection *spos = cfg->sections;
2153 NULL != spos;
2154 spos = spos->next)
2155 for (struct ConfigEntry *epos = spos->entries;
2156 NULL != epos;
2157 epos = epos->next)
2158 if (NULL != epos->val)
2159 iter (iter_cls,
2160 spos->name,
2161 epos->key,
2162 epos->val);
2163}

References cfg, and GNUNET_CONFIGURATION_Handle::sections.

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

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_iterate_sections()

void GNUNET_CONFIGURATION_iterate_sections ( const struct GNUNET_CONFIGURATION_Handle *  cfg,
GNUNET_CONFIGURATION_SectionIterator  iter,
void *  iter_cls 
)

Iterate over all sections in the configuration.

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

Definition at line 2200 of file configuration.c.

2204{
2205 struct ConfigSection *spos;
2206 struct ConfigSection *next;
2207
2208 next = cfg->sections;
2209 while (NULL != next)
2210 {
2211 spos = next;
2212 next = spos->next;
2213 if (spos->inaccessible && (NULL == spos->entries))
2214 continue;
2215 iter (iter_cls,
2216 spos->name);
2217 }
2218}
struct ConfigEntry * entries
entries in the section
bool inaccessible
Is the configuration section marked as inaccessible?
struct ConfigSection * next
This is a linked list.

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

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

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_remove_section()

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

Remove the given section and all options in it.

Parameters
cfgconfiguration to inspect
sectionname of the section to remove

Definition at line 2222 of file configuration.c.

2224{
2225 struct ConfigSection *spos;
2226 struct ConfigSection *prev;
2227 struct ConfigEntry *ent;
2228
2229 prev = NULL;
2230 spos = cfg->sections;
2231 while (NULL != spos)
2232 {
2233 if (0 == strcasecmp (section,
2234 spos->name))
2235 {
2236 if (NULL == prev)
2237 cfg->sections = spos->next;
2238 else
2239 prev->next = spos->next;
2240 while (NULL != (ent = spos->entries))
2241 {
2242 struct ConfigSource *source;
2243
2244 spos->entries = ent->next;
2245 GNUNET_free (ent->key);
2246 GNUNET_free (ent->val);
2247 while (NULL != (source = ent->sources))
2248 {
2249 ent->sources = source->next;
2250 GNUNET_free (source->value);
2251 GNUNET_free (source->filename);
2253 }
2254 GNUNET_free (ent);
2255 cfg->dirty = GNUNET_YES;
2256 }
2257 GNUNET_free (spos->name);
2261 GNUNET_free (spos);
2262 return;
2263 }
2264 prev = spos;
2265 spos = spos->next;
2266 }
2267}
struct ConfigEntry * next
This is a linked list.
char * key
key for this entry
struct ConfigSource * sources
Source definitions retained for diagnostics.
char * val
current, committed value
char * hint_inlined_from_filename
For secret sections: Where was this inlined from?
char * hint_secret_filename
Diagnostics hint for the secret file.
char * hint_secret_stat
Extra information regarding permissions of the secret file.
struct ConfigSource * next
Sources are ordered from highest to lowest precedence.

References cfg, GNUNET_CONFIGURATION_Handle::dirty, ConfigSection::entries, GNUNET_free, GNUNET_YES, ConfigSection::hint_inlined_from_filename, ConfigSection::hint_secret_filename, ConfigSection::hint_secret_stat, ConfigEntry::key, ConfigSection::name, ConfigSource::next, ConfigEntry::next, ConfigSection::next, GNUNET_CONFIGURATION_Handle::sections, source, ConfigEntry::sources, 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 2434 of file configuration.c.

2439{
2440 struct ConfigEntry *e;
2441 char dummy[2];
2442
2443 if (NULL == (e = find_entry (cfg,
2444 section,
2445 option)))
2446 return GNUNET_NO;
2447 if (NULL == e->val)
2448 return GNUNET_NO;
2449 if (1 != sscanf (e->val,
2450 "%llu%1s",
2451 number,
2452 dummy))
2453 return GNUNET_SYSERR;
2454 return GNUNET_OK;
2455}
static struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
uint32_t number

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

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

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

◆ GNUNET_CONFIGURATION_set_value_float()

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

Set a configuration value that should be a float.

Note that this possibly truncates your float value.

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

Definition at line 2459 of file configuration.c.

2463{
2464 char s[64];
2465
2466 /* See: #9369 */
2467 const locale_t cl = newlocale (LC_NUMERIC_MASK,
2468 "C",
2469 (locale_t) 0);
2470 locale_t old_locale = uselocale (cl);
2471 GNUNET_snprintf (s,
2472 64,
2473 "%f",
2474 (double) number);
2475 uselocale (old_locale);
2477 section,
2478 option,
2479 s);
2480}
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 2484 of file configuration.c.

2489{
2490 struct ConfigEntry *e;
2491 char dummy[2];
2492
2493 if (NULL == (e = find_entry (cfg,
2494 section,
2495 option)))
2496 return GNUNET_NO;
2497 if (NULL == e->val)
2498 return GNUNET_NO;
2499 /* See #9369 */
2500 {
2501 const locale_t cl = newlocale (LC_NUMERIC_MASK,
2502 "C",
2503 (locale_t) 0);
2504 locale_t old_locale = uselocale (cl);
2505
2506 if (1 != sscanf (e->val,
2507 "%f%1s",
2508 number,
2509 dummy))
2510 return GNUNET_SYSERR;
2511 uselocale (old_locale);
2512 }
2513 return GNUNET_OK;
2514}

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

2523{
2524 struct ConfigEntry *e;
2525 int ret;
2526
2527 if (NULL == (e = find_entry (cfg,
2528 section,
2529 option)))
2530 return GNUNET_NO;
2531 if (NULL == e->val)
2532 return GNUNET_NO;
2534 time);
2535 if (GNUNET_OK != ret)
2537 section,
2538 option,
2539 _ ("Not a valid relative time specification"));
2540 return ret;
2541}
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_time_to_relative(const char *fancy_time, struct GNUNET_TIME_Relative *rtime)
Convert a given fancy human-readable time to our internal representation.
Definition strings.c:259

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

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

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

◆ GNUNET_CONFIGURATION_get_value_size()

enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_size ( const struct GNUNET_CONFIGURATION_Handle *  cfg,
const char *  section,
const char *  option,
unsigned long long *  size 
)

Get a configuration value that should be a size in bytes.

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

Definition at line 2545 of file configuration.c.

2550{
2551 struct ConfigEntry *e;
2552
2553 if (NULL == (e = find_entry (cfg,
2554 section,
2555 option)))
2556 return GNUNET_NO;
2557 if (NULL == e->val)
2558 return GNUNET_NO;
2560 size);
2561}
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_size_to_bytes(const char *fancy_size, unsigned long long *size)
Convert a given fancy human-readable size to bytes.
Definition strings.c:235

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

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

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

◆ GNUNET_CONFIGURATION_have_value()

enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value ( const struct GNUNET_CONFIGURATION_Handle *  cfg,
const char *  section,
const char *  option 
)

Test if we have a value for a particular option.

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

Definition at line 2668 of file configuration.c.

2671{
2672 struct ConfigEntry *e;
2673
2674 if ( (NULL == (e = find_entry (cfg,
2675 section,
2676 option))) ||
2677 (NULL == e->val) )
2678 return GNUNET_NO;
2679 return GNUNET_YES;
2680}

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

2580{
2581 struct ConfigEntry *e;
2582
2583 if ( (NULL == (e = find_entry (cfg,
2584 section,
2585 option))) ||
2586 (NULL == e->val) )
2587 {
2588 *value = NULL;
2589 return GNUNET_NO;
2590 }
2591 *value = GNUNET_strdup (e->val);
2592 return GNUNET_OK;
2593}

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

Referenced by advertise_dns_exit(), check_authorization(), check_config(), client_connect_cb(), communicator_start(), DHTU_ip_init(), expand_dollar(), get_bootstrap_server(), get_server_addresses(), get_server_addresses(), gg_load_configuration(), GNUNET_CLIENT_connect(), GNUNET_CLIENT_test(), GNUNET_CONFIGURATION_append_value_filename(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_get_data(), GNUNET_CONFIGURATION_get_suid_binary_path(), 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_PQ_init(), GNUNET_SOCKS_do_connect(), GNUNET_TESTING_get_topo_from_string_(), handle_ego_delete(), handle_ego_rename(), handle_register(), handle_uri(), identity_continuation(), load_member_session(), load_member_session_next(), login_redirect(), mq_init(), mq_init(), process_acl4(), process_acl6(), read_service_conf(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), run(), setup_exit_helper_args(), setup_service(), sock_read(), sock_read(), start_arm_service(), start_peer_run(), start_process(), test_icmp_client(), test_icmp_server(), test_service_configuration(), token_endpoint(), and update_config_sections().

Here is the call graph for this function:

◆ GNUNET_CONFIGURATION_get_value_filename()

enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename ( const struct GNUNET_CONFIGURATION_Handle *  cfg,
const char *  section,
const char *  option,
char **  value 
)

Get a configuration value that should be the name of a file or directory.

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

Definition at line 2879 of file configuration.c.

2884{
2885 char *tmp;
2887
2889 section,
2890 option,
2891 &tmp);
2892 if (GNUNET_OK != ret)
2893 {
2895 "Failed to retrieve filename\n");
2896 *value = NULL;
2897 return ret;
2898 }
2900 tmp);
2902 GNUNET_free (tmp);
2903 if (*value == NULL)
2904 return GNUNET_SYSERR;
2905 return GNUNET_OK;
2906}
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
char * GNUNET_CONFIGURATION_expand_dollar(const struct GNUNET_CONFIGURATION_Handle *cfg, char *orig)
Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" where either in the "PATHS" section or...

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

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

Here is the call graph for this function:

◆ GNUNET_CONFIGURATION_iterate_value_filenames()

int GNUNET_CONFIGURATION_iterate_value_filenames ( const struct GNUNET_CONFIGURATION_Handle *  cfg,
const char *  section,
const char *  option,
GNUNET_FileNameCallback  cb,
void *  cb_cls 
)

Iterate over the set of filenames stored in a configuration value.

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

Definition at line 2938 of file configuration.c.

2944{
2945 char *list;
2946 char *pos;
2947 char *end;
2948 char old;
2949 int ret;
2950
2951 if (GNUNET_OK !=
2953 section,
2954 option,
2955 &list))
2956 return 0;
2957 GNUNET_assert (list != NULL);
2958 ret = 0;
2959 pos = list;
2960 while (1)
2961 {
2962 while (pos[0] == ' ')
2963 pos++;
2964 if (strlen (pos) == 0)
2965 break;
2966 end = pos + 1;
2967 while ((end[0] != ' ') && (end[0] != '\0'))
2968 {
2969 if (end[0] == '\\')
2970 {
2971 switch (end[1])
2972 {
2973 case '\\':
2974 case ' ':
2975 memmove (end, &end[1], strlen (&end[1]) + 1);
2976
2977 case '\0':
2978 /* illegal, but just keep it */
2979 break;
2980
2981 default:
2982 /* illegal, but just ignore that there was a '/' */
2983 break;
2984 }
2985 }
2986 end++;
2987 }
2988 old = end[0];
2989 end[0] = '\0';
2990 if (strlen (pos) > 0)
2991 {
2992 ret++;
2993 if ( (NULL != cb) &&
2994 (GNUNET_OK != cb (cb_cls,
2995 pos)))
2996 {
2998 break;
2999 }
3000 }
3001 if (old == '\0')
3002 break;
3003 pos = end + 1;
3004 }
3005 GNUNET_free (list);
3006 return ret;
3007}
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 2167 of file configuration.c.

2172{
2173 struct ConfigSection *spos;
2174
2175 spos = cfg->sections;
2176 while ((spos != NULL) && (0 != strcasecmp (spos->name, section)))
2177 spos = spos->next;
2178 if (NULL == spos)
2179 return;
2180 for (struct ConfigEntry *epos = spos->entries;
2181 NULL != epos;
2182 epos = epos->next)
2183 if (NULL != epos->val)
2184 iter (iter_cls,
2185 spos->name,
2186 epos->key,
2187 epos->val);
2188 if (spos->inaccessible)
2189 {
2191 "Section '%s' is marked as inaccessible, because a configuration "
2192 "file that contains the section can't be read.\n",
2193 section);
2194 return;
2195 }
2196}

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

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

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_value_choice()

enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_choice ( const struct GNUNET_CONFIGURATION_Handle *  cfg,
const char *  section,
const char *  option,
const char *const *  choices,
const char **  value 
)

Get a configuration value that should be in a set of predefined strings.

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

Definition at line 2597 of file configuration.c.

2603{
2604 struct ConfigEntry *e;
2605 unsigned int i;
2606
2607 if (NULL == (e = find_entry (cfg,
2608 section,
2609 option)))
2610 return GNUNET_NO;
2611 for (i = 0; NULL != choices[i]; i++)
2612 if (0 == strcasecmp (choices[i], e->val))
2613 break;
2614 if (NULL == choices[i])
2615 {
2617 _ ("Configuration value '%s' for '%s'"
2618 " in section '%s' is not in set of legal choices\n"),
2619 e->val,
2620 option,
2621 section);
2622 return GNUNET_SYSERR;
2623 }
2624 *value = choices[i];
2625 return GNUNET_OK;
2626}

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

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

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

◆ GNUNET_CONFIGURATION_get_value_yesno()

enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno ( const struct GNUNET_CONFIGURATION_Handle *  cfg,
const char *  section,
const char *  option 
)

Get a configuration value that should be in a set of "YES" or "NO".

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

Definition at line 2910 of file configuration.c.

2914{
2915 static const char *yesno[] = {
2916 "YES",
2917 "NO",
2918 NULL
2919 };
2920 const char *val;
2922
2923 ret =
2925 section,
2926 option,
2927 yesno,
2928 &val);
2929 if (GNUNET_OK != ret)
2930 return ret;
2931 if (val == yesno[0])
2932 return GNUNET_YES;
2933 return GNUNET_NO;
2934}
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_choice(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *const *choices, const char **value)
Get a configuration value that should be in a set of predefined strings.

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

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

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

◆ GNUNET_CONFIGURATION_get_data()

enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_data ( const struct GNUNET_CONFIGURATION_Handle *  cfg,
const char *  section,
const char *  option,
void *  buf,
size_t  buf_size 
)

Get Crockford32-encoded fixed-size binary data from a configuration.

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

Definition at line 2630 of file configuration.c.

2635{
2636 char *enc;
2637 int res;
2638 size_t data_size;
2639
2640 if (GNUNET_OK !=
2641 (res =
2643 section,
2644 option,
2645 &enc)))
2646 return res;
2647 data_size = (strlen (enc) * 5) / 8;
2648 if (data_size != buf_size)
2649 {
2650 GNUNET_free (enc);
2651 return GNUNET_SYSERR;
2652 }
2653 if (GNUNET_OK !=
2655 strlen (enc),
2656 buf,
2657 buf_size))
2658 {
2659 GNUNET_free (enc);
2660 return GNUNET_SYSERR;
2661 }
2662 GNUNET_free (enc);
2663 return GNUNET_OK;
2664}
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:843

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

2857{
2858 char *dup;
2859 size_t i;
2860 size_t len;
2861
2862 for (i = 0; '\0' != orig[i]; i++)
2863 {
2864 if ('$' != orig[i])
2865 continue;
2866 dup = GNUNET_strdup (orig + i);
2867 dup = expand_dollar (cfg, dup, 0);
2868 GNUNET_assert (NULL != dup); /* make compiler happy */
2869 len = strlen (dup) + 1;
2870 orig = GNUNET_realloc (orig, i + len);
2871 GNUNET_memcpy (orig + i, dup, len);
2872 GNUNET_free (dup);
2873 }
2874 return orig;
2875}
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 2415 of file configuration.c.

2419{
2420 char s[64];
2421
2422 GNUNET_snprintf (s,
2423 64,
2424 "%llu",
2425 number);
2427 section,
2428 option,
2429 s);
2430}

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

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

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

◆ GNUNET_CONFIGURATION_set_value_string()

void GNUNET_CONFIGURATION_set_value_string ( struct GNUNET_CONFIGURATION_Handle *  cfg,
const char *  section,
const char *  option,
const char *  value 
)

Set a configuration value that should be a string.

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

Definition at line 2372 of file configuration.c.

2377{
2378 struct ConfigSection *sec;
2379 struct ConfigEntry *e;
2380 char *nv;
2381
2382 e = find_entry (cfg, section, option);
2383 if (NULL != e)
2384 {
2385 if (NULL == value)
2386 {
2387 GNUNET_free (e->val);
2388 e->val = NULL;
2389 }
2390 else
2391 {
2392 nv = GNUNET_strdup (value);
2393 GNUNET_free (e->val);
2394 e->val = nv;
2395 }
2396 return;
2397 }
2398 sec = find_section (cfg, section);
2399 if (sec == NULL)
2400 {
2401 sec = GNUNET_new (struct ConfigSection);
2402 sec->name = GNUNET_strdup (section);
2403 sec->next = cfg->sections;
2404 cfg->sections = sec;
2405 }
2406 e = GNUNET_new (struct ConfigEntry);
2407 e->key = GNUNET_strdup (option);
2408 e->val = GNUNET_strdup (value);
2409 e->next = sec->entries;
2410 sec->entries = e;
2411}
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(), copy_entry_with_sources(), 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(), identity_cb(), next_phase(), process_if(), result_callback(), run(), run(), save_member(), save_member_session(), save_operation(), set_external_ipv4(), set_value(), start_peer_run(), test_local_ip(), test_upnpc(), update_config(), update_config_sections(), and update_enable_upnpc_option().

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

◆ GNUNET_CONFIGURATION_remove_value_filename()

enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_remove_value_filename ( struct GNUNET_CONFIGURATION_Handle *  cfg,
const char *  section,
const char *  option,
const char *  value 
)

Remove a filename from a configuration value that represents a list of filenames.

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

Definition at line 3106 of file configuration.c.

3111{
3112 char *list;
3113 char *pos;
3114 char *end;
3115 char *match;
3116 char old;
3117
3118 if (GNUNET_OK !=
3120 section,
3121 option,
3122 &list))
3123 return GNUNET_NO;
3124 match = escape_name (value);
3125 pos = list;
3126 while (1)
3127 {
3128 while (pos[0] == ' ')
3129 pos++;
3130 if (strlen (pos) == 0)
3131 break;
3132 end = pos + 1;
3133 while ((end[0] != ' ') && (end[0] != '\0'))
3134 {
3135 if (end[0] == '\\')
3136 {
3137 switch (end[1])
3138 {
3139 case '\\':
3140 case ' ':
3141 end++;
3142 break;
3143
3144 case '\0':
3145 /* illegal, but just keep it */
3146 break;
3147
3148 default:
3149 /* illegal, but just ignore that there was a '/' */
3150 break;
3151 }
3152 }
3153 end++;
3154 }
3155 old = end[0];
3156 end[0] = '\0';
3157 if (0 == strcmp (pos, match))
3158 {
3159 if (old != '\0')
3160 memmove (pos,
3161 &end[1],
3162 strlen (&end[1]) + 1);
3163 else
3164 {
3165 if (pos != list)
3166 pos[-1] = '\0';
3167 else
3168 pos[0] = '\0';
3169 }
3171 section,
3172 option,
3173 list);
3174 GNUNET_free (list);
3175 GNUNET_free (match);
3176 return GNUNET_OK;
3177 }
3178 if (old == '\0')
3179 break;
3180 end[0] = old;
3181 pos = end + 1;
3182 }
3183 GNUNET_free (list);
3184 GNUNET_free (match);
3185 return GNUNET_NO;
3186}
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 3068 of file configuration.c.

3073{
3074 char *escaped;
3075 char *old;
3076 char *nw;
3077
3078 if (GNUNET_SYSERR ==
3080 section,
3081 option,
3082 &test_match,
3083 (void *) value))
3084 return GNUNET_NO; /* already exists */
3085 if (GNUNET_OK !=
3086 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
3087 old = GNUNET_strdup ("");
3088 escaped = escape_name (value);
3089 nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2);
3090 strcpy (nw, old);
3091 if (strlen (old) > 0)
3092 strcat (nw, " ");
3093 strcat (nw, escaped);
3095 section,
3096 option,
3097 nw);
3098 GNUNET_free (old);
3099 GNUNET_free (nw);
3100 GNUNET_free (escaped);
3101 return GNUNET_OK;
3102}
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 3651 of file configuration.c.

3653{
3654 GNUNET_free (cs->option);
3655 GNUNET_free (cs->section);
3656 GNUNET_free (cs->value);
3657}

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

3461{
3462 struct GNUNET_CONFIGURATION_ConfigSettings *cs = cls;
3463 struct GNUNET_CONFIGURATION_Handle *out = NULL;
3464 struct GNUNET_CONFIGURATION_Handle *ncfg = NULL;
3465
3466 (void) args;
3467 if (cs->diagnostics &&
3468 (! cfg->diagnostics))
3469 {
3470 /* Re-parse the configuration with diagnostics enabled. */
3473 if (GNUNET_OK !=
3475 cfgfile))
3476 {
3477 fprintf (stderr,
3478 _ ("Failed to load config file `%s'"),
3479 cfgfile);
3480 return;
3481 }
3482 cfg = ncfg;
3483 }
3484
3485 if (cs->full)
3486 cs->rewrite = GNUNET_YES;
3487 if (cs->list_sections)
3488 {
3489 fprintf (stderr,
3490 _ ("The following sections are available:\n"));
3493 NULL);
3494 return;
3495 }
3496 if ( (! cs->rewrite) &&
3497 (NULL == cs->section) )
3498 {
3499 char *serialization;
3500
3501 if (! cs->diagnostics)
3502 {
3503 fprintf (stderr,
3504 _ ("%s, %s or %s argument is required\n"),
3505 "--section",
3506 "--list-sections",
3507 "--diagnostics");
3509 return;
3510 }
3511 serialization = (cs->diagnostics > 1)
3514 fprintf (stdout,
3515 "%s",
3516 serialization);
3517 GNUNET_free (serialization);
3518 }
3519 else if ( (NULL != cs->section) &&
3520 (NULL == cs->value) )
3521 {
3522 if (NULL == cs->option)
3523 {
3525 cfg,
3526 cs->section,
3527 cs->is_filename
3529 : &print_option,
3530 (void *) cfg);
3531 }
3532 else
3533 {
3534 char *value;
3535
3536 if (cs->is_filename)
3537 {
3538 if (GNUNET_OK !=
3540 cs->section,
3541 cs->option,
3542 &value))
3543 {
3545 cs->section,
3546 cs->option);
3548 return;
3549 }
3550 }
3551 else
3552 {
3553 if (GNUNET_OK !=
3555 cs->section,
3556 cs->option,
3557 &value))
3558 {
3560 cs->section,
3561 cs->option);
3563 return;
3564 }
3565 }
3566 fprintf (stdout,
3567 "%s\n",
3568 value);
3570 }
3571 }
3572 else if (NULL != cs->section)
3573 {
3574 if (NULL == cs->option)
3575 {
3576 fprintf (stderr,
3577 _ ("--option argument required to set value\n"));
3579 return;
3580 }
3583 cs->section,
3584 cs->option,
3585 cs->value);
3586 cs->rewrite = GNUNET_YES;
3587 }
3588 if (cs->rewrite)
3589 {
3590 char *cfg_fn = NULL;
3591
3592 if (NULL == out)
3594
3595 if (NULL == cfgfile)
3596 {
3597 const char *xdg = getenv ("XDG_CONFIG_HOME");
3598
3599 if (NULL != xdg)
3600 GNUNET_asprintf (&cfg_fn,
3601 "%s%s%s",
3602 xdg,
3604 cfg->pd->config_file);
3605 else
3606 cfg_fn = GNUNET_strdup (cfg->pd->user_config_file);
3607 cfgfile = cfg_fn;
3608 }
3609
3610 if (! cs->full)
3611 {
3612 struct GNUNET_CONFIGURATION_Handle *def;
3613
3615 if (GNUNET_OK !=
3617 NULL))
3618 {
3619 fprintf (stderr,
3620 _ ("failed to load configuration defaults"));
3621 cs->global_ret = 1;
3624 GNUNET_free (cfg_fn);
3625 return;
3626 }
3627 if (GNUNET_OK !=
3629 out,
3630 cfgfile))
3631 cs->global_ret = 2;
3633 }
3634 else
3635 {
3636 if (GNUNET_OK !=
3638 cfgfile))
3639 cs->global_ret = 2;
3640 }
3641 GNUNET_free (cfg_fn);
3642 }
3643 if (NULL != out)
3645 if (NULL != ncfg)
3647}
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.
char * GNUNET_CONFIGURATION_serialize_diagnostics_verbose(const struct GNUNET_CONFIGURATION_Handle *cfg)
Serializes the given configuration with verbose diagnostics information, including all source definit...
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:258
#define EXIT_NOTCONFIGURED
Definition platform.h:274
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 list_sections
Whether to show the sections.
int rewrite
Should we write out the configuration file, even if no value was changed?
int is_filename
Treat option as a filename.
unsigned int diagnostics
Diagnostics verbosity.

References _, cfg, GNUNET_OS_ProjectData::config_file, GNUNET_CONFIGURATION_ConfigSettings::diagnostics, GNUNET_CONFIGURATION_Handle::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_serialize_diagnostics_verbose(), 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:

◆ GNUNET_CONFIGURATION_get_suid_binary_path()

char * GNUNET_CONFIGURATION_get_suid_binary_path ( const struct GNUNET_OS_ProjectData *  pd,
const struct GNUNET_CONFIGURATION_Handle *  cfg,
const char *  progname 
)

Given the name of a helper, service or daemon binary construct the full path to the binary using the SUID_BINARY_PATH in the PATHS section of the configuration.

If that option is not present, fall back to GNUNET_OS_get_libexec_binary_path. If progname is an absolute path, a copy of this path is returned.

Parameters
pdproject data to use to determine paths
cfgconfiguration to inspect
prognamename of the binary
Returns
full path to the binary, if possible, a copy of progname otherwise

Definition at line 3669 of file configuration.c.

3674{
3675 static char *cache;
3676 char *binary = NULL;
3677 char *path = NULL;
3678 size_t path_len;
3679
3680 if (GNUNET_YES ==
3682 GNUNET_NO,
3683 NULL,
3684 NULL))
3685 {
3686 return GNUNET_strdup (progname);
3687 }
3688 if (NULL != cache)
3689 path = cache;
3690 else
3692 "PATHS",
3693 "SUID_BINARY_PATH",
3694 &path);
3695 if ( (NULL == path) ||
3696 (0 == strlen (path)) )
3697 {
3698 if (NULL != path)
3699 GNUNET_free (path);
3700 cache = NULL;
3702 progname);
3703 }
3704 path_len = strlen (path);
3705 GNUNET_asprintf (&binary,
3706 "%s%s%s",
3707 path,
3708 (path[path_len - 1] == DIR_SEPARATOR) ? ""
3710 progname);
3711 cache = path;
3712 return binary;
3713}
char * GNUNET_OS_get_libexec_binary_path(const struct GNUNET_OS_ProjectData *pd, const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
enum GNUNET_GenericReturnValue GNUNET_STRINGS_path_is_absolute(const char *filename, int can_be_uri, int *r_is_uri, char **r_uri_scheme)
Check whether filename is absolute or not, and if it's an URI.
Definition strings.c:1012
#define DIR_SEPARATOR
Definition platform.h:166

References cfg, DIR_SEPARATOR, DIR_SEPARATOR_STR, GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_free, GNUNET_NO, GNUNET_OS_get_libexec_binary_path(), GNUNET_strdup, GNUNET_STRINGS_path_is_absolute(), and GNUNET_YES.

Referenced by GN_request_connection_reversal(), restart_nat_server(), run(), run(), and run().

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