GNUnet 0.29.1-19-g7e0f9c364
 
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 2307 of file configuration.c.

2309{
2311
2314 &copy_entry,
2315 ret);
2316 return ret;
2317}
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 3393 of file configuration.c.

3396{
3397 char *baseconfig;
3398 const char *base_config_varname;
3399
3400 if (cfg->load_called)
3401 {
3402 /* FIXME: Make this a GNUNET_assert later */
3403 GNUNET_break (0);
3405 }
3406 cfg->load_called = true;
3407 if (NULL != filename)
3408 {
3411 }
3412
3413 base_config_varname = cfg->pd->base_config_varname;
3414
3415 if ((NULL != base_config_varname)
3416 && (NULL != (baseconfig = getenv (base_config_varname))))
3417 {
3418 baseconfig = GNUNET_strdup (baseconfig);
3419 }
3420 else
3421 {
3422 char *ipath;
3423
3426 if (NULL == ipath)
3427 {
3428 GNUNET_break (0);
3429 return GNUNET_SYSERR;
3430 }
3431 GNUNET_asprintf (&baseconfig,
3432 "%s%s",
3433 ipath,
3434 "config.d");
3435 GNUNET_free (ipath);
3436 }
3437
3438 {
3439 char *dname = GNUNET_STRINGS_filename_expand (baseconfig);
3440
3441 GNUNET_free (baseconfig);
3442
3443 if ((GNUNET_YES ==
3445 GNUNET_YES)) &&
3446 (GNUNET_SYSERR ==
3448 dname)))
3449 {
3451 "Failed to load base configuration from '%s'\n",
3452 filename);
3453 GNUNET_free (dname);
3454 return GNUNET_SYSERR; /* no configuration at all found */
3455 }
3456 GNUNET_free (dname);
3457 }
3458 if ((NULL != filename) &&
3459 (GNUNET_OK !=
3461 filename)))
3462 {
3463 /* specified configuration not found */
3465 "Failed to load configuration from file '%s'\n",
3466 filename);
3467 return GNUNET_SYSERR;
3468 }
3469 if (((GNUNET_YES !=
3471 "PATHS",
3472 "DEFAULTCONFIG"))) &&
3473 (filename != NULL))
3475 "PATHS",
3476 "DEFAULTCONFIG",
3477 filename);
3478 return GNUNET_OK;
3479}
#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 3295 of file configuration.c.

3298{
3299 struct CollectFilesContext files_context = {
3300 .files = NULL,
3301 .files_length = 0,
3302 };
3303 enum GNUNET_GenericReturnValue fun_ret = GNUNET_NO;
3304
3305 if (GNUNET_SYSERR ==
3306 GNUNET_DISK_directory_scan (defaults_d,
3308 &files_context))
3309 return GNUNET_SYSERR; /* no configuration at all found */
3310 qsort (files_context.files,
3311 files_context.files_length,
3312 sizeof (char *),
3313 &pstrcmp);
3314 for (unsigned int i = 0; i < files_context.files_length; i++)
3315 {
3316 const char *ext;
3317 const char *filename = files_context.files[i];
3318
3319 /* Examine file extension */
3320 ext = strrchr (filename, '.');
3321 if ( (NULL == ext) ||
3322 (0 != strcmp (ext,
3323 ".conf")) )
3324 {
3326 "Skipping file `%s'\n",
3327 filename);
3328 fun_ret = GNUNET_OK;
3329 continue;
3330 }
3332 filename);
3333 if (fun_ret != GNUNET_OK)
3334 break;
3335 }
3336 if (files_context.files_length > 0)
3337 {
3338 for (size_t i = 0; i < files_context.files_length; i++)
3339 GNUNET_free (files_context.files[i]);
3340 GNUNET_array_grow (files_context.files,
3341 files_context.files_length,
3342 0);
3343 }
3344 return fun_ret;
3345}
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 3349 of file configuration.c.

