GNUnet  0.20.0
Configuration library

Configuration management. More...

Collaboration diagram for Configuration library:

Data Structures

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

Macros

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

Typedefs

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

Functions

struct GNUNET_CONFIGURATION_HandleGNUNET_CONFIGURATION_create (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_SectionIterator iter, void *iter_cls)
 Iterate over all sections in the configuration. More...
 
void GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
 Remove the given section and all options in it. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
 Get a configuration value that should be a number. More...
 
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 716 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 223 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 286 of file gnunet_configuration_lib.h.

◆ GNUNET_CONFIGURATION_SectionIterator

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

Function to iterate over section.

Parameters
clsclosure
sectionname of the section

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

224 {
226  char *p;
227 
229  /* make certain values from the project data available
230  as PATHS */
232  if (NULL != p)
233  {
235  "PATHS",
236  "DATADIR",
237  p);
238  GNUNET_free (p);
239  }
241  if (NULL != p)
242  {
244  "PATHS",
245  "LIBDIR",
246  p);
247  GNUNET_free (p);
248  }
250  if (NULL != p)
251  {
253  "PATHS",
254  "BINDIR",
255  p);
256  GNUNET_free (p);
257  }
259  if (NULL != p)
260  {
262  "PATHS",
263  "PREFIX",
264  p);
265  GNUNET_free (p);
266  }
268  if (NULL != p)
269  {
271  "PATHS",
272  "LOCALEDIR",
273  p);
274  GNUNET_free (p);
275  }
277  if (NULL != p)
278  {
280  "PATHS",
281  "ICONDIR",
282  p);
283  GNUNET_free (p);
284  }
286  if (NULL != p)
287  {
289  "PATHS",
290  "DOCDIR",
291  p);
292  GNUNET_free (p);
293  }
295  if (NULL != p)
296  {
298  "PATHS",
299  "LIBEXECDIR",
300  p);
301  GNUNET_free (p);
302  }
303  return cfg;
304 }
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-uri.c:38
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_OS_installation_get_path(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(), 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 1529 of file configuration.c.

1530 {
1532 
1535  return ret;
1536 }
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 308 of file configuration.c.

309 {
310  struct ConfigSection *sec;
311  struct ConfigFile *cf;
312 
313  while (NULL != (sec = cfg->sections))
315  while (NULL != (cf = cfg->loaded_files_head))
316  {
321  cf);
322  GNUNET_free (cf);
323  }
325  GNUNET_free (cfg);
326 }
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:72
char * name
name of the section
Definition: configuration.c:86
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.

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_run(), tokenizer_cb(), and update_peer_config().

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

2498 {
2499  char *baseconfig;
2500  const char *base_config_varname;
2501 
2502  if (cfg->load_called)
2503  {
2504  /* FIXME: Make this a GNUNET_assert later */
2505  GNUNET_break (0);
2507  }
2508  cfg->load_called = true;
2509  if (NULL != filename)
2510  {
2513  }
2514 
2515  base_config_varname = GNUNET_OS_project_data_get ()->base_config_varname;
2516 
2517  if ((NULL != base_config_varname)
2518  && (NULL != (baseconfig = getenv (base_config_varname))))
2519  {
2520  baseconfig = GNUNET_strdup (baseconfig);
2521  }
2522  else
2523  {
2524  char *ipath;
2525 
2527  if (NULL == ipath)
2528  {
2529  GNUNET_break (0);
2530  return GNUNET_SYSERR;
2531  }
2532  GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d");
2533  GNUNET_free (ipath);
2534  }
2535 
2536  char *dname = GNUNET_STRINGS_filename_expand (baseconfig);
2537  GNUNET_free (baseconfig);
2538 
2539  if ((GNUNET_YES ==
2541  GNUNET_YES)) &&
2542  (GNUNET_SYSERR ==
2544  dname)))
2545  {
2547  "Failed to load base configuration from '%s'\n",
2548  filename);
2549  GNUNET_free (dname);
2550  return GNUNET_SYSERR; /* no configuration at all found */
2551  }
2552  GNUNET_free (dname);
2553  if ((NULL != filename) &&
2554  (GNUNET_OK !=
2556  filename)))
2557  {
2558  /* specified configuration not found */
2560  "Failed to load configuration from file '%s'\n",
2561  filename);
2562  return GNUNET_SYSERR;
2563  }
2564  if (((GNUNET_YES !=
2566  "PATHS",
2567  "DEFAULTCONFIG"))) &&
2568  (filename != NULL))
2570  "PATHS",
2571  "DEFAULTCONFIG",
2572  filename);
2573  return GNUNET_OK;
2574 }
#define LOG(kind,...)
Definition: configuration.c:31
char * getenv()
static char * filename
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Parse a configuration file, add all of the options in the file to the configuration environment.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load_from(struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d)
Load default configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:403
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
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:494
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...

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

2333 {
2334  struct CollectFilesContext files_context = {
2335  .files = NULL,
2336  .files_length = 0,
2337  };
2338  enum GNUNET_GenericReturnValue fun_ret;
2339 
2340  if (GNUNET_SYSERR ==
2342  &files_context))
2343  return GNUNET_SYSERR; /* no configuration at all found */
2344  qsort (files_context.files,
2345  files_context.files_length,
2346  sizeof (char *),
2347  pstrcmp);
2348  for (unsigned int i = 0; i < files_context.files_length; i++)
2349  {
2350  char *ext;
2351  const char *filename = files_context.files[i];
2352 
2353  /* Examine file extension */
2354  ext = strrchr (filename, '.');
2355  if ((NULL == ext) || (0 != strcmp (ext, ".conf")))
2356  {
2357  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Skipping file `%s'\n", filename);
2358  fun_ret = GNUNET_OK;
2359  goto cleanup;
2360  }
2362  if (fun_ret != GNUNET_OK)
2363  break;
2364  }
2365 cleanup:
2366  if (files_context.files_length > 0)
2367  {
2368  for (size_t i = 0; i < files_context.files_length; i++)
2369  GNUNET_free (files_context.files[i]);
2370  GNUNET_array_grow (files_context.files,
2371  files_context.files_length,
2372  0);
2373  }
2374  return fun_ret;
2375 }
static int pstrcmp(const void *a, const void *b)
static enum GNUNET_GenericReturnValue collect_files_cb(void *cls, const char *filename)
Function called with a filename.
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
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_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
Closure to collect_files_cb.
char ** files
Collected files from globbing.
unsigned int files_length
Size of the files array.

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

2422 {
2423  const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
2425  const char *xdg = getenv ("XDG_CONFIG_HOME");
2426  char *cfgname = NULL;
2428 
2429  /* Makes sure function implicitly looking at the installation directory (for
2430  example GNUNET_CONFIGURATION_load further down) use GNUnet's environment
2431  instead of the caller's. It's done at the start to make sure as many
2432  functions as possible are directed to the proper paths. */
2433  GNUNET_OS_init (dpd);
2434 
2436 
2437  /* First, try user configuration. */
2438  if (NULL != xdg)
2439  GNUNET_asprintf (&cfgname, "%s/%s", xdg, dpd->config_file);
2440  else
2441  cfgname = GNUNET_strdup (dpd->user_config_file);
2442 
2443  /* If user config doesn't exist, try in
2444  /etc/<projdir>/<cfgfile> and /etc/<cfgfile> */
2445  if (GNUNET_OK != GNUNET_DISK_file_test (cfgname))
2446  {
2447  GNUNET_free (cfgname);
2448  GNUNET_asprintf (&cfgname, "/etc/%s", dpd->config_file);
2449  }
2450  if (GNUNET_OK != GNUNET_DISK_file_test (cfgname))
2451  {
2452  GNUNET_free (cfgname);
2453  GNUNET_asprintf (&cfgname,
2454  "/etc/%s/%s",
2455  dpd->project_dirname,
2456  dpd->config_file);
2457  }
2458  if (GNUNET_OK != GNUNET_DISK_file_test (cfgname))
2459  {
2461  "Unable to top-level configuration file.\n");
2462  GNUNET_OS_init (pd);
2464  GNUNET_free (cfgname);
2465  return NULL;
2466  }
2467 
2468  /* We found a configuration file that looks good, try to load it. */
2469 
2471  "Loading top-level configuration from '%s'\n",
2472  cfgname);
2473  if (GNUNET_OK !=
2474  GNUNET_CONFIGURATION_load (cfg, cfgname))
2475  {
2476  GNUNET_OS_init (pd);
2478  GNUNET_free (cfgname);
2479  return NULL;
2480  }
2481  GNUNET_free (cfgname);
2482  GNUNET_OS_init (pd);
2483  return cfg;
2484 }
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration (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 2379 of file configuration.c.

2380 {
2381  char *cfg_fn;
2382  const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
2383  const char *xdg = getenv ("XDG_CONFIG_HOME");
2384 
2385  if (NULL != xdg)
2386  GNUNET_asprintf (&cfg_fn,
2387  "%s%s%s",
2388  xdg,
2390  pd->config_file);
2391  else
2392  cfg_fn = GNUNET_strdup (pd->user_config_file);
2393 
2394  if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2395  return cfg_fn;
2396  GNUNET_free (cfg_fn);
2397 
2398  /* Fall back to /etc/ for the default configuration.
2399  Should be okay to use forward slashes here. */
2400 
2401  GNUNET_asprintf (&cfg_fn,
2402  "/etc/%s",
2403  pd->config_file);
2404  if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2405  return cfg_fn;
2406  GNUNET_free (cfg_fn);
2407 
2408  GNUNET_asprintf (&cfg_fn,
2409  "/etc/%s/%s",
2410  pd->project_dirname,
2411  pd->config_file);
2412  if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2413  return cfg_fn;
2414 
2415  GNUNET_free (cfg_fn);
2416  return NULL;
2417 }
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:166

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

970 {
971  uint64_t fs64;
972  size_t fs;
973  char *fn;
974  char *mem;
975  int dirty;
977  ssize_t sret;
978 
980  LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to parse config file `%s'\n", fn);
981  if (NULL == fn)
982  return GNUNET_SYSERR;
983 
984 
985  /* Check for cycles */
986  {
987  unsigned int lvl = cfg->current_nest_level;
988  struct ConfigFile *cf = cfg->loaded_files_tail;
989  struct ConfigFile *parent = NULL;
990 
991 
992  for (; NULL != cf; parent = cf, cf = cf->prev)
993  {
994  /* Check parents based on level, skipping children of siblings. */
995  if (cf->level >= lvl)
996  continue;
997  lvl = cf->level;
998  if ( (NULL == cf->source_filename) || (NULL == filename))
999  continue;
1000  if (0 == strcmp (cf->source_filename, filename))
1001  {
1002  if (NULL == parent)
1003  {
1005  "Forbidden direct cyclic configuration import (%s -> %s)\n",
1006  cf->source_filename,
1007  filename);
1008  }
1009  else
1011  "Forbidden indirect cyclic configuration import (%s -> ... -> %s -> %s)\n",
1012  cf->source_filename,
1013  parent->source_filename,
1014  filename);
1015  GNUNET_free (fn);
1016  return GNUNET_SYSERR;
1017  }
1018  }
1019 
1020  }
1021 
1022  /* Keep track of loaded files.*/
1023  {
1024  struct ConfigFile *cf = GNUNET_new (struct ConfigFile);
1025 
1026  cf->level = cfg->current_nest_level;
1027  cf->source_filename = GNUNET_strdup (filename ? filename : "<input>");
1030  cf);
1031  }
1032 
1033  dirty = cfg->dirty; /* back up value! */
1034  if (GNUNET_SYSERR ==
1036  &fs64,
1037  GNUNET_YES,
1038  GNUNET_YES))
1039  {
1041  "Error while determining the file size of `%s'\n",
1042  fn);
1043  GNUNET_free (fn);
1044  return GNUNET_SYSERR;
1045  }
1046  if (fs64 > SIZE_MAX)
1047  {
1048  GNUNET_break (0); /* File size is more than the heap size */
1049  GNUNET_free (fn);
1050  return GNUNET_SYSERR;
1051  }
1052  fs = fs64;
1053  mem = GNUNET_malloc (fs);
1054  sret = GNUNET_DISK_fn_read (fn, mem, fs);
1055  if ((sret < 0) || (fs != (size_t) sret))
1056  {
1058  "Error while reading file `%s'\n",
1059  fn);
1060  GNUNET_free (fn);
1061  GNUNET_free (mem);
1062  return GNUNET_SYSERR;
1063  }
1065  "Deserializing contents of file `%s'\n",
1066  fn);
1068  mem,
1069  fs,
1070  fn);
1071  if (GNUNET_SYSERR == ret)
1072  {
1074  _ ("Failed to parse configuration file `%s'\n"),
1075  fn);
1076  }
1077  GNUNET_free (fn);
1078  GNUNET_free (mem);
1079  /* restore dirty flag - anything we set in the meantime
1080  * came from disk */
1081  cfg->dirty = dirty;
1082  return ret;
1083 }
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:37
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:221
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:178
#define SIZE_MAX
Definition: platform.h:208
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(), 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 1129 of file configuration.c.

1131 {
1132  char *mem;
1133  char *cbuf;
1134  char *val;
1135  char *pos;
1136  size_t m_size;
1137  size_t c_size;
1138 
1139  /* Pass1 : calculate the buffer size required */
1140  m_size = 0;
1141  for (struct ConfigSection *sec = cfg->sections;
1142  NULL != sec;
1143  sec = sec->next)
1144  {
1145  if (sec->inaccessible)
1146  continue;
1147  /* For each section we need to add 3 characters: {'[',']','\n'} */
1148  m_size += strlen (sec->name) + 3;
1149  for (struct ConfigEntry *ent = sec->entries;
1150  NULL != ent;
1151  ent = ent->next)
1152  {
1153  if (do_skip (sec->name,
1154  ent->key))
1155  continue;
1156  if (NULL != ent->val)
1157  {
1158  /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */
1159  pos = ent->val;
1160  while (NULL != (pos = strstr (pos, "\n")))
1161  {
1162  m_size++;
1163  pos++;
1164  }
1165  /* For each key = value pair we need to add 4 characters (2
1166  spaces and 1 equal-to character and 1 new line) */
1167  m_size += strlen (ent->key) + strlen (ent->val) + 4;
1168  }
1169  }
1170  /* A new line after section end */
1171  m_size++;
1172  }
1173 
1174  /* Pass2: Allocate memory and write the configuration to it */
1175  mem = GNUNET_malloc (m_size);
1176  c_size = 0;
1177  *size = c_size;
1178  for (struct ConfigSection *sec = cfg->sections;
1179  NULL != sec;
1180  sec = sec->next)
1181  {
1182  int len;
1183 
1184  len = GNUNET_asprintf (&cbuf,
1185  "[%s]\n",
1186  sec->name);
1187  GNUNET_assert (0 < len);
1188  GNUNET_memcpy (mem + c_size,
1189  cbuf,
1190  len);
1191  c_size += len;
1192  GNUNET_free (cbuf);
1193  for (struct ConfigEntry *ent = sec->entries;
1194  NULL != ent;
1195  ent = ent->next)
1196  {
1197  if (do_skip (sec->name,
1198  ent->key))
1199  continue;
1200  if (NULL != ent->val)
1201  {
1202  val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1203  strcpy (val, ent->val);
1204  while (NULL != (pos = strstr (val, "\n")))
1205  {
1206  memmove (&pos[2], &pos[1], strlen (&pos[1]));
1207  pos[0] = '\\';
1208  pos[1] = 'n';
1209  }
1210  len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
1211  GNUNET_free (val);
1212  GNUNET_memcpy (mem + c_size, cbuf, len);
1213  c_size += len;
1214  GNUNET_free (cbuf);
1215  }
1216  }
1217  GNUNET_memcpy (mem + c_size, "\n", 1);
1218  c_size++;
1219  }
1220  GNUNET_assert (c_size == m_size);
1221  *size = c_size;
1222  return mem;
1223 }
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:68
configuration entry
Definition: configuration.c:40
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:44
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:76

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

1229 {
1230  struct GNUNET_Buffer buf = { 0 };
1231 
1233  "#\n# Configuration file diagnostics\n#\n");
1235  "# Entry point: %s\n",
1237  "<none>");
1239  "#\n# Files Loaded:\n");
1240 
1241  for (struct ConfigFile *cfil = cfg->loaded_files_head;
1242  NULL != cfil;
1243  cfil = cfil->next)
1244  {
1246  "# ");
1247  for (unsigned int i = 0; i < cfil->level; i++)
1249  "+");
1250  if (0 != cfil->level)
1252  " ");
1253 
1255  "%s",
1256  cfil->source_filename);
1257 
1258  if (NULL != cfil->hint_restrict_section)
1260  " (%s secret section %s)",
1261  cfil->hint_inaccessible
1262  ? "inaccessible"
1263  : "loaded",
1264  cfil->hint_restrict_section);
1265 
1267  "\n");
1268  }
1269 
1271  "#\n\n");
1272 
1273  for (struct ConfigSection *sec = cfg->sections;
1274  NULL != sec;
1275  sec = sec->next)
1276  {
1277  if (sec->hint_secret_filename)
1279  "# secret section from %s\n# secret file stat %s\n",
1280  sec->hint_secret_filename,
1281  sec->hint_secret_stat);
1282  if (sec->hint_inlined_from_filename)
1283  {
1285  "# inlined from %s:%u\n",
1286  sec->hint_inlined_from_filename,
1287  sec->hint_inlined_from_line);
1288  }
1290  "[%s]\n\n",
1291  sec->name);
1292  if (sec->inaccessible)
1293  {
1295  "# <section contents inaccessible>\n\n\n");
1296  continue;
1297  }
1298  for (struct ConfigEntry *ent = sec->entries;
1299  NULL != ent;
1300  ent = ent->next)
1301  {
1302  if (do_skip (sec->name,
1303  ent->key))
1304  continue;
1305  if (NULL != ent->val)
1306  {
1307  char *pos;
1308  char *val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1309  strcpy (val, ent->val);
1310  while (NULL != (pos = strstr (val, "\n")))
1311  {
1312  memmove (&pos[2], &pos[1], strlen (&pos[1]));
1313  pos[0] = '\\';
1314  pos[1] = 'n';
1315  }
1316  if (NULL != ent->hint_filename)
1317  {
1319  "# %s:%u\n",
1320  ent->hint_filename,
1321  ent->hint_lineno);
1322  }
1324  "%s = %s\n",
1325  ent->key,
1326  val);
1327  GNUNET_free (val);
1328  }
1329  GNUNET_buffer_write_str (&buf, "\n");
1330  }
1331  GNUNET_buffer_write_str (&buf, "\n");
1332  }
1333  return GNUNET_buffer_reap_str (&buf);
1334 }
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
Dynamically growing buffer.

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

705 {
706  size_t line_size;
707  unsigned int nr;
708  size_t r_bytes;
709  size_t to_read;
711  char *section;
712  char *eq;
713  char *tag;
714  char *value;
715  char *line_orig = NULL;
716 
717  ret = GNUNET_OK;
718  section = NULL;
719  nr = 0;
720  r_bytes = 0;
721  while (r_bytes < size)
722  {
723  char *pos;
724  char *line;
725  bool emptyline;
726 
727  GNUNET_free (line_orig);
728  /* fgets-like behaviour on buffer */
729  to_read = size - r_bytes;
730  pos = memchr (&mem[r_bytes], '\n', to_read);
731  if (NULL == pos)
732  {
733  line_orig = GNUNET_strndup (&mem[r_bytes],
734  line_size = to_read);
735  r_bytes += line_size;
736  }
737  else
738  {
739  line_orig = GNUNET_strndup (&mem[r_bytes],
740  line_size = (pos - &mem[r_bytes]));
741  r_bytes += line_size + 1;
742  }
743  line = line_orig;
744  /* increment line number */
745  nr++;
746  /* tabs and '\r' are whitespace */
747  emptyline = GNUNET_YES;
748  for (size_t i = 0; i < line_size; i++)
749  {
750  if (line[i] == '\t')
751  line[i] = ' ';
752  if (line[i] == '\r')
753  line[i] = ' ';
754  if (' ' != line[i])
755  emptyline = GNUNET_NO;
756  }
757  /* ignore empty lines */
758  if (GNUNET_YES == emptyline)
759  continue;
760 
761  /* remove tailing whitespace */
762  for (size_t i = line_size - 1;
763  (i >= 1) && (isspace ((unsigned char) line[i]));
764  i--)
765  line[i] = '\0';
766 
767  /* remove leading whitespace */
768  for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++)
769  ;
770 
771  /* ignore comments */
772  if ( ('#' == line[0]) ||
773  ('%' == line[0]) )
774  continue;
775 
776  /* Handle special directives. */
777  if ('@' == line[0])
778  {
779  char *end = strchr (line + 1, '@');
780  char *directive;
781  enum GNUNET_GenericReturnValue directive_ret;
782 
783  if (NULL != cfg->restrict_section)
784  {
786  "Illegal directive in line %u (parsing restricted section %s)\n",
787  nr,
789  ret = GNUNET_SYSERR;
790  break;
791  }
792 
793  if (NULL == end)
794  {
796  "Bad directive in line %u\n",
797  nr);
798  ret = GNUNET_SYSERR;
799  break;
800  }
801  *end = '\0';
802  directive = line + 1;
803 
804  if (0 == strcasecmp (directive,
805  "INLINE"))
806  {
807  const char *path = end + 1;
808 
809  /* Skip space before path */
810  for (; isspace (*path); path++)
811  ;
812 
813  directive_ret = handle_inline (cfg,
814  path,
815  false,
816  NULL,
817  source_filename,
818  nr);
819  }
820  else if (0 == strcasecmp (directive,
821  "INLINE-MATCHING"))
822  {
823  const char *path = end + 1;
824 
825  /* Skip space before path */
826  for (; isspace (*path); path++)
827  ;
828 
829  directive_ret = handle_inline (cfg,
830  path,
831  true,
832  NULL,
833  source_filename,
834  nr);
835  }
836  else if (0 == strcasecmp (directive,
837  "INLINE-SECRET"))
838  {
839  char *secname = end + 1;
840  char *secname_end;
841  const char *path;
842 
843  /* Skip space before secname */
844  for (; isspace (*secname); secname++)
845  ;
846 
847  secname_end = strchr (secname, ' ');
848 
849  if (NULL == secname_end)
850  {
852  "Bad inline-secret directive in line %u\n",
853  nr);
854  ret = GNUNET_SYSERR;
855  break;
856  }
857  *secname_end = '\0';
858  path = secname_end + 1;
859 
860  /* Skip space before path */
861  for (; isspace (*path); path++)
862  ;
863 
864  directive_ret = handle_inline (cfg,
865  path,
866  false,
867  secname,
868  source_filename,
869  nr);
870  }
871  else
872  {
874  "Unknown or malformed directive '%s' in line %u\n",
875  directive,
876  nr);
877  ret = GNUNET_SYSERR;
878  break;
879  }
880  if (GNUNET_OK != directive_ret)
881  {
882  ret = directive_ret;
883  break;
884  }
885  continue;
886  }
887  if ( ('[' == line[0]) &&
888  (']' == 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  "Syntax error while deserializing in line %u (option without section)\n",
905  nr);
906  ret = GNUNET_SYSERR;
907  break;
908  }
909 
910  /* tag = value */
911  tag = GNUNET_strndup (line, eq - line);
912  /* remove tailing whitespace */
913  for (i = strlen (tag) - 1;
914  (i >= 1) && (isspace ((unsigned char) tag[i]));
915  i--)
916  tag[i] = '\0';
917 
918  /* Strip whitespace */
919  value = eq + 1;
920  while (isspace ((unsigned char) value[0]))
921  value++;
922  for (i = strlen (value) - 1;
923  (i >= 1) && (isspace ((unsigned char) value[i]));
924  i--)
925  value[i] = '\0';
926 
927  /* remove quotes */
928  i = 0;
929  if ( ('"' == value[0]) &&
930  ('"' == value[strlen (value) - 1]) )
931  {
932  value[strlen (value) - 1] = '\0';
933  value++;
934  }
936  section,
937  tag,
938  &value[i]);
939  if (cfg->diagnostics)
940  {
942  section,
943  tag,
944  source_filename
945  ? source_filename
946  : "<input>",
947  nr);
948  }
949  GNUNET_free (tag);
950  continue;
951  }
952  /* parse error */
954  "Syntax error while deserializing in line %u\n",
955  nr);
956  ret = GNUNET_SYSERR;
957  break;
958  }
959  GNUNET_free (line_orig);
960  GNUNET_free (section);
961  GNUNET_assert ( (GNUNET_OK != ret) ||
962  (r_bytes == size) );
963  return ret;
964 }
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
#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 1227 of file configuration.c.

1340 {
1341  char *fn;
1342  char *cfg_buf;
1343  size_t size;
1344 
1346  if (fn == NULL)
1347  return GNUNET_SYSERR;
1349  {
1350  GNUNET_free (fn);
1351  return GNUNET_SYSERR;
1352  }
1354  &size);
1355  {
1356  struct GNUNET_DISK_FileHandle *h;
1357 
1358  h = GNUNET_DISK_file_open (fn,
1366  if (NULL == h)
1367  {
1368  GNUNET_free (fn);
1369  GNUNET_free (cfg_buf);
1370  return GNUNET_SYSERR;
1371  }
1372  if (((ssize_t) size) !=
1374  cfg_buf,
1375  size))
1376  {
1378  "write",
1379  fn);
1381  (void) GNUNET_DISK_directory_remove (fn);
1382  GNUNET_free (fn);
1383  GNUNET_free (cfg_buf);
1384  cfg->dirty = GNUNET_SYSERR; /* last write failed */
1385  return GNUNET_SYSERR;
1386  }
1389  }
1390  GNUNET_free (fn);
1391  GNUNET_free (cfg_buf);
1392  cfg->dirty = GNUNET_NO; /* last write succeeded */
1393  return GNUNET_OK;
1394 }
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:1237
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:1087
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
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(), 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 1570 of file configuration.c.

1588 {
1589  int ret;
1590  struct GNUNET_CONFIGURATION_Handle *diff;
1591 
1592  diff = GNUNET_CONFIGURATION_get_diff (cfg_default, cfg_new);
1595  return ret;
1596 }
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 1570 of file configuration.c.

1573 {
1574  struct DiffHandle diffHandle;
1575 
1576  diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
1577  diffHandle.cfg_default = cfg_default;
1578  GNUNET_CONFIGURATION_iterate (cfg_new, &compare_entries, &diffHandle);
1579  return diffHandle.cfgDiff;
1580 }
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 684 of file configuration.c.

1088 {
1089  return cfg->dirty;
1090 }

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

333 {
336 
338  if (GNUNET_OK !=
340  filename))
341  {
342  GNUNET_break (0);
344  return GNUNET_SYSERR;
345  }
346  ret = cb (cb_cls, cfg);
348  return ret;
349 }

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

217 {
218  cfg->diagnostics = true;
219 }

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

1401 {
1402  for (struct ConfigSection *spos = cfg->sections;
1403  NULL != spos;
1404  spos = spos->next)
1405  for (struct ConfigEntry *epos = spos->entries;
1406  NULL != epos;
1407  epos = epos->next)
1408  if (NULL != epos->val)
1409  iter (iter_cls,
1410  spos->name,
1411  epos->key,
1412  epos->val);
1413 }

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_SectionIterator  iter,
void *  iter_cls 
)

Iterate over all sections in the configuration.

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

Definition at line 1446 of file configuration.c.

1450 {
1451  struct ConfigSection *spos;
1452  struct ConfigSection *next;
1453 
1454  next = cfg->sections;
1455  while (next != NULL)
1456  {
1457  spos = next;
1458  next = spos->next;
1459  iter (iter_cls, spos->name);
1460  }
1461 }

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

1467 {
1468  struct ConfigSection *spos;
1469  struct ConfigSection *prev;
1470  struct ConfigEntry *ent;
1471 
1472  prev = NULL;
1473  spos = cfg->sections;
1474  while (NULL != spos)
1475  {
1476  if (0 == strcasecmp (section, spos->name))
1477  {
1478  if (NULL == prev)
1479  cfg->sections = spos->next;
1480  else
1481  prev->next = spos->next;
1482  while (NULL != (ent = spos->entries))
1483  {
1484  spos->entries = ent->next;
1485  GNUNET_free (ent->key);
1486  GNUNET_free (ent->val);
1487  GNUNET_free (ent->hint_filename);
1488  GNUNET_free (ent);
1489  cfg->dirty = GNUNET_YES;
1490  }
1491  GNUNET_free (spos->name);
1493  GNUNET_free (spos->hint_secret_stat);
1495  GNUNET_free (spos);
1496  return;
1497  }
1498  prev = spos;
1499  spos = spos->next;
1500  }
1501 }
char * hint_filename
Diagnostics information for the filename.
Definition: configuration.c:59
char * key
key for this entry
Definition: configuration.c:49
char * val
current, committed value
Definition: configuration.c:54
char * hint_inlined_from_filename
For secret sections: Where was this inlined from?
struct ConfigEntry * entries
entries in the section
Definition: configuration.c:81
char * hint_secret_filename
Diagnostics hint for the secret file.
Definition: configuration.c:99
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 collect_files_cb(), 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 1642 of file configuration.c.

1666 {
1667  struct ConfigEntry *e;
1668  char dummy[2];
1669 
1670  if (NULL == (e = find_entry (cfg, section, option)))
1671  return GNUNET_SYSERR;
1672  if (NULL == e->val)
1673  return GNUNET_SYSERR;
1674  if (1 != sscanf (e->val, "%llu%1s", number, dummy))
1675  return GNUNET_SYSERR;
1676  return GNUNET_OK;
1677 }
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(), 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(), 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 1642 of file configuration.c.

1686 {
1687  struct ConfigEntry *e;
1688  char dummy[2];
1689 
1690  if (NULL == (e = find_entry (cfg, section, option)))
1691  return GNUNET_SYSERR;
1692  if (NULL == e->val)
1693  return GNUNET_SYSERR;
1694  if (1 != sscanf (e->val, "%f%1s", number, dummy))
1695  return GNUNET_SYSERR;
1696  return GNUNET_OK;
1697 }

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

1706 {
1707  struct ConfigEntry *e;
1708  int ret;
1709 
1710  if (NULL == (e = find_entry (cfg, section, option)))
1711  return GNUNET_SYSERR;
1712  if (NULL == e->val)
1713  return GNUNET_SYSERR;
1715  if (GNUNET_OK != ret)
1717  section,
1718  option,
1719  _ ("Not a valid relative time specification"));
1720  return ret;
1721 }
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_time_to_relative(const char *fancy_time, struct GNUNET_TIME_Relative *rtime)
Convert a given fancy human-readable time to our internal representation.
Definition: strings.c:260

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_rest_openid_connect_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(), run_service(), 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 1642 of file configuration.c.

1730 {
1731  struct ConfigEntry *e;
1732 
1733  if (NULL == (e = find_entry (cfg, section, option)))
1734  return GNUNET_SYSERR;
1735  if (NULL == e->val)
1736  return GNUNET_SYSERR;
1737  return GNUNET_STRINGS_fancy_size_to_bytes (e->val, size);
1738 }
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_size_to_bytes(const char *fancy_size, unsigned long long *size)
Convert a given fancy human-readable size to bytes.
Definition: strings.c:236

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

1837 {
1838  struct ConfigEntry *e;
1839 
1840  if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1841  return GNUNET_NO;
1842  return GNUNET_YES;
1843 }

Referenced by check_config(), get_server_addresses(), GNUNET_CLIENT_connect(), GNUNET_CLIENT_test(), GNUNET_HOSTLIST_server_start(), GNUNET_SERVICE_run_(), GNUNET_SOCKS_check_service(), GNUNET_TESTBED_run(), GNUNET_TESTING_peer_configure(), 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 1642 of file configuration.c.

1757 {
1758  struct ConfigEntry *e;
1759 
1760  if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1761  {
1762  *value = NULL;
1763  return GNUNET_SYSERR;
1764  }
1765  *value = GNUNET_strdup (e->val);
1766  return GNUNET_OK;
1767 }

Referenced by advertise_dns_exit(), check_authorization(), check_config(), client_configure_plugin(), client_connect_cb(), 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_check_helper_binary(), GNUNET_PQ_connect_with_cfg2(), GNUNET_SERVICE_run_(), GNUNET_SOCKS_do_connect(), GNUNET_TESTBED_run(), GNUNET_TESTING_peer_configure(), GNUNET_TESTING_service_run(), GPI_plugins_load(), GST_plugins_load(), handle_ego_delete(), handle_ego_rename(), handle_init(), handle_register(), handle_uri(), identity_continuation(), 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(), mq_init(), print_quotas(), process_acl4(), process_acl6(), read_service_conf(), run(), server_configure_plugin(), server_get_addresses(), setup_exit_helper_args(), setup_service(), sock_read(), 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 2017 of file configuration.c.

2047 {
2048  char *tmp;
2049 
2050  if (GNUNET_OK !=
2051  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp))
2052  {
2053  LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to retrieve filename\n");
2054  *value = NULL;
2055  return GNUNET_SYSERR;
2056  }
2059  GNUNET_free (tmp);
2060  if (*value == NULL)
2061  return GNUNET_SYSERR;
2062  return GNUNET_OK;
2063 }
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_oidc_dir_path(), get_pid_file_name(), get_serialization_file_name(), get_serialization_file_name_in_dir(), get_server_addresses(), get_update_information_directory(), get_user_name(), GNUNET_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 2087 of file configuration.c.

2093 {
2094  char *list;
2095  char *pos;
2096  char *end;
2097  char old;
2098  int ret;
2099 
2100  if (GNUNET_OK !=
2101  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list))
2102  return 0;
2103  GNUNET_assert (list != NULL);
2104  ret = 0;
2105  pos = list;
2106  while (1)
2107  {
2108  while (pos[0] == ' ')
2109  pos++;
2110  if (strlen (pos) == 0)
2111  break;
2112  end = pos + 1;
2113  while ((end[0] != ' ') && (end[0] != '\0'))
2114  {
2115  if (end[0] == '\\')
2116  {
2117  switch (end[1])
2118  {
2119  case '\\':
2120  case ' ':
2121  memmove (end, &end[1], strlen (&end[1]) + 1);
2122 
2123  case '\0':
2124  /* illegal, but just keep it */
2125  break;
2126 
2127  default:
2128  /* illegal, but just ignore that there was a '/' */
2129  break;
2130  }
2131  }
2132  end++;
2133  }
2134  old = end[0];
2135  end[0] = '\0';
2136  if (strlen (pos) > 0)
2137  {
2138  ret++;
2139  if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos)))
2140  {
2141  ret = GNUNET_SYSERR;
2142  break;
2143  }
2144  }
2145  if (old == '\0')
2146  break;
2147  pos = end + 1;
2148  }
2149  GNUNET_free (list);
2150  return ret;
2151 }
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 1417 of file configuration.c.

1422 {
1423  struct ConfigSection *spos;
1424  struct ConfigEntry *epos;
1425 
1426  spos = cfg->sections;
1427  while ((spos != NULL) && (0 != strcasecmp (spos->name, section)))
1428  spos = spos->next;
1429  if (NULL == spos)
1430  return;
1431  if (spos->inaccessible)
1432  {
1434  "Section '%s' is marked as inaccessible, because the configuration "
1435  " file that contains the section can't be read.\n",
1436  section);
1437  return;
1438  }
1439  for (epos = spos->entries; NULL != epos; epos = epos->next)
1440  if (NULL != epos->val)
1441  iter (iter_cls, spos->name, epos->key, epos->val);
1442 }
bool inaccessible
Is the configuration section marked as inaccessible?
Definition: configuration.c:94

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

1777 {
1778  struct ConfigEntry *e;
1779  unsigned int i;
1780 
1781  if (NULL == (e = find_entry (cfg, section, option)))
1782  return GNUNET_SYSERR;
1783  for (i = 0; NULL != choices[i]; i++)
1784  if (0 == strcasecmp (choices[i], e->val))
1785  break;
1786  if (NULL == choices[i])
1787  {
1789  _ ("Configuration value '%s' for '%s'"
1790  " in section '%s' is not in set of legal choices\n"),
1791  e->val,
1792  option,
1793  section);
1794  return GNUNET_SYSERR;
1795  }
1796  *value = choices[i];
1797  return GNUNET_OK;
1798 }

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

2071 {
2072  static const char *yesno[] = { "YES", "NO", NULL };
2073  const char *val;
2074  int ret;
2075 
2076  ret =
2077  GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
2078  if (ret == GNUNET_SYSERR)
2079  return ret;
2080  if (val == yesno[0])
2081  return GNUNET_YES;
2082  return GNUNET_NO;
2083 }
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(), 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(), load_underlay(), 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 1642 of file configuration.c.

1807 {
1808  char *enc;
1809  int res;
1810  size_t data_size;
1811 
1812  if (GNUNET_OK !=
1813  (res =
1814  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &enc)))
1815  return res;
1816  data_size = (strlen (enc) * 5) / 8;
1817  if (data_size != buf_size)
1818  {
1819  GNUNET_free (enc);
1820  return GNUNET_SYSERR;
1821  }
1822  if (GNUNET_OK !=
1823  GNUNET_STRINGS_string_to_data (enc, strlen (enc), buf, buf_size))
1824  {
1825  GNUNET_free (enc);
1826  return GNUNET_SYSERR;
1827  }
1828  GNUNET_free (enc);
1829  return GNUNET_OK;
1830 }
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:788

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

2020 {
2021  char *dup;
2022  size_t i;
2023  size_t len;
2024 
2025  for (i = 0; '\0' != orig[i]; i++)
2026  {
2027  if ('$' != orig[i])
2028  continue;
2029  dup = GNUNET_strdup (orig + i);
2030  dup = expand_dollar (cfg, dup, 0);
2031  GNUNET_assert (NULL != dup); /* make compiler happy */
2032  len = strlen (dup) + 1;
2033  orig = GNUNET_realloc (orig, i + len);
2034  GNUNET_memcpy (orig + i, dup, len);
2035  GNUNET_free (dup);
2036  }
2037  return orig;
2038 }
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 1642 of file configuration.c.

1646 {
1647  char s[64];
1648 
1649  GNUNET_snprintf (s,
1650  64,
1651  "%llu",
1652  number);
1654  section,
1655  option,
1656  s);
1657 }
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 1600 of file configuration.c.

1604 {
1605  struct ConfigSection *sec;
1606  struct ConfigEntry *e;
1607  char *nv;
1608 
1609  e = find_entry (cfg, section, option);
1610  if (NULL != e)
1611  {
1612  if (NULL == value)
1613  {
1614  GNUNET_free (e->val);
1615  e->val = NULL;
1616  }
1617  else
1618  {
1619  nv = GNUNET_strdup (value);
1620  GNUNET_free (e->val);
1621  e->val = nv;
1622  }
1623  return;
1624  }
1625  sec = find_section (cfg, section);
1626  if (sec == NULL)
1627  {
1628  sec = GNUNET_new (struct ConfigSection);
1629  sec->name = GNUNET_strdup (section);
1630  sec->next = cfg->sections;
1631  cfg->sections = sec;
1632  }
1633  e = GNUNET_new (struct ConfigEntry);
1634  e->key = GNUNET_strdup (option);
1635  e->val = GNUNET_strdup (value);
1636  e->next = sec->entries;
1637  sec->entries = e;
1638 }
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_NAT_autoconfig_start(), GNUNET_TESTING_configuration_create_(), handle_ego_delete(), handle_ego_rename(), 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 2161 of file configuration.c.

2252 {
2253  char *list;
2254  char *pos;
2255  char *end;
2256  char *match;
2257  char old;
2258 
2259  if (GNUNET_OK !=
2261  section,
2262  option,
2263  &list))
2264  return GNUNET_NO;
2265  match = escape_name (value);
2266  pos = list;
2267  while (1)
2268  {
2269  while (pos[0] == ' ')
2270  pos++;
2271  if (strlen (pos) == 0)
2272  break;
2273  end = pos + 1;
2274  while ((end[0] != ' ') && (end[0] != '\0'))
2275  {
2276  if (end[0] == '\\')
2277  {
2278  switch (end[1])
2279  {
2280  case '\\':
2281  case ' ':
2282  end++;
2283  break;
2284 
2285  case '\0':
2286  /* illegal, but just keep it */
2287  break;
2288 
2289  default:
2290  /* illegal, but just ignore that there was a '/' */
2291  break;
2292  }
2293  }
2294  end++;
2295  }
2296  old = end[0];
2297  end[0] = '\0';
2298  if (0 == strcmp (pos, match))
2299  {
2300  if (old != '\0')
2301  memmove (pos,
2302  &end[1],
2303  strlen (&end[1]) + 1);
2304  else
2305  {
2306  if (pos != list)
2307  pos[-1] = '\0';
2308  else
2309  pos[0] = '\0';
2310  }
2312  section,
2313  option,
2314  list);
2315  GNUNET_free (list);
2316  GNUNET_free (match);
2317  return GNUNET_OK;
2318  }
2319  if (old == '\0')
2320  break;
2321  end[0] = old;
2322  pos = end + 1;
2323  }
2324  GNUNET_free (list);
2325  GNUNET_free (match);
2326  return GNUNET_NO;
2327 }
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 2161 of file configuration.c.

2214 {
2215  char *escaped;
2216  char *old;
2217  char *nw;
2218 
2219  if (GNUNET_SYSERR ==
2221  section,
2222  option,
2223  &test_match,
2224  (void *) value))
2225  return GNUNET_NO; /* already exists */
2226  if (GNUNET_OK !=
2227  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
2228  old = GNUNET_strdup ("");
2229  escaped = escape_name (value);
2230  nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2);
2231  strcpy (nw, old);
2232  if (strlen (old) > 0)
2233  strcat (nw, " ");
2234  strcat (nw, escaped);
2236  section,
2237  option,
2238  nw);
2239  GNUNET_free (old);
2240  GNUNET_free (nw);
2241  GNUNET_free (escaped);
2242  return GNUNET_OK;
2243 }
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 294 of file configuration_helper.c.

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

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

113 {
114  struct GNUNET_CONFIGURATION_ConfigSettings *cs = cls;
115  struct GNUNET_CONFIGURATION_Handle *out = NULL;
116  struct GNUNET_CONFIGURATION_Handle *ncfg = NULL;
117 
118  (void) args;
119  if (cs->diagnostics)
120  {
121  /* Re-parse the configuration with diagnostics enabled. */
122  ncfg = GNUNET_CONFIGURATION_create ();
125  cfgfile);
126  cfg = ncfg;
127  }
128 
129  if (cs->full)
130  cs->rewrite = GNUNET_YES;
131  if (cs->list_sections)
132  {
133  fprintf (stderr,
134  _ ("The following sections are available:\n"));
137  NULL);
138  return;
139  }
140  if ( (! cs->rewrite) &&
141  (NULL == cs->section) )
142  {
143  char *serialization;
144 
145  if (! cs->diagnostics)
146  {
147  fprintf (stderr,
148  _ ("%s, %s or %s argument is required\n"),
149  "--section",
150  "--list-sections",
151  "--diagnostics");
153  return;
154  }
156  fprintf (stdout,
157  "%s",
158  serialization);
159  GNUNET_free (serialization);
160  }
161  else if ( (NULL != cs->section) &&
162  (NULL == cs->value) )
163  {
164  if (NULL == cs->option)
165  {
167  cfg,
168  cs->section,
169  cs->is_filename
171  : &print_option,
172  (void *) cfg);
173  }
174  else
175  {
176  char *value;
177 
178  if (cs->is_filename)
179  {
180  if (GNUNET_OK !=
182  cs->section,
183  cs->option,
184  &value))
185  {
187  cs->section,
188  cs->option);
190  return;
191  }
192  }
193  else
194  {
195  if (GNUNET_OK !=
197  cs->section,
198  cs->option,
199  &value))
200  {
202  cs->section,
203  cs->option);
205  return;
206  }
207  }
208  fprintf (stdout,
209  "%s\n",
210  value);
211  GNUNET_free (value);
212  }
213  }
214  else if (NULL != cs->section)
215  {
216  if (NULL == cs->option)
217  {
218  fprintf (stderr,
219  _ ("--option argument required to set value\n"));
221  return;
222  }
225  cs->section,
226  cs->option,
227  cs->value);
228  cs->rewrite = GNUNET_YES;
229  }
230  if (cs->rewrite)
231  {
232  char *cfg_fn = NULL;
233 
234  if (NULL == out)
236 
237  if (NULL == cfgfile)
238  {
239  const char *xdg = getenv ("XDG_CONFIG_HOME");
240 
241  if (NULL != xdg)
242  GNUNET_asprintf (&cfg_fn,
243  "%s%s%s",
244  xdg,
247  else
248  cfg_fn = GNUNET_strdup (
249  GNUNET_OS_project_data_get ()->user_config_file);
250  cfgfile = cfg_fn;
251  }
252 
253  if (! cs->full)
254  {
255  struct GNUNET_CONFIGURATION_Handle *def;
256 
258  if (GNUNET_OK !=
260  NULL))
261  {
262  fprintf (stderr,
263  _ ("failed to load configuration defaults"));
264  cs->global_ret = 1;
267  GNUNET_free (cfg_fn);
268  return;
269  }
270  if (GNUNET_OK !=
272  out,
273  cfgfile))
274  cs->global_ret = 2;
276  }
277  else
278  {
279  if (GNUNET_OK !=
281  cfgfile))
282  cs->global_ret = 2;
283  }
284  GNUNET_free (cfg_fn);
285  }
286  if (NULL != out)
288  if (NULL != ncfg)
290 }
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
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_sections(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_SectionIterator iter, void *iter_cls)
Iterate over all sections in the configuration.
void GNUNET_CONFIGURATION_iterate_section_values(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over values of a section in the configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write_diffs(const struct GNUNET_CONFIGURATION_Handle *cfg_default, const struct GNUNET_CONFIGURATION_Handle *cfg_new, const char *filename)
Write only configuration entries that have been changed to configuration file.
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:253
#define EXIT_NOTCONFIGURED
Definition: platform.h:269
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: