GNUnet  0.11.x
Data Structures | Macros | Typedefs | Functions
Configuration library

Configuration management. More...

Data Structures

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

Macros

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

Typedefs

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

Functions

struct GNUNET_CONFIGURATION_HandleGNUNET_CONFIGURATION_create (void)
 Create a new configuration object. More...
 
struct GNUNET_CONFIGURATION_HandleGNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Duplicate an existing configuration object. More...
 
void GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
 Destroy configuration object. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
 Load configuration. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d)
 Load default configuration. More...
 
struct GNUNET_CONFIGURATION_HandleGNUNET_CONFIGURATION_default (void)
 Return GNUnet's default configuration. More...
 
char * GNUNET_CONFIGURATION_default_filename (void)
 Return the filename of the default configuration filename that is used when no explicit configuration entry point has been specified. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
 Parse a configuration file, add all of the options in the file to the configuration environment. More...
 
char * GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
 Serializes the given configuration. More...
 
char * GNUNET_CONFIGURATION_serialize_diagnostics (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Serializes the given configuration with diagnostics information. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *source_filename)
 De-serializes configuration. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
 Write configuration file. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle *cfg_default, const struct GNUNET_CONFIGURATION_Handle *cfg_new, const char *filename)
 Write only configuration entries that have been changed to configuration file. More...
 
struct GNUNET_CONFIGURATION_HandleGNUNET_CONFIGURATION_get_diff (const struct GNUNET_CONFIGURATION_Handle *cfg_default, const struct GNUNET_CONFIGURATION_Handle *cfg_new)
 Compute configuration with only entries that have been changed. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Test if there are configuration options that were changed since the last save. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse_and_run (const char *filename, GNUNET_CONFIGURATION_Callback cb, void *cb_cls)
 Parse a configuration file filename and run the function cb with the resulting configuration object. More...
 
void GNUNET_CONFIGURATION_enable_diagnostics (struct GNUNET_CONFIGURATION_Handle *cfg)
 Enable extra diagnostics. More...
 
void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
 Iterate over all options in the configuration. More...
 
void GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Section_Iterator iter, void *iter_cls)
 Iterate over all sections in the configuration. More...
 
void GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
 Remove the given section and all options in it. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
 Get a configuration value that should be a number. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, float *number)
 Get a configuration value that should be a floating point number. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
 Get a configuration value that should be a relative time. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *size)
 Get a configuration value that should be a size in bytes. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
 Test if we have a value for a particular option. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
 Get a configuration value that should be a string. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
 Get a configuration value that should be the name of a file or directory. More...
 
int GNUNET_CONFIGURATION_iterate_value_filenames (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, GNUNET_FileNameCallback cb, void *cb_cls)
 Iterate over the set of filenames stored in a configuration value. More...
 
void GNUNET_CONFIGURATION_iterate_section_values (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
 Iterate over values of a section in the configuration. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *const *choices, const char **value)
 Get a configuration value that should be in a set of predefined strings. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
 Get a configuration value that should be in a set of "YES" or "NO". More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, void *buf, size_t buf_size)
 Get Crockford32-encoded fixed-size binary data from a configuration. More...
 
char * GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, char *orig)
 Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" where either in the "PATHS" section or the environment "FOO" is set to "DIRECTORY". More...
 
void GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long number)
 Set a configuration value that should be a number. More...
 
void GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
 Set a configuration value that should be a string. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
 Remove a filename from a configuration value that represents a list of filenames. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
 Append a filename to a configuration value that represents a list of filenames. More...
 
void GNUNET_CONFIGURATION_config_settings_free (struct GNUNET_CONFIGURATION_ConfigSettings *cs)
 Free resources associated with cs. More...
 
void GNUNET_CONFIGURATION_config_tool_run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main task to run to perform operations typical for gnunet-config as per the configuration settings given in cls. More...
 

Detailed Description

Configuration management.

Macro Definition Documentation

◆ GNUNET_CONFIGURATION_CONFIG_OPTIONS

#define GNUNET_CONFIGURATION_CONFIG_OPTIONS (   cs)

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

Parameters
csconfiguration settings to initialize

Definition at line 709 of file gnunet_configuration_lib.h.

Typedef Documentation

◆ GNUNET_CONFIGURATION_Callback

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

Signature of a function to be run with a configuration.

Parameters
clsclosure
cfgthe configuration
Returns
status code

Definition at line 218 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 281 of file gnunet_configuration_lib.h.

◆ GNUNET_CONFIGURATION_Section_Iterator

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

Function to iterate over section.

Parameters
clsclosure
sectionname of the section

Definition at line 294 of file gnunet_configuration_lib.h.

Function Documentation

◆ GNUNET_CONFIGURATION_create()

struct GNUNET_CONFIGURATION_Handle* GNUNET_CONFIGURATION_create ( void  )

Create a new configuration object.

Returns
fresh configuration object

Definition at line 226 of file configuration.c.

227 {
229  char *p;
230 
232  /* make certain values from the project data available
233  as PATHS */
235  if (NULL != p)
236  {
238  "PATHS",
239  "DATADIR",
240  p);
241  GNUNET_free (p);
242  }
244  if (NULL != p)
245  {
247  "PATHS",
248  "LIBDIR",
249  p);
250  GNUNET_free (p);
251  }
253  if (NULL != p)
254  {
256  "PATHS",
257  "BINDIR",
258  p);
259  GNUNET_free (p);
260  }
262  if (NULL != p)
263  {
265  "PATHS",
266  "PREFIX",
267  p);
268  GNUNET_free (p);
269  }
271  if (NULL != p)
272  {
274  "PATHS",
275  "LOCALEDIR",
276  p);
277  GNUNET_free (p);
278  }
280  if (NULL != p)
281  {
283  "PATHS",
284  "ICONDIR",
285  p);
286  GNUNET_free (p);
287  }
289  if (NULL != p)
290  {
292  "PATHS",
293  "DOCDIR",
294  p);
295  GNUNET_free (p);
296  }
298  if (NULL != p)
299  {
301  "PATHS",
302  "LIBEXECDIR",
303  p);
304  GNUNET_free (p);
305  }
306  return cfg;
307 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
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(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/)

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, and p.

Referenced by auto_config_cb(), callback_scan_for_rooms(), create_unique_cfgs(), gg_load_configuration(), GNUNET_ATS_solvers_experimentation_load(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_default(), GNUNET_CONFIGURATION_dup(), GNUNET_CONFIGURATION_get_diff(), GNUNET_CRYPTO_eddsa_setup_key(), GNUNET_SERVICE_run_(), GNUNET_TESTBED_barrier_wait(), GNUNET_TESTBED_extract_config_(), GNUNET_TESTING_service_run(), GNUNET_TESTING_system_create_with_portrange(), GNUNET_TRANSPORT_TESTING_start_peer(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(), handle_auto_result(), handle_autoconfig_request(), helper_mst(), iter_check_config(), iterate_save_rooms(), LEGACY_SERVICE_run(), load_member(), load_member_session(), load_member_session_next(), load_operation(), main(), netjail_exec_run(), run(), save_member(), save_operation(), start_peer_run(), and tokenizer_cb().

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

1515 {
1517 
1520  return ret;
1521 }
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
Return value of the commandline.
Definition: gnunet-abd.c:81
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create()
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(), and ret.

Referenced by associate_shared_service(), auto_config_cb(), controller_status_cb(), create_unique_cfgs(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_NAT_autoconfig_start(), GNUNET_TESTBED_controller_connect(), GNUNET_TESTBED_host_create_with_id(), GNUNET_TESTBED_host_replace_cfg_(), GNUNET_TESTBED_run(), GNUNET_TESTING_peer_configure(), GST_connection_pool_get_handle(), handle_autoconfig_request(), run(), set_cont(), and testbed_run().

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

312 {
313  struct ConfigSection *sec;
314  struct ConfigFile *cf;
315 
316  while (NULL != (sec = cfg->sections))
318  while (NULL != (cf = cfg->loaded_files_head))
319  {
324  cf);
325  GNUNET_free (cf);
326  }
328  GNUNET_free (cfg);
329 }
void GNUNET_CONFIGURATION_remove_section(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Remove the given section and all options in it.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
char * hint_restrict_section
Was this configuration file parsed via @inline-secret@?
char * source_filename
Source filename.
configuration section
Definition: configuration.c:75
char * name
name of the section
Definition: configuration.c:89
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 associate_shared_service(), auto_config_cb(), callback_scan_for_rooms(), clean_node(), cleanup(), cleanup_prc(), conclude_autoconfig_request(), controller_status_cb(), create_unique_cfgs(), destroy_pooled_connection(), do_shutdown(), GNUNET_ATS_solvers_experimentation_load(), GNUNET_ATS_solvers_experimentation_stop(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_default(), GNUNET_CRYPTO_eddsa_setup_key(), GNUNET_NAT_autoconfig_cancel(), GNUNET_SERVICE_run_(), GNUNET_TESTBED_barrier_wait(), GNUNET_TESTBED_barrier_wait_cancel(), GNUNET_TESTBED_controller_disconnect(), GNUNET_TESTBED_host_destroy(), GNUNET_TESTBED_host_replace_cfg_(), GNUNET_TESTBED_run(), GNUNET_TESTING_peer_destroy(), GNUNET_TESTING_service_run(), GNUNET_TESTING_system_destroy(), GNUNET_TRANSPORT_TESTING_start_peer(), GNUNET_TRANSPORT_TESTING_stop_peer(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop(), GST_destroy_peer(), GST_destroy_peers(), handle_add_host(), handle_auto_result(), handle_autoconfig_request(), handle_link_controllers_result(), helper_mst(), iterate_save_rooms(), LEGACY_SERVICE_run(), load_member(), load_member_session(), load_member_session_next(), load_operation(), main(), next_phase(), oprelease_get_slave_config(), oprelease_peer_getinfo(), oprelease_service_connect(), save_member(), save_operation(), shutdown_task(), start_peer_cleanup(), start_peer_run(), tokenizer_cb(), and update_peer_config().

Here is the call 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
cfgconfiguration to update
filenamename of the configuration file, NULL to load defaults
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Load configuration.

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

Definition at line 2450 of file configuration.c.

2452 {
2453  char *baseconfig;
2454  const char *base_config_varname;
2455 
2456  if (cfg->load_called)
2457  {
2458  /* FIXME: Make this a GNUNET_assert later */
2459  GNUNET_break (0);
2461  }
2462  cfg->load_called = true;
2463  if (NULL != filename)
2464  {
2467  }
2468 
2469  base_config_varname = GNUNET_OS_project_data_get ()->base_config_varname;
2470 
2471  if ((NULL != base_config_varname)
2472  && (NULL != (baseconfig = getenv (base_config_varname))))
2473  {
2474  baseconfig = GNUNET_strdup (baseconfig);
2475  }
2476  else
2477  {
2478  char *ipath;
2479 
2481  if (NULL == ipath)
2482  {
2483  GNUNET_break (0);
2484  return GNUNET_SYSERR;
2485  }
2486  GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d");
2487  GNUNET_free (ipath);
2488  }
2489 
2490  char *dname = GNUNET_STRINGS_filename_expand (baseconfig);
2491  GNUNET_free (baseconfig);
2492 
2493  if ((GNUNET_YES == GNUNET_DISK_directory_test (dname, GNUNET_YES)) &&
2495  {
2497  "Failed to load base configuration from '%s'\n",
2498  filename);
2499  GNUNET_free (dname);
2500  return GNUNET_SYSERR; /* no configuration at all found */
2501  }
2502  GNUNET_free (dname);
2503  if ((NULL != filename) &&
2505  {
2506  /* specified configuration not found */
2508  "Failed to load configuration from file '%s'\n",
2509  filename);
2510  return GNUNET_SYSERR;
2511  }
2512  if (((GNUNET_YES !=
2513  GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) &&
2514  (filename != NULL))
2515  GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG",
2516  filename);
2517  return GNUNET_OK;
2518 }
#define LOG(kind,...)
Definition: configuration.c:34
char * getenv()
static char * filename
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_YES
Definition: gnunet_common.h:97
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
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:404
#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_.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:482
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_OS_project_data_get(), GNUNET_strdup, GNUNET_STRINGS_filename_expand(), GNUNET_SYSERR, GNUNET_YES, GNUNET_CONFIGURATION_Handle::load_called, LOG, and GNUNET_CONFIGURATION_Handle::main_filename.

Referenced by auto_config_cb(), create_unique_cfgs(), gg_load_configuration(), GNUNET_ATS_solvers_experimentation_load(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_default(), GNUNET_CRYPTO_eddsa_setup_key(), GNUNET_SERVICE_run_(), GNUNET_TESTBED_barrier_wait(), GNUNET_TESTING_service_run(), GNUNET_TRANSPORT_TESTING_start_peer(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(), iter_check_config(), LEGACY_SERVICE_run(), main(), and start_peer_run().

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

◆ GNUNET_CONFIGURATION_load_from()

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

Load default configuration.

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

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

Definition at line 2129 of file configuration.c.

2290 {
2291  struct CollectFilesContext files_context = {
2292  .files = NULL,
2293  .files_length = 0,
2294  };
2295  enum GNUNET_GenericReturnValue fun_ret;
2296 
2297  if (GNUNET_SYSERR ==
2299  &files_context))
2300  return GNUNET_SYSERR; /* no configuration at all found */
2301  qsort (files_context.files,
2302  files_context.files_length,
2303  sizeof (char *),
2304  pstrcmp);
2305  for (unsigned int i = 0; i < files_context.files_length; i++)
2306  {
2307  char *ext;
2308  const char *filename = files_context.files[i];
2309 
2310  /* Examine file extension */
2311  ext = strrchr (filename, '.');
2312  if ((NULL == ext) || (0 != strcmp (ext, ".conf")))
2313  {
2314  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Skipping file `%s'\n", filename);
2315  fun_ret = GNUNET_OK;
2316  goto cleanup;
2317  }
2319  if (fun_ret != GNUNET_OK)
2320  break;
2321  }
2322 cleanup:
2323  if (files_context.files_length > 0)
2324  {
2325  for (size_t i = 0; i < files_context.files_length; i++)
2326  GNUNET_free (files_context.files[i]);
2327  GNUNET_array_grow (files_context.files,
2328  files_context.files_length,
2329  0);
2330  }
2331  return fun_ret;
2332 }
static int pstrcmp(const void *a, const void *b)
static int collect_files_cb(void *cls, const char *filename)
Function called with a filename.
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:92
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:814
#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.

Referenced by GNUNET_CONFIGURATION_load().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_default()

struct GNUNET_CONFIGURATION_Handle* GNUNET_CONFIGURATION_default ( void  )

Return GNUnet's default configuration.

A new configuration is allocated each time and it's up to the caller to destroy it when done. This function returns GNUnet's configuration even when GNUNET_OS_init has been called with a value different from GNUNET_OS_project_data_default.

Returns
a freshly allocated configuration

Definition at line 2378 of file configuration.c.

2379 {
2380  const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
2382  const char *xdg = getenv ("XDG_CONFIG_HOME");
2383  char *cfgname = NULL;
2385 
2386  /* FIXME: Why are we doing this? Needs some commentary! */
2387  GNUNET_OS_init (dpd);
2388 
2390 
2391  /* First, try user configuration. */
2392  if (NULL != xdg)
2393  GNUNET_asprintf (&cfgname, "%s/%s", xdg, pd->config_file);
2394  else
2395  cfgname = GNUNET_strdup (pd->user_config_file);
2396 
2397  /* If user config doesn't exist, try in
2398  /etc/<projdir>/<cfgfile> and /etc/<cfgfile> */
2399  if (GNUNET_OK != GNUNET_DISK_file_test (cfgname))
2400  {
2401  GNUNET_free (cfgname);
2402  GNUNET_asprintf (&cfgname, "/etc/%s", pd->config_file);
2403  }
2404  if (GNUNET_OK != GNUNET_DISK_file_test (cfgname))
2405  {
2406  GNUNET_free (cfgname);
2407  GNUNET_asprintf (&cfgname,
2408  "/etc/%s/%s",
2409  pd->project_dirname,
2410  pd->config_file);
2411  }
2412  if (GNUNET_OK != GNUNET_DISK_file_test (cfgname))
2413  {
2415  "Unable to top-level configuration file.\n");
2416  GNUNET_OS_init (pd);
2418  GNUNET_free (cfgname);
2419  return NULL;
2420  }
2421 
2422  /* We found a configuration file that looks good, try to load it. */
2423 
2425  "Loading top-level configuration from '%s'\n",
2426  cfgname);
2427  if (GNUNET_OK !=
2428  GNUNET_CONFIGURATION_load (cfg, cfgname))
2429  {
2430  GNUNET_OS_init (pd);
2432  GNUNET_free (cfgname);
2433  return NULL;
2434  }
2435  GNUNET_free (cfgname);
2436  GNUNET_OS_init (pd);
2437  return cfg;
2438 }
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
int GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration (starts with defaults, then loads system-specific configuration).
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:482
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_default(void)
Return default project data used by 'libgnunetutil' for GNUnet.
void GNUNET_OS_init(const struct GNUNET_OS_ProjectData *pd)
Setup OS subsystem with project data.
Project-specific data used to help the OS subsystem find installation paths.
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 cfg, GNUNET_OS_ProjectData::config_file, getenv(), GNUNET_asprintf(), GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_load(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_OK, GNUNET_OS_init(), GNUNET_OS_project_data_default(), GNUNET_OS_project_data_get(), GNUNET_strdup, LOG, GNUNET_OS_ProjectData::project_dirname, and GNUNET_OS_ProjectData::user_config_file.

Here is the call graph for this function:

◆ GNUNET_CONFIGURATION_default_filename()

char* GNUNET_CONFIGURATION_default_filename ( void  )

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

Returns
NULL if no default configuration file can be located, a newly allocated string otherwise

Definition at line 2336 of file configuration.c.

2337 {
2338  char *cfg_fn;
2339  const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
2340  const char *xdg = getenv ("XDG_CONFIG_HOME");
2341 
2342  if (NULL != xdg)
2343  GNUNET_asprintf (&cfg_fn,
2344  "%s%s%s",
2345  xdg,
2347  pd->config_file);
2348  else
2349  cfg_fn = GNUNET_strdup (pd->user_config_file);
2350 
2351  if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2352  return cfg_fn;
2353  GNUNET_free (cfg_fn);
2354 
2355  /* Fall back to /etc/ for the default configuration.
2356  Should be okay to use forward slashes here. */
2357 
2358  GNUNET_asprintf (&cfg_fn,
2359  "/etc/%s",
2360  pd->config_file);
2361  if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2362  return cfg_fn;
2363  GNUNET_free (cfg_fn);
2364 
2365  GNUNET_asprintf (&cfg_fn,
2366  "/etc/%s/%s",
2367  pd->project_dirname,
2368  pd->config_file);
2369  if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2370  return cfg_fn;
2371 
2372  GNUNET_free (cfg_fn);
2373  return NULL;
2374 }
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:489
#define DIR_SEPARATOR_STR
Definition: platform.h:165

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

Here is the call 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 687 of file configuration.c.

965 {
966  uint64_t fs64;
967  size_t fs;
968  char *fn;
969  char *mem;
970  int dirty;
972  ssize_t sret;
973 
975  LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to parse config file `%s'\n", fn);
976  if (NULL == fn)
977  return GNUNET_SYSERR;
978 
979 
980  /* Check for cycles */
981  {
982  unsigned int lvl = cfg->current_nest_level;
983  struct ConfigFile *cf = cfg->loaded_files_tail;
984  struct ConfigFile *parent = NULL;
985 
986 
987  for (; NULL != cf; parent = cf, cf = cf->prev)
988  {
989  /* Check parents based on level, skipping children of siblings. */
990  if (cf->level >= lvl)
991  continue;
992  lvl = cf->level;
993  if ( (NULL == cf->source_filename) || (NULL == filename))
994  continue;
995  if (0 == strcmp (cf->source_filename, filename))
996  {
997  if (NULL == parent)
998  {
1000  "Forbidden direct cyclic configuration import (%s -> %s)\n",
1001  cf->source_filename,
1002  filename);
1003  }
1004  else
1006  "Forbidden indirect cyclic configuration import (%s -> ... -> %s -> %s)\n",
1007  cf->source_filename,
1008  parent->source_filename,
1009  filename);
1010  GNUNET_free (fn);
1011  return GNUNET_SYSERR;
1012  }
1013  }
1014 
1015  }
1016 
1017  /* Keep track of loaded files.*/
1018  {
1019  struct ConfigFile *cf = GNUNET_new (struct ConfigFile);
1020 
1021  cf->level = cfg->current_nest_level;
1022  cf->source_filename = GNUNET_strdup (filename ? filename : "<input>");
1025  cf);
1026  }
1027 
1028  dirty = cfg->dirty; /* back up value! */
1029  if (GNUNET_SYSERR ==
1031  {
1033  "Error while determining the file size of `%s'\n",
1034  fn);
1035  GNUNET_free (fn);
1036  return GNUNET_SYSERR;
1037  }
1038  if (fs64 > SIZE_MAX)
1039  {
1040  GNUNET_break (0); /* File size is more than the heap size */
1041  GNUNET_free (fn);
1042  return GNUNET_SYSERR;
1043  }
1044  fs = fs64;
1045  mem = GNUNET_malloc (fs);
1046  sret = GNUNET_DISK_fn_read (fn, mem, fs);
1047  if ((sret < 0) || (fs != (size_t) sret))
1048  {
1049  LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Error while reading file `%s'\n"), fn);
1050  GNUNET_free (fn);
1051  GNUNET_free (mem);
1052  return GNUNET_SYSERR;
1053  }
1054  LOG (GNUNET_ERROR_TYPE_DEBUG, "Deserializing contents of file `%s'\n", fn);
1056  mem,
1057  fs,
1058  fn);
1059  if (GNUNET_SYSERR == ret)
1060  {
1062  _ ("Failed to parse configuration file `%s'\n"),
1063  fn);
1064  }
1065  GNUNET_free (fn);
1066  GNUNET_free (mem);
1067  /* restore dirty flag - anything we set in the meantime
1068  * came from disk */
1069  cfg->dirty = dirty;
1070  return ret;
1071 }
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:36
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:222
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:664
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
#define SIZE_MAX
Definition: platform.h:207
struct ConfigFile * prev
unsigned int level
Level in the tree of loaded config files.
unsigned int current_nest_level
Current nesting level of file loading.
enum GNUNET_GenericReturnValue dirty
Modification indication since last save GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on err...

Referenced by callback_scan_for_rooms(), GNUNET_CONFIGURATION_load(), load_member(), load_member_session(), load_member_session_next(), load_operation(), and run().

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

1119 {
1120  char *mem;
1121  char *cbuf;
1122  char *val;
1123  char *pos;
1124  size_t m_size;
1125  size_t c_size;
1126 
1127  /* Pass1 : calculate the buffer size required */
1128  m_size = 0;
1129  for (struct ConfigSection *sec = cfg->sections;
1130  NULL != sec;
1131  sec = sec->next)
1132  {
1133  if (sec->inaccessible)
1134  continue;
1135  /* For each section we need to add 3 characters: {'[',']','\n'} */
1136  m_size += strlen (sec->name) + 3;
1137  for (struct ConfigEntry *ent = sec->entries;
1138  NULL != ent;
1139  ent = ent->next)
1140  {
1141  if (do_skip (sec->name,
1142  ent->key))
1143  continue;
1144  if (NULL != ent->val)
1145  {
1146  /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */
1147  pos = ent->val;
1148  while (NULL != (pos = strstr (pos, "\n")))
1149  {
1150  m_size++;
1151  pos++;
1152  }
1153  /* For each key = value pair we need to add 4 characters (2
1154  spaces and 1 equal-to character and 1 new line) */
1155  m_size += strlen (ent->key) + strlen (ent->val) + 4;
1156  }
1157  }
1158  /* A new line after section end */
1159  m_size++;
1160  }
1161 
1162  /* Pass2: Allocate memory and write the configuration to it */
1163  mem = GNUNET_malloc (m_size);
1164  c_size = 0;
1165  *size = c_size;
1166  for (struct ConfigSection *sec = cfg->sections;
1167  NULL != sec;
1168  sec = sec->next)
1169  {
1170  int len;
1171 
1172  len = GNUNET_asprintf (&cbuf,
1173  "[%s]\n",
1174  sec->name);
1175  GNUNET_assert (0 < len);
1176  GNUNET_memcpy (mem + c_size,
1177  cbuf,
1178  len);
1179  c_size += len;
1180  GNUNET_free (cbuf);
1181  for (struct ConfigEntry *ent = sec->entries;
1182  NULL != ent;
1183  ent = ent->next)
1184  {
1185  if (do_skip (sec->name,
1186  ent->key))
1187  continue;
1188  if (NULL != ent->val)
1189  {
1190  val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1191  strcpy (val, ent->val);
1192  while (NULL != (pos = strstr (val, "\n")))
1193  {
1194  memmove (&pos[2], &pos[1], strlen (&pos[1]));
1195  pos[0] = '\\';
1196  pos[1] = 'n';
1197  }
1198  len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
1199  GNUNET_free (val);
1200  GNUNET_memcpy (mem + c_size, cbuf, len);
1201  c_size += len;
1202  GNUNET_free (cbuf);
1203  }
1204  }
1205  GNUNET_memcpy (mem + c_size, "\n", 1);
1206  c_size++;
1207  }
1208  GNUNET_assert (c_size == m_size);
1209  *size = c_size;
1210  return mem;
1211 }
static bool do_skip(const char *sec, const char *key)
Should we skip this configuration entry when serializing?
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
#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:67
configuration entry
Definition: configuration.c:43
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:47
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:79

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

Referenced by conclude_autoconfig_request(), GNUNET_NAT_AUTO_autoconfig_start(), GNUNET_TESTBED_compress_cfg_(), GNUNET_TESTBED_create_helper_init_msg_(), GNUNET_TESTBED_peer_update_configuration(), GNUNET_TESTBED_register_host(), handle_peer_get_config(), handle_slave_get_config(), opstart_peer_create(), and tokenizer_cb().

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

1217 {
1218  struct GNUNET_Buffer buf = { 0 };
1219 
1221  "#\n# Configuration file diagnostics\n#\n");
1223  "# Entry point: %s\n",
1225  "<none>");
1227  "#\n# Files Loaded:\n");
1228 
1229  for (struct ConfigFile *cfil = cfg->loaded_files_head;
1230  NULL != cfil;
1231  cfil = cfil->next)
1232  {
1234  "# ");
1235  for (unsigned int i = 0; i < cfil->level; i++)
1237  "+");
1238  if (0 != cfil->level)
1240  " ");
1241 
1243  "%s",
1244  cfil->source_filename);
1245 
1246  if (NULL != cfil->hint_restrict_section)
1248  " (%s secret section %s)",
1249  cfil->hint_inaccessible
1250  ? "inaccessible"
1251  : "loaded",
1252  cfil->hint_restrict_section);
1253 
1255  "\n");
1256  }
1257 
1259  "#\n\n");
1260 
1261  for (struct ConfigSection *sec = cfg->sections;
1262  NULL != sec;
1263  sec = sec->next)
1264  {
1265  if (sec->hint_secret_filename)
1267  "# secret section from %s\n# secret file stat %s\n",
1268  sec->hint_secret_filename,
1269  sec->hint_secret_stat);
1270  if (sec->hint_inlined_from_filename)
1271  {
1273  "# inlined from %s:%u\n",
1274  sec->hint_inlined_from_filename,
1275  sec->hint_inlined_from_line);
1276  }
1278  "[%s]\n\n",
1279  sec->name);
1280  if (sec->inaccessible)
1281  {
1283  "# <section contents inaccessible>\n\n\n");
1284  continue;
1285  }
1286  for (struct ConfigEntry *ent = sec->entries;
1287  NULL != ent;
1288  ent = ent->next)
1289  {
1290  if (do_skip (sec->name,
1291  ent->key))
1292  continue;
1293  if (NULL != ent->val)
1294  {
1295  char *pos;
1296  char *val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1297  strcpy (val, ent->val);
1298  while (NULL != (pos = strstr (val, "\n")))
1299  {
1300  memmove (&pos[2], &pos[1], strlen (&pos[1]));
1301  pos[0] = '\\';
1302  pos[1] = 'n';
1303  }
1304  if (NULL != ent->hint_filename)
1305  {
1307  "# %s:%u\n",
1308  ent->hint_filename,
1309  ent->hint_lineno);
1310  }
1312  "%s = %s\n",
1313  ent->key,
1314  val);
1315  GNUNET_free (val);
1316  }
1317  GNUNET_buffer_write_str (&buf, "\n");
1318  }
1319  GNUNET_buffer_write_str (&buf, "\n");
1320  }
1321  return GNUNET_buffer_reap_str (&buf);
1322 }
static char buf[2048]
char * GNUNET_buffer_reap_str(struct GNUNET_Buffer *buf)
Clear the buffer and return the string it contained.
Definition: buffer.c:123
void GNUNET_buffer_write_fstr(struct GNUNET_Buffer *buf, const char *fmt,...) __attribute__((format(printf
Write a 0-terminated formatted string to a buffer, excluding the 0-terminator.
void GNUNET_buffer_write_str(struct GNUNET_Buffer *buf, const char *str)
Write a 0-terminated string to a buffer, excluding the 0-terminator.
Definition: buffer.c:103
struct ConfigFile * next
Common buffer management functions.

References buf, cfg, do_skip(), GNUNET_buffer_reap_str(), GNUNET_buffer_write_fstr(), GNUNET_buffer_write_str(), GNUNET_free, GNUNET_malloc, GNUNET_CONFIGURATION_Handle::loaded_files_head, GNUNET_CONFIGURATION_Handle::main_filename, ConfigEntry::next, ConfigSection::next, ConfigFile::next, and GNUNET_CONFIGURATION_Handle::sections.

Referenced by GNUNET_CONFIGURATION_config_tool_run().

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

◆ GNUNET_CONFIGURATION_deserialize()

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

De-serializes configuration.

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

Definition at line 687 of file configuration.c.

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

References cfg, GNUNET_CONFIGURATION_Handle::diagnostics, e, find_entry(), GNUNET_strdup, and ConfigEntry::hint_filename.

Referenced by GNUNET_TESTBED_extract_config_(), handle_auto_result(), handle_autoconfig_request(), helper_mst(), and tokenizer_cb().

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

1328 {
1329  char *fn;
1330  char *cfg_buf;
1331  size_t size;
1332 
1334  if (fn == NULL)
1335  return GNUNET_SYSERR;
1337  {
1338  GNUNET_free (fn);
1339  return GNUNET_SYSERR;
1340  }
1342  &size);
1343  {
1344  struct GNUNET_DISK_FileHandle *h;
1345 
1346  h = GNUNET_DISK_file_open (fn,
1354  if (NULL == h)
1355  {
1356  GNUNET_free (fn);
1357  GNUNET_free (cfg_buf);
1358  return GNUNET_SYSERR;
1359  }
1360  if (((ssize_t) size) !=
1362  cfg_buf,
1363  size))
1364  {
1366  "write",
1367  fn);
1369  (void) GNUNET_DISK_directory_remove (fn);
1370  GNUNET_free (fn);
1371  GNUNET_free (cfg_buf);
1372  cfg->dirty = GNUNET_SYSERR; /* last write failed */
1373  return GNUNET_SYSERR;
1374  }
1377  }
1378  GNUNET_free (fn);
1379  GNUNET_free (cfg_buf);
1380  cfg->dirty = GNUNET_NO; /* last write succeeded */
1381  return GNUNET_OK;
1382 }
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
char * GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
Serializes the given configuration.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1235
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:686
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1085
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1306
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:582
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_OPEN_TRUNCATE
Truncate file if it exists.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_GROUP_READ
Group can read.
@ GNUNET_DISK_PERM_GROUP_WRITE
Group can write.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
Handle used to access files (and pipes).

Referenced by associate_shared_service(), create_unique_cfgs(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_TESTING_peer_configure(), handle_delete_message(), handle_rename_message(), handle_set_default_message(), iterate_save_rooms(), save_member(), save_operation(), set_cont(), testing_main(), and tokenizer_cb().

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

1570 {
1571  int ret;
1572  struct GNUNET_CONFIGURATION_Handle *diff;
1573 
1574  diff = GNUNET_CONFIGURATION_get_diff (cfg_default, cfg_new);
1577  return ret;
1578 }
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.

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

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

1555 {
1556  struct DiffHandle diffHandle;
1557 
1558  diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
1559  diffHandle.cfg_default = cfg_default;
1560  GNUNET_CONFIGURATION_iterate (cfg_new, &compare_entries, &diffHandle);
1561  return diffHandle.cfgDiff;
1562 }
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
struct GNUNET_CONFIGURATION_Handle * cfgDiff

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

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

1076 {
1077  return cfg->dirty;
1078 }

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

336 {
339 
341  if (GNUNET_OK !=
343  filename))
344  {
345  GNUNET_break (0);
347  return GNUNET_SYSERR;
348  }
349  ret = cb (cb_cls, cfg);
351  return ret;
352 }

Referenced by GNUNET_DISK_purge_cfg_dir().

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

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

References cfg, and GNUNET_CONFIGURATION_Handle::diagnostics.

Referenced by GNUNET_CONFIGURATION_config_tool_run().

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

1389 {
1390  for (struct ConfigSection *spos = cfg->sections;
1391  NULL != spos;
1392  spos = spos->next)
1393  for (struct ConfigEntry *epos = spos->entries;
1394  NULL != epos;
1395  epos = epos->next)
1396  if (NULL != epos->val)
1397  iter (iter_cls,
1398  spos->name,
1399  epos->key,
1400  epos->val);
1401 }

References cfg, ConfigEntry::next, ConfigSection::next, and GNUNET_CONFIGURATION_Handle::sections.

Referenced by get_cont(), GNUNET_CONFIGURATION_dup(), GNUNET_CONFIGURATION_get_diff(), and GNUNET_TESTING_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_Section_Iterator  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 1434 of file configuration.c.

1438 {
1439  struct ConfigSection *spos;
1440  struct ConfigSection *next;
1441 
1442  next = cfg->sections;
1443  while (next != NULL)
1444  {
1445  spos = next;
1446  next = spos->next;
1447  iter (iter_cls, spos->name);
1448  }
1449 }

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

Referenced by GNUNET_CONFIGURATION_config_tool_run(), GNUNET_TESTING_configuration_create_(), handle_delete_message(), handle_rename_message(), and run().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_remove_section()

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

Remove the given section and all options in it.

Parameters
cfgconfiguration to inspect
sectionname of the section to remove

Definition at line 1453 of file configuration.c.

1455 {
1456  struct ConfigSection *spos;
1457  struct ConfigSection *prev;
1458  struct ConfigEntry *ent;
1459 
1460  prev = NULL;
1461  spos = cfg->sections;
1462  while (NULL != spos)
1463  {
1464  if (0 == strcasecmp (section, spos->name))
1465  {
1466  if (NULL == prev)
1467  cfg->sections = spos->next;
1468  else
1469  prev->next = spos->next;
1470  while (NULL != (ent = spos->entries))
1471  {
1472  spos->entries = ent->next;
1473  GNUNET_free (ent->key);
1474  GNUNET_free (ent->val);
1475  GNUNET_free (ent->hint_filename);
1476  GNUNET_free (ent);
1477  cfg->dirty = GNUNET_YES;
1478  }
1479  GNUNET_free (spos->name);
1481  GNUNET_free (spos->hint_secret_stat);
1483  GNUNET_free (spos);
1484  return;
1485  }
1486  prev = spos;
1487  spos = spos->next;
1488  }
1489 }
char * hint_filename
Diagnostics information for the filename.
Definition: configuration.c:62
char * key
key for this entry
Definition: configuration.c:52
char * val
current, committed value
Definition: configuration.c:57
char * hint_inlined_from_filename
For secret sections: Where was this inlined from?
struct ConfigEntry * entries
entries in the section
Definition: configuration.c:84
char * hint_secret_filename
Diagnostics hint for the secret file.
char * hint_secret_stat
Extra information regarding permissions of the secret file.

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

Referenced by GNUNET_CONFIGURATION_destroy(), and GNUNET_TESTING_peer_configure().

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_SYSERR on error

Definition at line 1624 of file configuration.c.

1642 {
1643  struct ConfigEntry *e;
1644  char dummy[2];
1645 
1646  if (NULL == (e = find_entry (cfg, section, option)))
1647  return GNUNET_SYSERR;
1648  if (NULL == e->val)
1649  return GNUNET_SYSERR;
1650  if (1 != sscanf (e->val, "%llu%1s", number, dummy))
1651  return GNUNET_SYSERR;
1652  return GNUNET_OK;
1653 }
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 Experiment * e
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
uint32_t number

Referenced by client_configure_plugin(), event_cb(), GCD_init(), GCO_init(), GDS_NEIGHBOURS_init(), GDS_NSE_init(), get_server_addresses(), GNUNET_ATS_solvers_load_quotas(), GNUNET_CLIENT_connect(), GNUNET_CLIENT_test(), GNUNET_HOSTLIST_server_start(), GNUNET_NAT_AUTO_test_start(), GNUNET_REVOCATION_revoke(), GNUNET_SERVICE_run_(), GNUNET_SOCKS_do_connect(), GNUNET_TESTBED_controller_connect(), GNUNET_TESTBED_run(), GNUNET_TRANSPORT_communicator_connect(), GSF_cadet_start_server(), GSF_pending_request_init_(), GST_plugins_load(), iopen(), LEGACY_SERVICE_get_server_addresses(), LEGACY_SERVICE_run(), libgnunet_plugin_block_revocation_init(), libgnunet_plugin_datastore_heap_init(), libgnunet_plugin_dhtu_ip_init(), libgnunet_plugin_transport_tcp_init(), libgnunet_plugin_transport_udp_init(), load_member_session(), load_op_add_address(), load_op_del_address(), load_op_start_request(), load_op_start_set_preference(), load_op_start_set_property(), load_op_stop_request(), load_op_stop_set_preference(), load_op_stop_set_property(), load_operation(), run(), run_service(), server_configure_plugin(), server_get_addresses(), setup_exit_helper_args(), test_service_configuration(), test_stun(), testbed_run(), and update_config().

Here is the caller 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_SYSERR on error

Definition at line 1624 of file configuration.c.

1662 {
1663  struct ConfigEntry *e;
1664  char dummy[2];
1665 
1666  if (NULL == (e = find_entry (cfg, section, option)))
1667  return GNUNET_SYSERR;
1668  if (NULL == e->val)
1669  return GNUNET_SYSERR;
1670  if (1 != sscanf (e->val, "%f%1s", number, dummy))
1671  return GNUNET_SYSERR;
1672  return GNUNET_OK;
1673 }

Referenced by GNUNET_RPS_connect(), and libgnunet_plugin_ats_proportional_init().

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_SYSERR on error

Definition at line 1624 of file configuration.c.

1682 {
1683  struct ConfigEntry *e;
1684  int ret;
1685 
1686  if (NULL == (e = find_entry (cfg, section, option)))
1687  return GNUNET_SYSERR;
1688  if (NULL == e->val)
1689  return GNUNET_SYSERR;
1691  if (GNUNET_OK != ret)
1693  section,
1694  option,
1695  _ ("Not a valid relative time specification"));
1696  return ret;
1697 }
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.
int 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:284

Referenced by GCD_init(), GNUNET_ATS_solvers_experimentation_load(), GNUNET_REVOCATION_revoke(), GNUNET_SPEEDUP_start_(), GNUNET_TESTBED_run(), GSF_push_init_(), GST_manipulation_init(), libgnunet_plugin_block_revocation_init(), libgnunet_plugin_transport_tcp_init(), libgnunet_plugin_transport_udp_init(), load_episodes(), load_op_start_set_preference(), load_op_start_set_property(), RECLAIM_TICKETS_init(), run(), setup_service(), testbed_run(), and token_endpoint().

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_SYSERR on error

Definition at line 1624 of file configuration.c.

1706 {
1707  struct ConfigEntry *e;
1708 
1709  if (NULL == (e = find_entry (cfg, section, option)))
1710  return GNUNET_SYSERR;
1711  if (NULL == e->val)
1712  return GNUNET_SYSERR;
1713  return GNUNET_STRINGS_fancy_size_to_bytes (e->val, size);
1714 }
int 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:260

Referenced by GNUNET_DATACACHE_create(), and run().

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

1813 {
1814  struct ConfigEntry *e;
1815 
1816  if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1817  return GNUNET_NO;
1818  return GNUNET_YES;
1819 }

Referenced by check_config(), GDS_NSE_init(), get_my_cnf_path(), get_server_addresses(), GNUNET_CLIENT_connect(), GNUNET_CLIENT_test(), GNUNET_CONFIGURATION_load(), GNUNET_HOSTLIST_server_start(), GNUNET_SERVICE_run_(), GNUNET_SOCKS_check_service(), GNUNET_TESTBED_run(), GNUNET_TESTING_peer_configure(), iopen(), LEGACY_SERVICE_get_server_addresses(), LEGACY_SERVICE_run(), LEGACY_SERVICE_stop(), process_acl4(), process_acl6(), server_configure_plugin(), server_get_addresses(), setup_service(), test_service_configuration(), and update_config_sections().

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_SYSERR on error

Definition at line 1624 of file configuration.c.

1733 {
1734  struct ConfigEntry *e;
1735 
1736  if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1737  {
1738  *value = NULL;
1739  return GNUNET_SYSERR;
1740  }
1741  *value = GNUNET_strdup (e->val);
1742  return GNUNET_OK;
1743 }

Referenced by advertise_dns_exit(), check_authorization(), check_config(), client_configure_plugin(), communicator_start(), expand_dollar(), GAS_plugin_init(), get_bootstrap_server(), get_server_addresses(), gg_load_configuration(), GNUNET_ATS_solvers_experimentation_load(), GNUNET_ATS_solvers_load_quotas(), GNUNET_CLIENT_connect(), GNUNET_CLIENT_test(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_iterate_value_filenames(), GNUNET_CONVERSATION_phone_create(), GNUNET_DATACACHE_create(), GNUNET_FS_unindex_do_extract_keywords_(), GNUNET_GNS_lookup_with_tld(), GNUNET_HOSTLIST_client_start(), GNUNET_HOSTLIST_server_start(), GNUNET_OS_get_suid_binary_path(), GNUNET_PQ_connect_with_cfg2(), GNUNET_SERVICE_run_(), GNUNET_SOCKS_do_connect(), GNUNET_TESTBED_run(), GNUNET_TESTING_peer_configure(), GNUNET_TESTING_service_run(), gnunet_uri(), GPI_plugins_load(), GST_plugins_load(), handle_ego_delete(), handle_ego_rename(), handle_get_default_message(), handle_init(), handle_register(), identity_continuation(), iopen(), LEGACY_SERVICE_get_server_addresses(), LEGACY_SERVICE_run(), LEGACY_SERVICE_stop(), libgnunet_plugin_dhtu_ip_init(), libgnunet_plugin_transport_udp_init(), load_episode(), load_member_session(), load_member_session_next(), load_op_add_address(), load_op_del_address(), load_op_start_set_preference(), load_op_start_set_property(), load_op_stop_set_preference(), load_op_stop_set_property(), load_quota(), login_redirect(), print_quotas(), process_acl4(), process_acl6(), read_service_conf(), run(), server_configure_plugin(), server_get_addresses(), setup_exit_helper_args(), setup_service(), start_process(), test_icmp_client(), test_icmp_server(), test_service_configuration(), testbed_run(), token_endpoint(), and update_config_sections().

◆ 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_SYSERR on error

Definition at line 1985 of file configuration.c.

2015 {
2016  char *tmp;
2017 
2018  if (GNUNET_OK !=
2019  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp))
2020  {
2021  LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to retrieve filename\n");
2022  *value = NULL;
2023  return GNUNET_SYSERR;
2024  }
2027  GNUNET_free (tmp);
2028  if (*value == NULL)
2029  return GNUNET_SYSERR;
2030  return GNUNET_OK;
2031 }
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...
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.

Referenced by create_service(), database_setup(), get_my_cnf_path(), get_pid_file_name(), get_serialization_file_name(), get_serialization_file_name_in_dir(), get_server_addresses(), get_update_information_directory(), get_user_name(), GNUNET_ATS_solvers_experimentation_load(), GNUNET_CLIENT_test(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CRYPTO_eddsa_key_create_from_configuration(), GNUNET_FRIENDS_parse(), GNUNET_FRIENDS_write_start(), GNUNET_HOSTLIST_client_start(), GNUNET_PQ_connect_with_cfg2(), GNUNET_TESTBED_controller_start(), GNUNET_TESTBED_is_host_habitable(), GNUNET_TESTBED_run(), GNUNET_TESTING_peer_configure(), GST_stats_init(), LEGACY_SERVICE_get_server_addresses(), libgnunet_plugin_transport_unix_init(), load(), load_hostlist_file(), logger_run(), main_init(), new_sub(), print_filename_option(), read_index_list(), run(), run_service(), save(), save_hostlist_file(), setup_service(), test_service_configuration(), testbed_run(), tokenizer_cb(), try_unixpath(), write_index_list(), and write_proof().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_iterate_value_filenames()

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

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

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

Definition at line 2055 of file configuration.c.

2061 {
2062  char *list;
2063  char *pos;
2064  char *end;
2065  char old;
2066  int ret;
2067 
2068  if (GNUNET_OK !=
2069  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list))
2070  return 0;
2071  GNUNET_assert (list != NULL);
2072  ret = 0;
2073  pos = list;
2074  while (1)
2075  {
2076  while (pos[0] == ' ')
2077  pos++;
2078  if (strlen (pos) == 0)
2079  break;
2080  end = pos + 1;
2081  while ((end[0] != ' ') && (end[0] != '\0'))
2082  {
2083  if (end[0] == '\\')
2084  {
2085  switch (end[1])
2086  {
2087  case '\\':
2088  case ' ':
2089  memmove (end, &end[1], strlen (&end[1]) + 1);
2090 
2091  case '\0':
2092  /* illegal, but just keep it */
2093  break;
2094 
2095  default:
2096  /* illegal, but just ignore that there was a '/' */
2097  break;
2098  }
2099  }
2100  end++;
2101  }
2102  old = end[0];
2103  end[0] = '\0';
2104  if (strlen (pos) > 0)
2105  {
2106  ret++;
2107  if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos)))
2108  {
2109  ret = GNUNET_SYSERR;
2110  break;
2111  }
2112  }
2113  if (old == '\0')
2114  break;
2115  pos = end + 1;
2116  }
2117  GNUNET_free (list);
2118  return ret;
2119 }
static int list
Set if we should print a list of currently running services.
Definition: gnunet-arm.c:69

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

Here is the call 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 1405 of file configuration.c.

1410 {
1411  struct ConfigSection *spos;
1412  struct ConfigEntry *epos;
1413 
1414  spos = cfg->sections;
1415  while ((spos != NULL) && (0 != strcasecmp (spos->name, section)))
1416  spos = spos->next;
1417  if (NULL == spos)
1418  return;
1419  if (spos->inaccessible)
1420  {
1422  "Section '%s' is marked as inaccessible, because the configuration "
1423  " file that contains the section can't be read.\n",
1424  section);
1425  return;
1426  }
1427  for (epos = spos->entries; NULL != epos; epos = epos->next)
1428  if (NULL != epos->val)
1429  iter (iter_cls, spos->name, epos->key, epos->val);
1430 }
bool inaccessible
Is the configuration section marked as inaccessible?
Definition: configuration.c:97

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

Referenced by associate_shared_service(), authorize_endpoint(), auto_config_cb(), get_cont(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_TESTING_system_create_with_portrange(), read_blacklist_configuration(), 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_SYSERR on error

Definition at line 1624 of file configuration.c.

1753 {
1754  struct ConfigEntry *e;
1755  unsigned int i;
1756 
1757  if (NULL == (e = find_entry (cfg, section, option)))
1758  return GNUNET_SYSERR;
1759  for (i = 0; NULL != choices[i]; i++)
1760  if (0 == strcasecmp (choices[i], e->val))
1761  break;
1762  if (NULL == choices[i])
1763  {
1765  _ ("Configuration value '%s' for '%s'"
1766  " in section '%s' is not in set of legal choices\n"),
1767  e->val,
1768  option,
1769  section);
1770  return GNUNET_SYSERR;
1771  }
1772  *value = choices[i];
1773  return GNUNET_OK;
1774 }

Referenced by start_process().

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_YES, GNUNET_NO or if option has no valid value, GNUNET_SYSERR

Definition at line 1985 of file configuration.c.

2039 {
2040  static const char *yesno[] = { "YES", "NO", NULL };
2041  const char *val;
2042  int ret;
2043 
2044  ret =
2045  GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
2046  if (ret == GNUNET_SYSERR)
2047  return ret;
2048  if (val == yesno[0])
2049  return GNUNET_YES;
2050  return GNUNET_NO;
2051 }
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.

Referenced by advertise_dns_exit(), client_configure_plugin(), create_listen_socket(), database_setup(), GDS_NEIGHBOURS_init(), get_server_addresses(), gg_load_configuration(), GNS_resolver_init(), GNUNET_ATS_solvers_experimentation_load(), GNUNET_CONNECTION_create_from_connect_to_unixpath(), GNUNET_DATACACHE_create(), GNUNET_STATISTICS_create(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(), GSF_pending_request_init_(), GSF_push_init_(), LEGACY_SERVICE_get_server_addresses(), libgnunet_plugin_datacache_sqlite_init(), libgnunet_plugin_transport_http_client_init(), libgnunet_plugin_transport_tcp_init(), libgnunet_plugin_transport_udp_init(), libgnunet_plugin_transport_unix_init(), main_init(), parse_ip_options(), run(), server_configure_plugin(), setup_broadcast(), setup_service(), sign_ephemeral_key(), start_process(), tcp_address_to_sockaddr_port_only(), test_icmp_client(), test_icmp_server(), test_master(), udp_address_to_sockaddr(), and update_config().

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

1783 {
1784  char *enc;
1785  int res;
1786  size_t data_size;
1787 
1788  if (GNUNET_OK !=
1789  (res =
1790  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &enc)))
1791  return res;
1792  data_size = (strlen (enc) * 5) / 8;
1793  if (data_size != buf_size)
1794  {
1795  GNUNET_free (enc);
1796  return GNUNET_SYSERR;
1797  }
1798  if (GNUNET_OK !=
1799  GNUNET_STRINGS_string_to_data (enc, strlen (enc), buf, buf_size))
1800  {
1801  GNUNET_free (enc);
1802  return GNUNET_SYSERR;
1803  }
1804  GNUNET_free (enc);
1805  return GNUNET_OK;
1806 }
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
static int res
static OpusEncoder * enc
OPUS encoder.
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:775

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

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

1988 {
1989  char *dup;
1990  size_t i;
1991  size_t len;
1992 
1993  for (i = 0; '\0' != orig[i]; i++)
1994  {
1995  if ('$' != orig[i])
1996  continue;
1997  dup = GNUNET_strdup (orig + i);
1998  dup = expand_dollar (cfg, dup, 0);
1999  GNUNET_assert (NULL != dup); /* make compiler happy */
2000  len = strlen (dup) + 1;
2001  orig = GNUNET_realloc (orig, i + len);
2002  GNUNET_memcpy (orig + i, dup, len);
2003  GNUNET_free (dup);
2004  }
2005  return orig;
2006 }
static char * expand_dollar(const struct GNUNET_CONFIGURATION_Handle *cfg, char *orig, unsigned int depth)
Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" where either in the "PATHS" section or...
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.

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

Referenced by expand_dollar(), GNUNET_TESTING_peer_start(), run(), 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 1624 of file configuration.c.

1628 {
1629  char s[64];
1630 
1631  GNUNET_snprintf (s, 64, "%llu", number);
1632  GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s);
1633 }
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.

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

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

1586 {
1587  struct ConfigSection *sec;
1588  struct ConfigEntry *e;
1589  char *nv;
1590 
1591  e = find_entry (cfg, section, option);
1592  if (NULL != e)
1593  {
1594  if (NULL == value)
1595  {
1596  GNUNET_free (e->val);
1597  e->val = NULL;
1598  }
1599  else
1600  {
1601  nv = GNUNET_strdup (value);
1602  GNUNET_free (e->val);
1603  e->val = nv;
1604  }
1605  return;
1606  }
1607  sec = find_section (cfg, section);
1608  if (sec == NULL)
1609  {
1610  sec = GNUNET_new (struct ConfigSection);
1611  sec->name = GNUNET_strdup (section);
1612  sec->next = cfg->sections;
1613  cfg->sections = sec;
1614  }
1615  e = GNUNET_new (struct ConfigEntry);
1616  e->key = GNUNET_strdup (option);
1617  e->val = GNUNET_strdup (value);
1618  e->next = sec->entries;
1619  sec->entries = e;
1620 }
static struct ConfigSection * find_section(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Find a section entry from a configuration.

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

Referenced by associate_shared_service(), auto_conf_iter(), auto_config_cb(), cfg_copy_iterator(), compare_entries(), copy_entry(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_get_data(), GNUNET_CONFIGURATION_load(), GNUNET_NAT_autoconfig_start(), GNUNET_TESTING_configuration_create_(), handle_ego_delete(), handle_ego_rename(), handle_set_default_message(), helper_mst(), identity_cb(), iterate_save_rooms(), next_phase(), process_if(), result_callback(), run(), save_member(), 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 2129 of file configuration.c.

2217 {
2218  char *list;
2219  char *pos;
2220  char *end;
2221  char *match;
2222  char old;
2223 
2224  if (GNUNET_OK !=
2225  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list))
2226  return GNUNET_NO;
2227  match = escape_name (value);
2228  pos = list;
2229  while (1)
2230  {
2231  while (pos[0] == ' ')
2232  pos++;
2233  if (strlen (pos) == 0)
2234  break;
2235  end = pos + 1;
2236  while ((end[0] != ' ') && (end[0] != '\0'))
2237  {
2238  if (end[0] == '\\')
2239  {
2240  switch (end[1])
2241  {
2242  case '\\':
2243  case ' ':
2244  end++;
2245  break;
2246 
2247  case '\0':
2248  /* illegal, but just keep it */
2249  break;
2250 
2251  default:
2252  /* illegal, but just ignore that there was a '/' */
2253  break;
2254  }
2255  }
2256  end++;
2257  }
2258  old = end[0];
2259  end[0] = '\0';
2260  if (0 == strcmp (pos, match))
2261  {
2262  if (old != '\0')
2263  memmove (pos, &end[1], strlen (&end[1]) + 1);
2264  else
2265  {
2266  if (pos != list)
2267  pos[-1] = '\0';
2268  else
2269  pos[0] = '\0';
2270  }
2271  GNUNET_CONFIGURATION_set_value_string (cfg, section, option, list);
2272  GNUNET_free (list);
2273  GNUNET_free (match);
2274  return GNUNET_OK;
2275  }
2276  if (old == '\0')
2277  break;
2278  end[0] = old;
2279  pos = end + 1;
2280  }
2281  GNUNET_free (list);
2282  GNUNET_free (match);
2283  return GNUNET_NO;
2284 }
static char * escape_name(const char *value)
FIXME.

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

2182 {
2183  char *escaped;
2184  char *old;
2185  char *nw;
2186 
2187  if (GNUNET_SYSERR ==
2189  section,
2190  option,
2191  &test_match,
2192  (void *) value))
2193  return GNUNET_NO; /* already exists */
2194  if (GNUNET_OK !=
2195  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
2196  old = GNUNET_strdup ("");
2197  escaped = escape_name (value);
2198  nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2);
2199  strcpy (nw, old);
2200  if (strlen (old) > 0)
2201  strcat (nw, " ");
2202  strcat (nw, escaped);
2203  GNUNET_CONFIGURATION_set_value_string (cfg, section, option, nw);
2204  GNUNET_free (old);
2205  GNUNET_free (nw);
2206  GNUNET_free (escaped);
2207  return GNUNET_OK;
2208 }
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 GNUNET_malloc, and value.

◆ 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 293 of file configuration_helper.c.

295 {
296  GNUNET_free (cs->option);
297  GNUNET_free (cs->section);
298  GNUNET_free (cs->value);
299 }

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 107 of file configuration_helper.c.

112 {
113  struct GNUNET_CONFIGURATION_ConfigSettings *cs = cls;
114  struct GNUNET_CONFIGURATION_Handle *out = NULL;
115  struct GNUNET_CONFIGURATION_Handle *ncfg = NULL;
116 
117  (void) args;
118  if (cs->diagnostics)
119  {
120  /* Re-parse the configuration with diagnostics enabled. */
121  ncfg = GNUNET_CONFIGURATION_create ();
124  cfgfile);
125  cfg = ncfg;
126  }
127 
128  if (cs->full)
129  cs->rewrite = GNUNET_YES;
130  if (cs->list_sections)
131  {
132  fprintf (stderr,
133  _ ("The following sections are available:\n"));
136  NULL);
137  return;
138  }
139  if ( (! cs->rewrite) &&
140  (NULL == cs->section) )
141  {
142  char *serialization;
143 
144  if (! cs->diagnostics)
145  {
146  fprintf (stderr,
147  _ ("%s, %s or %s argument is required\n"),
148  "--section",
149  "--list-sections",
150  "--diagnostics");
152  return;
153  }
155  fprintf (stdout,
156  "%s",
157  serialization);
158  GNUNET_free (serialization);
159  }
160  else if ( (NULL != cs->section) &&
161  (NULL == cs->value) )
162  {
163  if (NULL == cs->option)
164  {
166  cfg,
167  cs->section,
168  cs->is_filename
170  : &print_option,
171  (void *) cfg);
172  }
173  else
174  {
175  char *value;
176 
177  if (cs->is_filename)
178  {
179  if (GNUNET_OK !=
181  cs->section,
182  cs->option,
183  &value))
184  {
186  cs->section,
187  cs->option);
189  return;
190  }
191  }
192  else
193  {
194  if (GNUNET_OK !=
196  cs->section,
197  cs->option,
198  &value))
199  {
201  cs->section,
202  cs->option);
204  return;
205  }
206  }
207  fprintf (stdout,
208  "%s\n",
209  value);
210  GNUNET_free (value);
211  }
212  }
213  else if (NULL != cs->section)
214  {
215  if (NULL == cs->option)
216  {
217  fprintf (stderr,
218  _ ("--option argument required to set value\n"));
220  return;
221  }
224  cs->section,
225  cs->option,
226  cs->value);
227  cs->rewrite = GNUNET_YES;
228  }
229  if (cs->rewrite)
230  {
231  char *cfg_fn = NULL;
232 
233  if (NULL == out)
235 
236  if (NULL == cfgfile)
237  {
238  const char *xdg = getenv ("XDG_CONFIG_HOME");
239 
240  if (NULL != xdg)
241  GNUNET_asprintf (&cfg_fn,
242  "%s%s%s",
243  xdg,
246  else
247  cfg_fn = GNUNET_strdup (
248  GNUNET_OS_project_data_get ()->user_config_file);
249  cfgfile = cfg_fn;
250  }
251 
252  if (! cs->full)
253  {
254  struct GNUNET_CONFIGURATION_Handle *def;
255 
257  if (GNUNET_OK !=
259  NULL))
260  {
261  fprintf (stderr,
262  _ ("failed to load configuration defaults"));
263  cs->global_ret = 1;
266  GNUNET_free (cfg_fn);
267  return;
268  }
269  if (GNUNET_OK !=
271  out,
272  cfgfile))
273  cs->global_ret = 2;
275  }
276  else
277  {
278  if (GNUNET_OK !=
280  cfgfile))
281  cs->global_ret = 2;
282  }
283  GNUNET_free (cfg_fn);
284  }
285  if (NULL != out)
287  if (NULL != ncfg)
289 }
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.
static char * config_file
Set to the name of the config file used.
Definition: gnunet-arm.c:84
void GNUNET_CONFIGURATION_iterate_sections(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Section_Iterator iter, void *iter_cls)
Iterate over all sections in the configuration.
char * GNUNET_CONFIGURATION_serialize_diagnostics(const struct GNUNET_CONFIGURATION_Handle *cfg)
Serializes the given configuration with diagnostics information.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
void GNUNET_CONFIGURATION_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.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
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:252
#define EXIT_NOTCONFIGURED
Definition: platform.h:268
Closure for GNUNET_CONFIGURATION_config_tool_run() with settings for what should be done with the con...
int full
Should the generated configuration file contain the whole configuration?
int global_ret
Return value from the operation, to be returned from 'main'.
int diagnostics
Should we give extra diagnostics?
int list_sections
Whether to show the sections.
int rewrite
Should we write out the configuration file, even if no value was changed?
int is_filename
Treat option as a filename.

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

Referenced by run().

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