3351{
3352 char *cfg_fn;
3353 const char *xdg = getenv ("XDG_CONFIG_HOME");
3354
3355 if (NULL != xdg)
3356 GNUNET_asprintf (&cfg_fn,
3357 "%s%s%s",
3358 xdg,
3360 pd->config_file);
3361 else
3362 cfg_fn = GNUNET_strdup (pd->user_config_file);
3363
3364 if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
3365 return cfg_fn;
3366 GNUNET_free (cfg_fn);
3367
3368 /* Fall back to /etc/ for the default configuration.
3369 Should be okay to use forward slashes here. */
3370
3371 GNUNET_asprintf (&cfg_fn,
3372 "/etc/%s",
3373 pd->config_file);
3374 if (GNUNET_OK ==
3376 return cfg_fn;
3377 GNUNET_free (cfg_fn);
3378
3379 GNUNET_asprintf (&cfg_fn,
3380 "/etc/%s/%s",
3381 pd->project_dirname,
3382 pd->config_file);
3383 if (GNUNET_OK ==
3385 return cfg_fn;
3386
3387 GNUNET_free (cfg_fn);
3388 return NULL;
3389}
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 1106 of file configuration.c.

1108{
1109 struct ConfigFile *loaded_file;
1110 uint64_t fs64;
1111 size_t fs;
1112 char *fn;
1113 char *mem;
1114 int dirty;
1116 ssize_t sret;
1117
1120 "Asked to parse config file `%s'\n",
1121 fn);
1122 if (NULL == fn)
1123 return GNUNET_SYSERR;
1124
1125
1126 /* Check for cycles */
1127 {
1128 unsigned int lvl = cfg->current_nest_level;
1129 struct ConfigFile *cf = cfg->loaded_files_tail;
1130 struct ConfigFile *parent = NULL;
1131
1132
1133 for (; NULL != cf; parent = cf, cf = cf->prev)
1134 {
1135 /* Check parents based on level, skipping children of siblings. */
1136 if (cf->level >= lvl)
1137 continue;
1138 lvl = cf->level;
1139 if ( (NULL == cf->source_filename) ||
1140 (NULL == filename) )
1141 continue;
1142 if (0 == strcmp (cf->source_filename,
1143 filename))
1144 {
1145 if (NULL == parent)
1146 {
1148 "Forbidden direct cyclic configuration import (%s -> %s)\n",
1149 cf->source_filename,
1150 filename);
1151 }
1152 else
1154 "Forbidden indirect cyclic configuration import (%s -> ... -> %s -> %s)\n",
1155 cf->source_filename,
1156 parent->source_filename,
1157 filename);
1158 GNUNET_free (fn);
1159 return GNUNET_SYSERR;
1160 }
1161 }
1162
1163 }
1164
1165 /* Keep track of loaded files.*/
1166 {
1167 loaded_file = GNUNET_new (struct ConfigFile);
1168
1169 loaded_file->level = cfg->current_nest_level;
1170 loaded_file->source_filename = GNUNET_strdup (filename
1171 ? filename
1172 : "<input>");
1175 loaded_file);
1176 }
1177
1178 dirty = cfg->dirty; /* back up value! */
1179 if (GNUNET_SYSERR ==
1181 &fs64,
1182 GNUNET_NO,
1183 GNUNET_YES))
1184 {
1186 "Error while determining the file size of `%s'\n",
1187 fn);
1188 GNUNET_free (fn);
1189 return GNUNET_SYSERR;
1190 }
1191 if (fs64 > SIZE_MAX)
1192 {
1193 GNUNET_break (0); /* File size is more than the heap size */
1194 GNUNET_free (fn);
1195 return GNUNET_SYSERR;
1196 }
1197 fs = fs64;
1198 mem = GNUNET_malloc (fs);
1199 sret = GNUNET_DISK_fn_read (fn,
1200 mem,
1201 fs);
1202 if ((sret < 0) || (fs != (size_t) sret))
1203 {
1205 "Error while reading file `%s'\n",
1206 fn);
1207 GNUNET_free (fn);
1208 GNUNET_free (mem);
1209 return GNUNET_SYSERR;
1210 }
1211 if (cfg->diagnostics)
1212 {
1213 GNUNET_CRYPTO_hash (mem,
1214 fs,
1215 &loaded_file->content_hash);
1216 }
1218 "Deserializing contents of file `%s'\n",
1219 fn);
1221 mem,
1222 fs,
1223 fn);
1224 if (GNUNET_SYSERR == ret)
1225 {
1227 _ ("Failed to parse configuration file `%s'\n"),
1228 fn);
1229 }
1230 else if (cfg->diagnostics)
1231 {
1232 loaded_file->have_content_hash = true;
1233 }
1234 GNUNET_free (fn);
1235 GNUNET_free (mem);
1236 /* restore dirty flag - anything we set in the meantime
1237 * came from disk */
1238 cfg->dirty = dirty;
1239 return ret;
1240}
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 1286 of file configuration.c.

1288{
1289 char *mem;
1290 char *cbuf;
1291 char *val;
1292 char *pos;
1293 size_t m_size;
1294 size_t c_size;
1295
1296 /* Pass1 : calculate the buffer size required */
1297 m_size = 0;
1298 for (struct ConfigSection *sec = cfg->sections;
1299 NULL != sec;
1300 sec = sec->next)
1301 {
1302 if (sec->inaccessible && (NULL == sec->entries))
1303 continue;
1304 /* For each section we need to add 3 characters: {'[',']','\n'} */
1305 m_size += strlen (sec->name) + 3;
1306 for (struct ConfigEntry *ent = sec->entries;
1307 NULL != ent;
1308 ent = ent->next)
1309 {
1310 if (do_skip (sec->name,
1311 ent->key))
1312 continue;
1313 if (NULL != ent->val)
1314 {
1315 /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */
1316 pos = ent->val;
1317 while (NULL != (pos = strstr (pos, "\n")))
1318 {
1319 m_size++;
1320 pos++;
1321 }
1322 /* For each key = value pair we need to add 4 characters (2
1323 spaces and 1 equal-to character and 1 new line) */
1324 m_size += strlen (ent->key) + strlen (ent->val) + 4;
1325 }
1326 }
1327 /* A new line after section end */
1328 m_size++;
1329 }
1330
1331 /* Pass2: Allocate memory and write the configuration to it */
1332 mem = GNUNET_malloc (m_size);
1333 c_size = 0;
1334 *size = c_size;
1335 for (struct ConfigSection *sec = cfg->sections;
1336 NULL != sec;
1337 sec = sec->next)
1338 {
1339 int len;
1340
1341 /* skipped in pass 1 */
1342 if (sec->inaccessible && (NULL == sec->entries))
1343 continue;
1344 len = GNUNET_asprintf (&cbuf,
1345 "[%s]\n",
1346 sec->name);
1347 GNUNET_assert (0 < len);
1348 GNUNET_memcpy (mem + c_size,
1349 cbuf,
1350 len);
1351 c_size += len;
1352 GNUNET_free (cbuf);
1353 for (struct ConfigEntry *ent = sec->entries;
1354 NULL != ent;
1355 ent = ent->next)
1356 {
1357 if (do_skip (sec->name,
1358 ent->key))
1359 continue;
1360 if (NULL != ent->val)
1361 {
1362 val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1363 strcpy (val, ent->val);
1364 while (NULL != (pos = strstr (val, "\n")))
1365 {
1366 memmove (&pos[2], &pos[1], strlen (&pos[1]));
1367 pos[0] = '\\';
1368 pos[1] = 'n';
1369 }
1370 len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
1371 GNUNET_free (val);
1372 GNUNET_memcpy (mem + c_size, cbuf, len);
1373 c_size += len;
1374 GNUNET_free (cbuf);
1375 }
1376 }
1377 GNUNET_memcpy (mem + c_size, "\n", 1);
1378 c_size++;
1379 }
1380 GNUNET_assert (c_size == m_size);
1381 *size = c_size;
1382 return mem;
1383}
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 1612 of file configuration.c.

1614{
1615 return serialize_diagnostics (cfg,
1616 false);
1617}
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 1621 of file configuration.c.

1623{
1624 return serialize_diagnostics (cfg,
1625 true);
1626}

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

1927{
1928 struct CleanLine *lines = NULL;
1929 unsigned int lines_length = 0;
1930 const struct ConfigFile *parsed_file = NULL;
1931 char *target;
1932 char *contents = NULL;
1933 char *cleaned = NULL;
1934 size_t size;
1935 size_t cleaned_size = 0;
1937
1938 if (NULL != removed)
1939 *removed = 0;
1940 if ( (! cfg->diagnostics) ||
1941 (NULL == filename) )
1942 return GNUNET_SYSERR;
1944 if (NULL == target)
1945 return GNUNET_SYSERR;
1946
1947 for (const struct ConfigFile *cf = cfg->loaded_files_head;
1948 NULL != cf;
1949 cf = cf->next)
1950 {
1951 char *source;
1952
1953 if (! cf->have_content_hash)
1954 continue;
1955 source = GNUNET_STRINGS_filename_expand (cf->source_filename);
1956 if ( (NULL != source) &&
1957 (0 == strcmp (source,
1958 target)) )
1959 parsed_file = cf;
1961 }
1962 if (NULL == parsed_file)
1963 {
1965 "Configuration file `%s' was not parsed with diagnostics enabled\n",
1966 target);
1967 goto cleanup;
1968 }
1969 if (GNUNET_OK != read_file (target,
1970 &contents,
1971 &size))
1972 {
1974 "Configuration file `%s' changed since it was parsed\n",
1975 target);
1976 goto cleanup;
1977 }
1978 {
1979 struct GNUNET_HashCode actual;
1980
1981 GNUNET_CRYPTO_hash (contents,
1982 size,
1983 &actual);
1984 if (0 != GNUNET_memcmp (&actual,
1985 &parsed_file->content_hash))
1986 {
1988 "Configuration file `%s' changed since it was parsed\n",
1989 target);
1990 goto cleanup;
1991 }
1992 }
1993
1994 /* First mark every target definition that has an exact duplicate at a
1995 distinct source location. */
1996 for (const struct ConfigSection *sec = cfg->sections;
1997 NULL != sec;
1998 sec = sec->next)
1999 for (const struct ConfigEntry *ent = sec->entries;
2000 NULL != ent;
2001 ent = ent->next)
2002 for (const struct ConfigSource *source = ent->sources;
2003 NULL != source;
2004 source = source->next)
2005 {
2006 bool duplicate = false;
2007 struct CleanLine line;
2008
2009 if (0 != strcmp (source->filename,
2010 target))
2011 continue;
2012 for (const struct ConfigSource *other = ent->sources;
2013 NULL != other;
2014 other = other->next)
2015 {
2016 if ( (0 == strcmp (source->value,
2017 other->value)) &&
2018 ( (source->lineno != other->lineno) ||
2019 (0 != strcmp (source->filename,
2020 other->filename)) ) )
2021 {
2022 duplicate = true;
2023 break;
2024 }
2025 }
2026 if ( (! duplicate) ||
2027 (NULL != find_clean_line (lines,
2028 lines_length,
2029 source->lineno)) )
2030 continue;
2031 line.section = sec->name;
2032 line.option = ent->key;
2033 line.line = source->lineno;
2034 line.remove = true;
2035 GNUNET_array_append (lines,
2036 lines_length,
2037 line);
2038 }
2039
2040 /* Keep the highest-precedence target duplicate needed to preserve every
2041 effective value after all of the tentative removals. */
2042 for (const struct ConfigSection *sec = cfg->sections;
2043 NULL != sec;
2044 sec = sec->next)
2045 for (const struct ConfigEntry *ent = sec->entries;
2046 NULL != ent;
2047 ent = ent->next)
2048 {
2049 const struct ConfigSource *survivor = NULL;
2050
2051 for (const struct ConfigSource *source = ent->sources;
2052 NULL != source;
2053 source = source->next)
2055 target,
2056 lines,
2057 lines_length))
2058 {
2059 survivor = source;
2060 break;
2061 }
2062 if ( (NULL != survivor) &&
2063 (0 == strcmp (survivor->value,
2064 ent->val)) )
2065 continue;
2066 for (const struct ConfigSource *source = ent->sources;
2067 NULL != source;
2068 source = source->next)
2069 {
2070 struct CleanLine *line;
2071
2072 if ( (0 != strcmp (source->filename,
2073 target)) ||
2074 (0 != strcmp (source->value,
2075 ent->val)) )
2076 continue;
2077 line = find_clean_line (lines,
2078 lines_length,
2079 source->lineno);
2080 if ( (NULL != line) && line->remove)
2081 {
2082 line->remove = false;
2083 break;
2084 }
2085 }
2086 }
2087
2088 if (lines_length > 1)
2089 qsort (lines,
2090 lines_length,
2091 sizeof (*lines),
2093 {
2094 unsigned int remove_count = 0;
2095
2096 for (unsigned int i = 0; i < lines_length; i++)
2097 if (lines[i].remove)
2098 remove_count++;
2099 if (0 == remove_count)
2100 {
2101 if (NULL != removed)
2102 *removed = 0;
2103 ret = GNUNET_OK;
2104 goto cleanup;
2105 }
2106
2107 cleaned = GNUNET_malloc (size);
2108 for (size_t offset = 0, line_number = 1; offset < size; line_number++)
2109 {
2110 size_t end = offset;
2111 struct CleanLine *line;
2112
2113 while ( (end < size) && ('\n' != contents[end]) )
2114 end++;
2115 if (end < size)
2116 end++;
2117 line = find_clean_line (lines,
2118 lines_length,
2119 (unsigned int) line_number);
2120 if ( (NULL == line) || (! line->remove) )
2121 {
2122 GNUNET_memcpy (&cleaned[cleaned_size],
2123 &contents[offset],
2124 end - offset);
2125 cleaned_size += end - offset;
2126 }
2127 offset = end;
2128 }
2129 if (GNUNET_OK !=
2130 write_buffer_atomic (target,
2131 cleaned,
2132 cleaned_size,
2133 &parsed_file->content_hash))
2134 goto cleanup;
2135 if (NULL != removed)
2136 *removed = remove_count;
2137 if (NULL != cb)
2138 for (unsigned int i = 0; i < lines_length; i++)
2139 if (lines[i].remove)
2140 cb (cb_cls,
2141 lines[i].section,
2142 lines[i].option,
2143 lines[i].line);
2144 ret = GNUNET_OK;
2145 }
2146
2147cleanup:
2148 GNUNET_free (cleaned);
2149 GNUNET_free (contents);
2150 GNUNET_array_grow (lines,
2151 lines_length,
2152 0);
2153 GNUNET_free (target);
2154 return ret;
2155}
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 if (strlen (line_orig) != line_size)
877 {
879 "NUL byte in line %u\n",
880 nr);
882 break;
883 }
884 /* tabs and '\r' are whitespace */
885 emptyline = GNUNET_YES;
886 for (size_t i = 0; i < line_size; i++)
887 {
888 if (line[i] == '\t')
889 line[i] = ' ';
890 if (line[i] == '\r')
891 line[i] = ' ';
892 if (' ' != line[i])
893 emptyline = GNUNET_NO;
894 }
895 /* ignore empty lines */
896 if (GNUNET_YES == emptyline)
897 continue;
898
899 /* remove tailing whitespace */
900 for (size_t i = line_size - 1;
901 (i >= 1) && (isspace ((unsigned char) line[i]));
902 i--)
903 line[i] = '\0';
904
905 /* remove leading whitespace */
906 for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++)
907 ;
908 line_size = strlen (line);
909
910 /* ignore comments */
911 if ( ('#' == line[0]) ||
912 ('%' == line[0]) )
913 continue;
914
915 /* Handle special directives. */
916 if ('@' == line[0])
917 {
918 char *end = strchr (line + 1, '@');
919 char *directive;
920 enum GNUNET_GenericReturnValue directive_ret;
921
922 if (NULL != cfg->restrict_section)
923 {
925 "Illegal directive in line %u (parsing restricted section %s)\n",
926 nr,
929 break;
930 }
931
932 if (NULL == end)
933 {
935 "Bad directive in line %u\n",
936 nr);
938 break;
939 }
940 *end = '\0';
941 directive = line + 1;
942
943 if (0 == strcasecmp (directive,
944 "INLINE"))
945 {
946 const char *path = end + 1;
947
948 /* Skip space before path */
949 for (; isspace (*path); path++)
950 ;
951
952 directive_ret = handle_inline (cfg,
953 path,
954 false,
955 NULL,
956 source_filename,
957 nr);
958 }
959 else if (0 == strcasecmp (directive,
960 "INLINE-MATCHING"))
961 {
962 const char *path = end + 1;
963
964 /* Skip space before path */
965 for (; isspace (*path); path++)
966 ;
967
968 directive_ret = handle_inline (cfg,
969 path,
970 true,
971 NULL,
972 source_filename,
973 nr);
974 }
975 else if (0 == strcasecmp (directive,
976 "INLINE-SECRET"))
977 {
978 char *secname = end + 1;
979 char *secname_end;
980 const char *path;
981
982 /* Skip space before secname */
983 for (; isspace (*secname); secname++)
984 ;
985
986 secname_end = strchr (secname, ' ');
987
988 if (NULL == secname_end)
989 {
991 "Bad inline-secret directive in line %u\n",
992 nr);
994 break;
995 }
996 *secname_end = '\0';
997 path = secname_end + 1;
998
999 /* Skip space before path */
1000 for (; isspace (*path); path++)
1001 ;
1002
1003 directive_ret = handle_inline (cfg,
1004 path,
1005 false,
1006 secname,
1007 source_filename,
1008 nr);
1009 }
1010 else
1011 {
1013 "Unknown or malformed directive '%s' in line %u\n",
1014 directive,
1015 nr);
1017 break;
1018 }
1019 if (GNUNET_OK != directive_ret)
1020 {
1021 ret = directive_ret;
1022 break;
1023 }
1024 continue;
1025 }
1026 if ( ('[' == line[0]) &&
1027 (']' == line[line_size - 1]) )
1028 {
1029 /* [value] */
1030 line[line_size - 1] = '\0';
1031 value = &line[1];
1032 GNUNET_free (section);
1033 section = GNUNET_strdup (value);
1034 continue;
1035 }
1036 if (NULL != (eq = strchr (line, '=')))
1037 {
1038
1039 if (NULL == section)
1040 {
1042 "Syntax error while deserializing in line %u (option without section)\n",
1043 nr);
1045 break;
1046 }
1047
1048 /* tag = value */
1049 tag = GNUNET_strndup (line, eq - line);
1050 /* remove tailing whitespace */
1051 for (int i = strlen (tag) - 1;
1052 (i >= 1) && (isspace ((unsigned char) tag[i]));
1053 i--)
1054 tag[i] = '\0';
1055
1056 /* Strip whitespace */
1057 value = eq + 1;
1058 while (isspace ((unsigned char) value[0]))
1059 value++;
1060 for (int i = strlen (value) - 1;
1061 (i >= 1) && (isspace ((unsigned char) value[i]));
1062 i--)
1063 value[i] = '\0';
1064
1065 /* remove quotes */
1066 if ( ('"' == value[0]) &&
1067 ('"' == value[strlen (value) - 1]) )
1068 {
1069 value[strlen (value) - 1] = '\0';
1070 value++;
1071 }
1073 section,
1074 tag,
1075 value);
1076 if (cfg->diagnostics)
1077 {
1079 section,
1080 tag,
1081 value,
1082 source_filename
1083 ? source_filename
1084 : "<input>",
1085 nr);
1086 }
1087 GNUNET_free (tag);
1088 continue;
1089 }
1090 /* parse error */
1092 "Syntax error while deserializing in line %u\n",
1093 nr);
1095 break;
1096 }
1097 GNUNET_free (line_orig);
1098 GNUNET_free (section);
1099 GNUNET_assert ( (GNUNET_OK != ret) ||
1100 (r_bytes == size) );
1101 return ret;
1102}
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 1834 of file configuration.c.

1837{
1839 char *cfg_buf;
1840 size_t size;
1841
1843 &size);
1845 cfg_buf,
1846 size,
1847 NULL);
1848 GNUNET_free (cfg_buf);
1850 return ret;
1851}
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 2368 of file configuration.c.

2372{
2373 int ret;
2374 struct GNUNET_CONFIGURATION_Handle *diff;
2375
2376 diff = GNUNET_CONFIGURATION_get_diff (cfg_default, cfg_new);
2379 return ret;
2380}
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 2351 of file configuration.c.

2354{
2355 struct DiffHandle diffHandle;
2356
2357 GNUNET_break (cfg_default->pd == cfg_new->pd);
2358 diffHandle.cfgDiff = GNUNET_CONFIGURATION_create (cfg_new->pd);
2359 diffHandle.cfg_default = cfg_default;
2362 &diffHandle);
2363 return diffHandle.cfgDiff;
2364}
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 1244 of file configuration.c.

1245{
1246 return cfg->dirty;
1247}

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

3768{
3769 return cfg->pd;
3770}

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

2163{
2164 for (struct ConfigSection *spos = cfg->sections;
2165 NULL != spos;
2166 spos = spos->next)
2167 for (struct ConfigEntry *epos = spos->entries;
2168 NULL != epos;
2169 epos = epos->next)
2170 if (NULL != epos->val)
2171 iter (iter_cls,
2172 spos->name,
2173 epos->key,
2174 epos->val);
2175}

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

2216{
2217 struct ConfigSection *spos;
2218 struct ConfigSection *next;
2219
2220 next = cfg->sections;
2221 while (NULL != next)
2222 {
2223 spos = next;
2224 next = spos->next;
2225 if (spos->inaccessible && (NULL == spos->entries))
2226 continue;
2227 iter (iter_cls,
2228 spos->name);
2229 }
2230}
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 2234 of file configuration.c.

2236{
2237 struct ConfigSection *spos;
2238 struct ConfigSection *prev;
2239 struct ConfigEntry *ent;
2240
2241 prev = NULL;
2242 spos = cfg->sections;
2243 while (NULL != spos)
2244 {
2245 if (0 == strcasecmp (section,
2246 spos->name))
2247 {
2248 if (NULL == prev)
2249 cfg->sections = spos->next;
2250 else
2251 prev->next = spos->next;
2252 while (NULL != (ent = spos->entries))
2253 {
2254 struct ConfigSource *source;
2255
2256 spos->entries = ent->next;
2257 GNUNET_free (ent->key);
2258 GNUNET_free (ent->val);
2259 while (NULL != (source = ent->sources))
2260 {
2261 ent->sources = source->next;
2262 GNUNET_free (source->value);
2263 GNUNET_free (source->filename);
2265 }
2266 GNUNET_free (ent);
2267 cfg->dirty = GNUNET_YES;
2268 }
2269 GNUNET_free (spos->name);
2273 GNUNET_free (spos);
2274 return;
2275 }
2276 prev = spos;
2277 spos = spos->next;
2278 }
2279}
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 2446 of file configuration.c.

2451{
2452 struct ConfigEntry *e;
2453 char dummy[2];
2454
2455 if (NULL == (e = find_entry (cfg,
2456 section,
2457 option)))
2458 return GNUNET_NO;
2459 if (NULL == e->val)
2460 return GNUNET_NO;
2461 if (1 != sscanf (e->val,
2462 "%llu%1s",
2463 number,
2464 dummy))
2465 return GNUNET_SYSERR;
2466 return GNUNET_OK;
2467}
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 2471 of file configuration.c.

2475{
2476 char s[64];
2477
2478 /* See: #9369 */
2479 const locale_t cl = newlocale (LC_NUMERIC_MASK,
2480 "C",
2481 (locale_t) 0);
2482 locale_t old_locale;
2483
2484 GNUNET_assert ((locale_t) 0 != cl);
2485 old_locale = uselocale (cl);
2486 GNUNET_snprintf (s,
2487 64,
2488 "%f",
2489 (double) number);
2490 uselocale (old_locale);
2491 freelocale (cl);
2493 section,
2494 option,
2495 s);
2496}
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_assert, 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 2500 of file configuration.c.

2505{
2506 struct ConfigEntry *e;
2507 char dummy[2];
2508
2509 if (NULL == (e = find_entry (cfg,
2510 section,
2511 option)))
2512 return GNUNET_NO;
2513 if (NULL == e->val)
2514 return GNUNET_NO;
2515 /* See #9369 */
2516 {
2517 const locale_t cl = newlocale (LC_NUMERIC_MASK,
2518 "C",
2519 (locale_t) 0);
2520 locale_t old_locale;
2521 int n;
2522
2523 GNUNET_assert ((locale_t) 0 != cl);
2524 old_locale = uselocale (cl);
2525 n = sscanf (e->val,
2526 "%f%1s",
2527 number,
2528 dummy);
2529 uselocale (old_locale);
2530 freelocale (cl);
2531 if (1 != n)
2532 return GNUNET_SYSERR;
2533 }
2534 return GNUNET_OK;
2535}

References cfg, dummy, find_entry(), GNUNET_assert, 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 2539 of file configuration.c.

2544{
2545 struct ConfigEntry *e;
2546 int ret;
2547
2548 if (NULL == (e = find_entry (cfg,
2549 section,
2550 option)))
2551 return GNUNET_NO;
2552 if (NULL == e->val)
2553 return GNUNET_NO;
2555 time);
2556 if (GNUNET_OK != ret)
2558 section,
2559 option,
2560 _ ("Not a valid relative time specification"));
2561 return ret;
2562}
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 2566 of file configuration.c.

2571{
2572 struct ConfigEntry *e;
2573
2574 if (NULL == (e = find_entry (cfg,
2575 section,
2576 option)))
2577 return GNUNET_NO;
2578 if (NULL == e->val)
2579 return GNUNET_NO;
2581 size);
2582}
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 2689 of file configuration.c.

2692{
2693 struct ConfigEntry *e;
2694
2695 if ( (NULL == (e = find_entry (cfg,
2696 section,
2697 option))) ||
2698 (NULL == e->val) )
2699 return GNUNET_NO;
2700 return GNUNET_YES;
2701}

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

2601{
2602 struct ConfigEntry *e;
2603
2604 if ( (NULL == (e = find_entry (cfg,
2605 section,
2606 option))) ||
2607 (NULL == e->val) )
2608 {
2609 *value = NULL;
2610 return GNUNET_NO;
2611 }
2612 *value = GNUNET_strdup (e->val);
2613 return GNUNET_OK;
2614}

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

2989{
2990 char *tmp;
2992
2994 section,
2995 option,
2996 &tmp);
2997 if (GNUNET_OK != ret)
2998 {
3000 "Failed to retrieve filename\n");
3001 *value = NULL;
3002 return ret;
3003 }
3005 tmp);
3007 GNUNET_free (tmp);
3008 if (*value == NULL)
3009 return GNUNET_SYSERR;
3010 return GNUNET_OK;
3011}
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 3043 of file configuration.c.

3049{
3050 char *list;
3051 char *pos;
3052 char *end;
3053 char old;
3054 int ret;
3055
3056 if (GNUNET_OK !=
3058 section,
3059 option,
3060 &list))
3061 return 0;
3062 GNUNET_assert (list != NULL);
3063 ret = 0;
3064 pos = list;
3065 while (1)
3066 {
3067 while (pos[0] == ' ')
3068 pos++;
3069 if (strlen (pos) == 0)
3070 break;
3071 end = pos + 1;
3072 while ((end[0] != ' ') && (end[0] != '\0'))
3073 {
3074 if (end[0] == '\\')
3075 {
3076 switch (end[1])
3077 {
3078 case '\\':
3079 case ' ':
3080 memmove (end, &end[1], strlen (&end[1]) + 1);
3081
3082 case '\0':
3083 /* illegal, but just keep it */
3084 break;
3085
3086 default:
3087 /* illegal, but just ignore that there was a '/' */
3088 break;
3089 }
3090 }
3091 end++;
3092 }
3093 old = end[0];
3094 end[0] = '\0';
3095 if (strlen (pos) > 0)
3096 {
3097 ret++;
3098 if ( (NULL != cb) &&
3099 (GNUNET_OK != cb (cb_cls,
3100 pos)))
3101 {
3103 break;
3104 }
3105 }
3106 if (old == '\0')
3107 break;
3108 pos = end + 1;
3109 }
3110 GNUNET_free (list);
3111 return ret;
3112}
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 2179 of file configuration.c.

2184{
2185 struct ConfigSection *spos;
2186
2187 spos = cfg->sections;
2188 while ((spos != NULL) && (0 != strcasecmp (spos->name, section)))
2189 spos = spos->next;
2190 if (NULL == spos)
2191 return;
2192 for (struct ConfigEntry *epos = spos->entries;
2193 NULL != epos;
2194 epos = epos->next)
2195 if (NULL != epos->val)
2196 iter (iter_cls,
2197 spos->name,
2198 epos->key,
2199 epos->val);
2200 if (spos->inaccessible)
2201 {
2203 "Section '%s' is marked as inaccessible, because a configuration "
2204 "file that contains the section can't be read.\n",
2205 section);
2206 return;
2207 }
2208}

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

2624{
2625 struct ConfigEntry *e;
2626 unsigned int i;
2627
2628 if (NULL == (e = find_entry (cfg,
2629 section,
2630 option)))
2631 return GNUNET_NO;
2632 for (i = 0; NULL != choices[i]; i++)
2633 if (0 == strcasecmp (choices[i], e->val))
2634 break;
2635 if (NULL == choices[i])
2636 {
2638 _ ("Configuration value '%s' for '%s'"
2639 " in section '%s' is not in set of legal choices\n"),
2640 e->val,
2641 option,
2642 section);
2643 return GNUNET_SYSERR;
2644 }
2645 *value = choices[i];
2646 return GNUNET_OK;
2647}

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

3019{
3020 static const char *yesno[] = {
3021 "YES",
3022 "NO",
3023 NULL
3024 };
3025 const char *val;
3027
3028 ret =
3030 section,
3031 option,
3032 yesno,
3033 &val);
3034 if (GNUNET_OK != ret)
3035 return ret;
3036 if (val == yesno[0])
3037 return GNUNET_YES;
3038 return GNUNET_NO;
3039}
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, and ret.

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

2656{
2657 char *enc;
2658 int res;
2659 size_t data_size;
2660
2661 if (GNUNET_OK !=
2662 (res =
2664 section,
2665 option,
2666 &enc)))
2667 return res;
2668 data_size = (strlen (enc) * 5) / 8;
2669 if (data_size != buf_size)
2670 {
2671 GNUNET_free (enc);
2672 return GNUNET_SYSERR;
2673 }
2674 if (GNUNET_OK !=
2676 strlen (enc),
2677 buf,
2678 buf_size))
2679 {
2680 GNUNET_free (enc);
2681 return GNUNET_SYSERR;
2682 }
2683 GNUNET_free (enc);
2684 return GNUNET_OK;
2685}
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 2973 of file configuration.c.

2976{
2977 return expand_all (cfg,
2978 orig,
2979 NULL);
2980}
static char * expand_all(const struct GNUNET_CONFIGURATION_Handle *cfg, char *orig, const struct ExpansionFrame *frame)
$-expand all terms in a string.

References cfg, and expand_all().

Referenced by 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 2427 of file configuration.c.

2431{
2432 char s[64];
2433
2434 GNUNET_snprintf (s,
2435 64,
2436 "%llu",
2437 number);
2439 section,
2440 option,
2441 s);
2442}

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

2389{
2390 struct ConfigSection *sec;
2391 struct ConfigEntry *e;
2392 char *nv;
2393
2394 e = find_entry (cfg, section, option);
2395 if (NULL != e)
2396 {
2397 if (NULL == value)
2398 {
2399 GNUNET_free (e->val);
2400 e->val = NULL;
2401 }
2402 else
2403 {
2404 nv = GNUNET_strdup (value);
2405 GNUNET_free (e->val);
2406 e->val = nv;
2407 }
2408 return;
2409 }
2410 sec = find_section (cfg, section);
2411 if (sec == NULL)
2412 {
2413 sec = GNUNET_new (struct ConfigSection);
2414 sec->name = GNUNET_strdup (section);
2415 sec->next = cfg->sections;
2416 cfg->sections = sec;
2417 }
2418 e = GNUNET_new (struct ConfigEntry);
2419 e->key = GNUNET_strdup (option);
2420 e->val = GNUNET_strdup (value);
2421 e->next = sec->entries;
2422 sec->entries = e;
2423}
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 3211 of file configuration.c.

3216{
3217 char *list;
3218 char *pos;
3219 char *end;
3220 char *match;
3221 char old;
3222
3223 if (GNUNET_OK !=
3225 section,
3226 option,
3227 &list))
3228 return GNUNET_NO;
3229 match = escape_name (value);
3230 pos = list;
3231 while (1)
3232 {
3233 while (pos[0] == ' ')
3234 pos++;
3235 if (strlen (pos) == 0)
3236 break;
3237 end = pos + 1;
3238 while ((end[0] != ' ') && (end[0] != '\0'))
3239 {
3240 if (end[0] == '\\')
3241 {
3242 switch (end[1])
3243 {
3244 case '\\':
3245 case ' ':
3246 end++;
3247 break;
3248
3249 case '\0':
3250 /* illegal, but just keep it */
3251 break;
3252
3253 default:
3254 /* illegal, but just ignore that there was a '/' */
3255 break;
3256 }
3257 }
3258 end++;
3259 }
3260 old = end[0];
3261 end[0] = '\0';
3262 if (0 == strcmp (pos, match))
3263 {
3264 if (old != '\0')
3265 memmove (pos,
3266 &end[1],
3267 strlen (&end[1]) + 1);
3268 else
3269 {
3270 if (pos != list)
3271 pos[-1] = '\0';
3272 else
3273 pos[0] = '\0';
3274 }
3276 section,
3277 option,
3278 list);
3279 GNUNET_free (list);
3280 GNUNET_free (match);
3281 return GNUNET_OK;
3282 }
3283 if (old == '\0')
3284 break;
3285 end[0] = old;
3286 pos = end + 1;
3287 }
3288 GNUNET_free (list);
3289 GNUNET_free (match);
3290 return GNUNET_NO;
3291}
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 3173 of file configuration.c.

3178{
3179 char *escaped;
3180 char *old;
3181 char *nw;
3182
3183 if (GNUNET_SYSERR ==
3185 section,
3186 option,
3187 &test_match,
3188 (void *) value))
3189 return GNUNET_NO; /* already exists */
3190 if (GNUNET_OK !=
3191 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
3192 old = GNUNET_strdup ("");
3193 escaped = escape_name (value);
3194 nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2);
3195 strcpy (nw, old);
3196 if (strlen (old) > 0)
3197 strcat (nw, " ");
3198 strcat (nw, escaped);
3200 section,
3201 option,
3202 nw);
3203 GNUNET_free (old);
3204 GNUNET_free (nw);
3205 GNUNET_free (escaped);
3206 return GNUNET_OK;
3207}
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 3756 of file configuration.c.

3758{
3759 GNUNET_free (cs->option);
3760 GNUNET_free (cs->section);
3761 GNUNET_free (cs->value);
3762}

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

3566{
3567 struct GNUNET_CONFIGURATION_ConfigSettings *cs = cls;
3568 struct GNUNET_CONFIGURATION_Handle *out = NULL;
3569 struct GNUNET_CONFIGURATION_Handle *ncfg = NULL;
3570
3571 (void) args;
3572 if (cs->diagnostics &&
3573 (! cfg->diagnostics))
3574 {
3575 /* Re-parse the configuration with diagnostics enabled. */
3578 if (GNUNET_OK !=
3580 cfgfile))
3581 {
3582 fprintf (stderr,
3583 _ ("Failed to load config file `%s'"),
3584 cfgfile);
3585 return;
3586 }
3587 cfg = ncfg;
3588 }
3589
3590 if (cs->full)
3591 cs->rewrite = GNUNET_YES;
3592 if (cs->list_sections)
3593 {
3594 fprintf (stderr,
3595 _ ("The following sections are available:\n"));
3598 NULL);
3599 return;
3600 }
3601 if ( (! cs->rewrite) &&
3602 (NULL == cs->section) )
3603 {
3604 char *serialization;
3605
3606 if (! cs->diagnostics)
3607 {
3608 fprintf (stderr,
3609 _ ("%s, %s or %s argument is required\n"),
3610 "--section",
3611 "--list-sections",
3612 "--diagnostics");
3614 return;
3615 }
3616 serialization = (cs->diagnostics > 1)
3619 fprintf (stdout,
3620 "%s",
3621 serialization);
3622 GNUNET_free (serialization);
3623 }
3624 else if ( (NULL != cs->section) &&
3625 (NULL == cs->value) )
3626 {
3627 if (NULL == cs->option)
3628 {
3630 cfg,
3631 cs->section,
3632 cs->is_filename
3634 : &print_option,
3635 (void *) cfg);
3636 }
3637 else
3638 {
3639 char *value;
3640
3641 if (cs->is_filename)
3642 {
3643 if (GNUNET_OK !=
3645 cs->section,
3646 cs->option,
3647 &value))
3648 {
3650 cs->section,
3651 cs->option);
3653 return;
3654 }
3655 }
3656 else
3657 {
3658 if (GNUNET_OK !=
3660 cs->section,
3661 cs->option,
3662 &value))
3663 {
3665 cs->section,
3666 cs->option);
3668 return;
3669 }
3670 }
3671 fprintf (stdout,
3672 "%s\n",
3673 value);
3675 }
3676 }
3677 else if (NULL != cs->section)
3678 {
3679 if (NULL == cs->option)
3680 {
3681 fprintf (stderr,
3682 _ ("--option argument required to set value\n"));
3684 return;
3685 }
3688 cs->section,
3689 cs->option,
3690 cs->value);
3691 cs->rewrite = GNUNET_YES;
3692 }
3693 if (cs->rewrite)
3694 {
3695 char *cfg_fn = NULL;
3696
3697 if (NULL == out)
3699
3700 if (NULL == cfgfile)
3701 {
3702 const char *xdg = getenv ("XDG_CONFIG_HOME");
3703
3704 if (NULL != xdg)
3705 GNUNET_asprintf (&cfg_fn,
3706 "%s%s%s",
3707 xdg,
3709 cfg->pd->config_file);
3710 else
3711 cfg_fn = GNUNET_strdup (cfg->pd->user_config_file);
3712 cfgfile = cfg_fn;
3713 }
3714
3715 if (! cs->full)
3716 {
3717 struct GNUNET_CONFIGURATION_Handle *def;
3718
3720 if (GNUNET_OK !=
3722 NULL))
3723 {
3724 fprintf (stderr,
3725 _ ("failed to load configuration defaults"));
3726 cs->global_ret = 1;
3729 GNUNET_free (cfg_fn);
3730 return;
3731 }
3732 if (GNUNET_OK !=
3734 out,
3735 cfgfile))
3736 cs->global_ret = 2;
3738 }
3739 else
3740 {
3741 if (GNUNET_OK !=
3743 cfgfile))
3744 cs->global_ret = 2;
3745 }
3746 GNUNET_free (cfg_fn);
3747 }
3748 if (NULL != out)
3750 if (NULL != ncfg)
3752}
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 3774 of file configuration.c.

3779{
3780 static char *cache;
3781 char *binary = NULL;
3782 char *path = NULL;
3783 size_t path_len;
3784
3785 if (GNUNET_YES ==
3787 GNUNET_NO,
3788 NULL,
3789 NULL))
3790 {
3791 return GNUNET_strdup (progname);
3792 }
3793 if (NULL != cache)
3794 path = cache;
3795 else
3797 "PATHS",
3798 "SUID_BINARY_PATH",
3799 &path);
3800 if ( (NULL == path) ||
3801 (0 == strlen (path)) )
3802 {
3803 if (NULL != path)
3804 GNUNET_free (path);
3805 cache = NULL;
3807 progname);
3808 }
3809 path_len = strlen (path);
3810 GNUNET_asprintf (&binary,
3811 "%s%s%s",
3812 path,
3813 (path[path_len - 1] == DIR_SEPARATOR) ? ""
3815 progname);
3816 cache = path;
3817 return binary;
3818}
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: