GNUnet  0.11.x
Typedefs | Functions
Configuration library

Configuration management. More...

Typedefs

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

Functions

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

Detailed Description

Configuration management.

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

◆ GNUNET_CONFIGURATION_Section_Iterator

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

Function to iterate over section.

Parameters
clsclosure
sectionname of the section

Definition at line 295 of file gnunet_configuration_lib.h.

Function Documentation

◆ GNUNET_CONFIGURATION_create()

struct GNUNET_CONFIGURATION_Handle* GNUNET_CONFIGURATION_create ( void  )

Create a new configuration object.

Returns
fresh configuration object

Definition at line 226 of file configuration.c.

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_ATS_TEST_experimentation_load(), GNUNET_CONFIGURATION_default(), GNUNET_CONFIGURATION_dup(), GNUNET_CONFIGURATION_get_diff(), GNUNET_CONFIGURATION_parse_and_run(), GNUNET_CRYPTO_eddsa_setup_key(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), GNUNET_TESTBED_barrier_wait(), GNUNET_TESTBED_extract_cfg(), 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(), handle_inline(), iter_check_config(), iterate_save_rooms(), LEGACY_SERVICE_run(), load_member(), load_member_session(), load_member_session_next(), load_operation(), main(), netjail_exec_run(), run(), save_member(), save_member_session(), save_operation(), start_peer_run(), and tokenizer_cb().

227 {
229  char *p;
230 
232  /* make certain values from the project data available
233  as PATHS */
235  if (NULL != p)
236  {
238  "PATHS",
239  "DATADIR",
240  p);
241  GNUNET_free (p);
242  }
244  if (NULL != p)
245  {
247  "PATHS",
248  "LIBDIR",
249  p);
250  GNUNET_free (p);
251  }
253  if (NULL != p)
254  {
256  "PATHS",
257  "BINDIR",
258  p);
259  GNUNET_free (p);
260  }
262  if (NULL != p)
263  {
265  "PATHS",
266  "PREFIX",
267  p);
268  GNUNET_free (p);
269  }
271  if (NULL != p)
272  {
274  "PATHS",
275  "LOCALEDIR",
276  p);
277  GNUNET_free (p);
278  }
280  if (NULL != p)
281  {
283  "PATHS",
284  "ICONDIR",
285  p);
286  GNUNET_free (p);
287  }
289  if (NULL != p)
290  {
292  "PATHS",
293  "DOCDIR",
294  p);
295  GNUNET_free (p);
296  }
298  if (NULL != p)
299  {
301  "PATHS",
302  "LIBEXECDIR",
303  p);
304  GNUNET_free (p);
305  }
306  return cfg;
307 }
Return the directory where translations are installed (share/locale/)
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
Return the directory where libraries are installed.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Return the "PREFIX" directory given to configure.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
Return the prefix of the path with documentation files, including the license (share/doc/gnunet/).
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, the current running apps installation directory.
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.
Return the directory where helper binaries are installed (lib/gnunet/libexec/)
Return the directory where the program binaries are installed.
configuration data
Return the prefix of the path with application icons (share/icons/).
Return the directory where data is installed (share/gnunet/)
#define GNUNET_free(ptr)
Wrapper around free.
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 1509 of file configuration.c.

References 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_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().

1510 {
1512 
1513  ret = GNUNET_CONFIGURATION_create ();
1515  return ret;
1516 }
void GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over all options in the 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.
static void copy_entry(void *cls, const char *section, const char *option, const char *value)
Copy a configuration value to the given target configuration.
configuration data
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_destroy()

void GNUNET_CONFIGURATION_destroy ( struct GNUNET_CONFIGURATION_Handle cfg)

Destroy configuration object.

Parameters
cfgconfiguration to destroy

Definition at line 311 of file configuration.c.

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

Referenced by associate_shared_service(), auto_config_cb(), callback_scan_for_rooms(), clean_node(), cleanup(), cleanup_prc(), conclude_autoconfig_request(), controller_status_cb(), create_unique_cfgs(), destroy_pooled_connection(), do_shutdown(), GNUNET_ATS_solvers_experimentation_load(), GNUNET_ATS_solvers_experimentation_stop(), GNUNET_ATS_TEST_experimentation_load(), GNUNET_CONFIGURATION_default(), GNUNET_CONFIGURATION_parse_and_run(), GNUNET_CONFIGURATION_write_diffs(), GNUNET_CRYPTO_eddsa_setup_key(), GNUNET_NAT_autoconfig_cancel(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), GNUNET_TESTBED_barrier_wait(), GNUNET_TESTBED_barrier_wait_cancel(), GNUNET_TESTBED_controller_disconnect(), GNUNET_TESTBED_extract_cfg(), GNUNET_TESTBED_host_destroy(), GNUNET_TESTBED_host_replace_cfg_(), GNUNET_TESTBED_run(), GNUNET_TESTBED_shutdown_controller(), GNUNET_TESTBED_shutdown_peer(), 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_inline(), handle_link_controllers_result(), 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(), run(), save_member(), save_member_session(), save_operation(), shutdown_task(), start_peer_cleanup(), start_peer_run(), tokenizer_cb(), and update_peer_config().

312 {
313  struct ConfigSection *sec;
314  struct ConfigFile *cf;
315 
316  while (NULL != (sec = cfg->sections))
318  while (NULL != (cf = cfg->loaded_files_head))
319  {
323  cfg->loaded_files_tail,
324  cf);
325  }
326  GNUNET_free (cfg);
327 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
char * name
name of the section
Definition: configuration.c:89
void GNUNET_CONFIGURATION_remove_section(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Remove the given section and all options in it.
struct ConfigSection * sections
Configuration sections.
struct ConfigFile * loaded_files_head
Linked list of loaded files.
char * source_filename
Source filename.
char * hint_restrict_section
Was this configuration file parsed via -secret@?
configuration section
Definition: configuration.c:74
struct ConfigFile * loaded_files_tail
Linked list of loaded files.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ GNUNET_CONFIGURATION_load()

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

Load configuration.

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

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

Load configuration.

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

Definition at line 2456 of file configuration.c.

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

Referenced by auto_config_cb(), create_unique_cfgs(), gg_load_configuration(), GNUNET_ATS_solvers_experimentation_load(), GNUNET_ATS_TEST_experimentation_load(), GNUNET_CONFIGURATION_default(), GNUNET_CONFIGURATION_parse_and_run(), GNUNET_CRYPTO_eddsa_setup_key(), GNUNET_PROGRAM_run2(), 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(), run(), and start_peer_run().

2458 {
2459  char *baseconfig;
2460  const char *base_config_varname;
2461 
2462  if (cfg->load_called)
2463  {
2464  /* FIXME: Make this a GNUNET_assert later */
2465  GNUNET_break (0);
2466  GNUNET_free (cfg->main_filename);
2467  }
2468  cfg->load_called = true;
2469  if (NULL != filename)
2471 
2472  base_config_varname = GNUNET_OS_project_data_get ()->base_config_varname;
2473 
2474  if ((NULL != base_config_varname)
2475  && (NULL != (baseconfig = getenv (base_config_varname))))
2476  {
2477  baseconfig = GNUNET_strdup (baseconfig);
2478  }
2479  else
2480  {
2481  char *ipath;
2482 
2484  if (NULL == ipath)
2485  {
2486  GNUNET_break (0);
2487  return GNUNET_SYSERR;
2488  }
2489  GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d");
2490  GNUNET_free (ipath);
2491  }
2492 
2493  char *dname = GNUNET_STRINGS_filename_expand (baseconfig);
2494  GNUNET_free (baseconfig);
2495 
2496  if ((GNUNET_YES == GNUNET_DISK_directory_test (dname, GNUNET_YES)) &&
2498  {
2500  "Failed to load base configuration from '%s'\n",
2501  filename);
2502  GNUNET_free (dname);
2503  return GNUNET_SYSERR; /* no configuration at all found */
2504  }
2505  GNUNET_free (dname);
2506  if ((NULL != filename) &&
2508  {
2509  /* specified configuration not found */
2511  "Failed to load configuration from file '%s'\n",
2512  filename);
2513  return GNUNET_SYSERR;
2514  }
2515  if (((GNUNET_YES !=
2516  GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) &&
2517  (filename != NULL))
2518  GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG",
2519  filename);
2520  return GNUNET_OK;
2521 }
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...
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
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, the current running apps installation directory.
static char * filename
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 LOG(kind,...)
Definition: configuration.c:34
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
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.
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:482
char * getenv()
char * main_filename
Name of the entry point configuration file.
const char * base_config_varname
Name of an environment variable that can be used to override the location from which default configur...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load_from(struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d)
Load default configuration.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
bool load_called
Was the configuration ever loaded via GNUNET_CONFIGURATION_load?
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:404
Return the directory where data is installed (share/gnunet/)
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_load_from()

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

Load default configuration.

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

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

Definition at line 2283 of file configuration.c.

References cleanup(), collect_files_cb(), filename, CollectFilesContext::files, CollectFilesContext::files_length, GNUNET_array_grow, GNUNET_CONFIGURATION_parse(), GNUNET_DISK_directory_scan(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, and pstrcmp().

Referenced by GNUNET_CONFIGURATION_load().

2285 {
2286  struct CollectFilesContext files_context = {
2287  .files = NULL,
2288  .files_length = 0,
2289  };
2290  enum GNUNET_GenericReturnValue fun_ret;
2291 
2292  if (GNUNET_SYSERR ==
2294  &files_context))
2295  return GNUNET_SYSERR; /* no configuration at all found */
2296  qsort (files_context.files,
2297  files_context.files_length,
2298  sizeof (char *),
2299  pstrcmp);
2300  for (unsigned int i = 0; i < files_context.files_length; i++)
2301  {
2302  char *ext;
2303  const char *filename = files_context.files[i];
2304 
2305  /* Examine file extension */
2306  ext = strrchr (filename, '.');
2307  if ((NULL == ext) || (0 != strcmp (ext, ".conf")))
2308  {
2309  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Skipping file `%s'\n", filename);
2310  fun_ret = GNUNET_OK;
2311  goto cleanup;
2312  }
2313  fun_ret = GNUNET_CONFIGURATION_parse (cfg, filename);
2314  if (fun_ret != GNUNET_OK)
2315  break;
2316  }
2317  cleanup:
2318  if (files_context.files_length > 0)
2319  {
2320  for (size_t i = 0; i < files_context.files_length; i++)
2321  GNUNET_free (files_context.files[i]);
2322  GNUNET_array_grow (files_context.files,
2323  files_context.files_length,
2324  0);
2325  }
2326  return fun_ret;
2327 }
static int collect_files_cb(void *cls, const char *filename)
Function called with a 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...
unsigned int files_length
Size of the files array.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:83
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:814
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
static char * filename
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
char ** files
Collected files from globbing.
#define GNUNET_log(kind,...)
static int pstrcmp(const void *a, const void *b)
Closure to collect_files_cb.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_default()

struct GNUNET_CONFIGURATION_Handle* GNUNET_CONFIGURATION_default ( void  )

Return GNUnet's default configuration.

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

Returns
a freshly allocated configuration

Definition at line 2384 of file configuration.c.

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.

2385 {
2386  const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
2388  const char *xdg = getenv ("XDG_CONFIG_HOME");
2389  char *cfgname = NULL;
2391 
2392  /* FIXME: Why are we doing this? Needs some commentary! */
2393  GNUNET_OS_init (dpd);
2394 
2395  cfg = GNUNET_CONFIGURATION_create ();
2396 
2397  /* First, try user configuration. */
2398  if (NULL != xdg)
2399  GNUNET_asprintf (&cfgname, "%s/%s", xdg, pd->config_file);
2400  else
2401  cfgname = GNUNET_strdup (pd->user_config_file);
2402 
2403  /* If user config doesn't exist, try in
2404  /etc/<projdir>/<cfgfile> and /etc/<cfgfile> */
2405  if (GNUNET_OK != GNUNET_DISK_file_test (cfgname))
2406  {
2407  GNUNET_free (cfgname);
2408  GNUNET_asprintf (&cfgname, "/etc/%s", pd->config_file);
2409  }
2410  if (GNUNET_OK != GNUNET_DISK_file_test (cfgname))
2411  {
2412  GNUNET_free (cfgname);
2413  GNUNET_asprintf (&cfgname,
2414  "/etc/%s/%s",
2415  pd->project_dirname,
2416  pd->config_file);
2417  }
2418  if (GNUNET_OK != GNUNET_DISK_file_test (cfgname))
2419  {
2421  "Unable to top-level configuration file.\n");
2422  GNUNET_OS_init (pd);
2424  GNUNET_free (cfgname);
2425  return NULL;
2426  }
2427 
2428  /* We found a configuration file that looks good, try to load it. */
2429 
2431  "Loading top-level configuration from '%s'\n",
2432  cfgname);
2433  if (GNUNET_OK !=
2434  GNUNET_CONFIGURATION_load (cfg, cfgname))
2435  {
2436  GNUNET_OS_init (pd);
2438  GNUNET_free (cfgname);
2439  return NULL;
2440  }
2441  GNUNET_free (cfgname);
2442  GNUNET_OS_init (pd);
2443  return cfg;
2444 }
const char * config_file
Configuration file name (in $XDG_CONFIG_HOME) to use.
Project-specific data used to help the OS subsystem find installation paths.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
int GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration (starts with defaults, then loads system-specific configuration).
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 struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_default(void)
Return default project data used by &#39;libgnunetutil&#39; for GNUnet.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create()
Create a new configuration object.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
#define LOG(kind,...)
Definition: configuration.c:34
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
char * getenv()
configuration data
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
void GNUNET_OS_init(const struct GNUNET_OS_ProjectData *pd)
Setup OS subsystem with project data.
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
#define GNUNET_free(ptr)
Wrapper around free.
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 2331 of file configuration.c.

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.

Referenced by GNUNET_PROGRAM_run2().

2332 {
2333  char *cfg_fn;
2334  const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
2335  const char *xdg = getenv ("XDG_CONFIG_HOME");
2336 
2337  if (NULL != xdg)
2338  GNUNET_asprintf (&cfg_fn,
2339  "%s%s%s",
2340  xdg,
2342  pd->config_file);
2343  else
2344  cfg_fn = GNUNET_strdup (pd->user_config_file);
2345 
2346  if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2347  return cfg_fn;
2348 
2349  GNUNET_free (cfg_fn);
2350 
2351  /* Fall back to /etc/ for the default configuration.
2352  Should be okay to use forward slashes here. */
2353 
2354  GNUNET_asprintf (&cfg_fn,
2355  "/etc/%s",
2356  pd->config_file);
2357 
2358  if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2359  return cfg_fn;
2360 
2361  GNUNET_free (cfg_fn);
2362 
2363  GNUNET_asprintf (&cfg_fn,
2364  "/etc/%s",
2365  pd->config_file);
2366 
2367  if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2368  return cfg_fn;
2369 
2370  GNUNET_asprintf (&cfg_fn,
2371  "/etc/%s/%s",
2372  pd->project_dirname,
2373  pd->config_file);
2374 
2375  if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2376  return cfg_fn;
2377 
2378  GNUNET_free (cfg_fn);
2379  return NULL;
2380 }
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
const char * config_file
Configuration file name (in $XDG_CONFIG_HOME) to use.
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).
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define DIR_SEPARATOR_STR
Definition: platform.h:165
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
char * getenv()
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_parse()

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

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

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

Definition at line 959 of file configuration.c.

References _, GNUNET_CONFIGURATION_Handle::current_nest_level, GNUNET_CONFIGURATION_Handle::dirty, fn, fs, GNUNET_break, GNUNET_CONFIGURATION_deserialize(), GNUNET_CONTAINER_DLL_insert_tail, GNUNET_DISK_file_size(), GNUNET_DISK_fn_read(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_new, GNUNET_strdup, GNUNET_STRINGS_filename_expand(), GNUNET_SYSERR, GNUNET_YES, ConfigFile::level, GNUNET_CONFIGURATION_Handle::loaded_files_head, GNUNET_CONFIGURATION_Handle::loaded_files_tail, LOG, ConfigFile::prev, ret, SIZE_MAX, and ConfigFile::source_filename.

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

961 {
962  uint64_t fs64;
963  size_t fs;
964  char *fn;
965  char *mem;
966  int dirty;
968  ssize_t sret;
969 
971  LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to parse config file `%s'\n", fn);
972  if (NULL == fn)
973  return GNUNET_SYSERR;
974 
975 
976  /* Check for cycles */
977  {
978  unsigned int lvl = cfg->current_nest_level;
979  struct ConfigFile *cf = cfg->loaded_files_tail;
980  struct ConfigFile *parent = NULL;
981 
982 
983  for (; NULL != cf; parent = cf, cf = cf->prev)
984  {
985  /* Check parents based on level, skipping children of siblings. */
986  if (cf->level >= lvl)
987  continue;
988  lvl = cf->level;
989  if ( (NULL == cf->source_filename) || (NULL == filename))
990  continue;
991  if (0 == strcmp (cf->source_filename, filename))
992  {
993  if (NULL == parent)
994  {
996  "Forbidden direct cyclic configuration import (%s -> %s)\n",
997  cf->source_filename,
998  filename);
999  }
1000  else
1002  "Forbidden indirect cyclic configuration import (%s -> ... -> %s -> %s)\n",
1003  cf->source_filename,
1004  parent->source_filename,
1005  filename);
1006  return GNUNET_SYSERR;
1007  }
1008  }
1009 
1010  }
1011 
1012  /* Keep track of loaded files.*/
1013  {
1014  struct ConfigFile *cf = GNUNET_new (struct ConfigFile);
1015 
1016  cf->level = cfg->current_nest_level;
1017  cf->source_filename = GNUNET_strdup (filename ? filename : "<input>");
1019  cfg->loaded_files_tail,
1020  cf);
1021  }
1022 
1023  dirty = cfg->dirty; /* back up value! */
1024  if (GNUNET_SYSERR ==
1026  {
1028  "Error while determining the file size of `%s'\n",
1029  fn);
1030  GNUNET_free (fn);
1031  return GNUNET_SYSERR;
1032  }
1033  if (fs64 > SIZE_MAX)
1034  {
1035  GNUNET_break (0); /* File size is more than the heap size */
1036  GNUNET_free (fn);
1037  return GNUNET_SYSERR;
1038  }
1039  fs = fs64;
1040  mem = GNUNET_malloc (fs);
1041  sret = GNUNET_DISK_fn_read (fn, mem, fs);
1042  if ((sret < 0) || (fs != (size_t) sret))
1043  {
1044  LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Error while reading file `%s'\n"), fn);
1045  GNUNET_free (fn);
1046  GNUNET_free (mem);
1047  return GNUNET_SYSERR;
1048  }
1049  LOG (GNUNET_ERROR_TYPE_DEBUG, "Deserializing contents of file `%s'\n", fn);
1051  mem,
1052  fs,
1053  fn);
1054  if (GNUNET_SYSERR == ret)
1055  {
1057  _ ("Failed to parse configuration file `%s'\n"),
1058  fn);
1059  }
1060  GNUNET_free (fn);
1061  GNUNET_free (mem);
1062  /* restore dirty flag - anything we set in the meantime
1063  * came from disk */
1064  cfg->dirty = dirty;
1065  return ret;
1066 }
enum GNUNET_GenericReturnValue dirty
Modification indication since last save GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on err...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *source_filename)
De-serializes configuration.
unsigned int level
Level in the tree of loaded config files.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:83
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define SIZE_MAX
Definition: platform.h:213
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
unsigned int current_nest_level
Current nesting level of file loading.
static char * fn
Filename of the unique file.
static char * filename
struct ConfigFile * loaded_files_head
Linked list of loaded files.
#define LOG(kind,...)
Definition: configuration.c:34
char * source_filename
Source filename.
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:482
struct ConfigFile * prev
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:36
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition: disk.c:222
#define GNUNET_log(kind,...)
struct ConfigFile * loaded_files_tail
Linked list of loaded files.
#define GNUNET_malloc(size)
Wrapper around malloc.
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_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_serialize()

char* GNUNET_CONFIGURATION_serialize ( const struct GNUNET_CONFIGURATION_Handle cfg,
size_t *  size 
)

Serializes the given configuration.

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

Definition at line 1112 of file configuration.c.

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

Referenced by conclude_autoconfig_request(), GNUNET_CONFIGURATION_write(), 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().

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

References 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, GNUNET_CONFIGURATION_Handle::sections, and ConfigEntry::val.

Referenced by run().

1212 {
1213  struct GNUNET_Buffer buf = { 0 };
1214 
1216  "#\n# Configuration file diagnostics\n#\n");
1218  "# Entry point: %s\n",
1219  cfg->main_filename ? cfg->main_filename :
1220  "<none>");
1222  "#\n# Files Loaded:\n");
1223 
1224  for (struct ConfigFile *cfil = cfg->loaded_files_head;
1225  NULL != cfil;
1226  cfil = cfil->next)
1227  {
1229  "# ");
1230  for (unsigned int i = 0; i < cfil->level; i++)
1232  "+");
1233  if (0 != cfil->level)
1235  " ");
1236 
1238  "%s",
1239  cfil->source_filename);
1240 
1241  if (NULL != cfil->hint_restrict_section)
1243  " (%s secret section %s)",
1244  cfil->hint_inaccessible
1245  ? "inaccessible"
1246  : "loaded",
1247  cfil->hint_restrict_section);
1248 
1250  "\n");
1251  }
1252 
1254  "#\n\n");
1255 
1256  for (struct ConfigSection *sec = cfg->sections;
1257  NULL != sec;
1258  sec = sec->next)
1259  {
1260  if (sec->hint_secret_filename)
1262  "# secret section from %s\n# secret file stat %s\n",
1263  sec->hint_secret_filename,
1264  sec->hint_secret_stat);
1265  if (sec->hint_inlined_from_filename)
1266  {
1268  "# inlined from %s:%u\n",
1269  sec->hint_inlined_from_filename,
1270  sec->hint_inlined_from_line);
1271  }
1273  "[%s]\n\n",
1274  sec->name);
1275  if (sec->inaccessible)
1276  {
1278  "# <section contents inaccessible>\n\n\n");
1279  continue;
1280  }
1281  for (struct ConfigEntry *ent = sec->entries;
1282  NULL != ent;
1283  ent = ent->next)
1284  {
1285  if (do_skip (sec->name,
1286  ent->key))
1287  continue;
1288  if (NULL != ent->val)
1289  {
1290  char *pos;
1291  char *val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1292  strcpy (val, ent->val);
1293  while (NULL != (pos = strstr (val, "\n")))
1294  {
1295  memmove (&pos[2], &pos[1], strlen (&pos[1]));
1296  pos[0] = '\\';
1297  pos[1] = 'n';
1298  }
1299  if (NULL != ent->hint_filename)
1300  {
1302  "# %s:%u\n",
1303  ent->hint_filename,
1304  ent->hint_lineno);
1305  }
1307  "%s = %s\n",
1308  ent->key,
1309  val);
1310  GNUNET_free (val);
1311  }
1312  GNUNET_buffer_write_str (&buf, "\n");
1313  }
1314  GNUNET_buffer_write_str (&buf, "\n");
1315  }
1316  return GNUNET_buffer_reap_str (&buf);
1317 }
struct ConfigFile * next
static bool do_skip(const char *sec, const char *key)
Should we skip this configuration entry when serializing?
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.
configuration entry
Definition: configuration.c:42
static char buf[2048]
struct ConfigSection * sections
Configuration sections.
struct ConfigFile * loaded_files_head
Linked list of loaded files.
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:47
configuration section
Definition: configuration.c:74
char * main_filename
Name of the entry point configuration file.
Common buffer management functions.
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 ConfigSection * next
This is a linked list.
Definition: configuration.c:79
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
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 @ statements
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 700 of file configuration.c.

References _, GNUNET_CONFIGURATION_Handle::diagnostics, end, GNUNET_assert, GNUNET_CONFIGURATION_set_value_string(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_NO, GNUNET_OK, GNUNET_strdup, GNUNET_strndup, GNUNET_SYSERR, GNUNET_YES, handle_inline(), line, LOG, GNUNET_CONFIGURATION_Handle::restrict_section, ret, section, set_entry_hint(), and value.

Referenced by GNUNET_CONFIGURATION_parse(), GNUNET_TESTBED_extract_cfg(), GNUNET_TESTBED_extract_config_(), handle_auto_result(), handle_autoconfig_request(), and tokenizer_cb().

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

References GNUNET_CONFIGURATION_Handle::dirty, fn, GNUNET_assert, GNUNET_CONFIGURATION_serialize(), GNUNET_DISK_directory_create_for_file(), GNUNET_DISK_directory_remove(), GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_write(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_TRUNCATE, GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_GROUP_READ, GNUNET_DISK_PERM_GROUP_WRITE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log_strerror_file, GNUNET_NO, GNUNET_OK, GNUNET_STRINGS_filename_expand(), GNUNET_SYSERR, h, and size.

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

1323 {
1324  char *fn;
1325  char *cfg_buf;
1326  size_t size;
1327 
1329  if (fn == NULL)
1330  return GNUNET_SYSERR;
1332  {
1333  GNUNET_free (fn);
1334  return GNUNET_SYSERR;
1335  }
1336  cfg_buf = GNUNET_CONFIGURATION_serialize (cfg,
1337  &size);
1338  {
1339  struct GNUNET_DISK_FileHandle *h;
1340 
1341  h = GNUNET_DISK_file_open (fn,
1349  if (NULL == h)
1350  {
1351  GNUNET_free (fn);
1352  GNUNET_free (cfg_buf);
1353  return GNUNET_SYSERR;
1354  }
1355  if (((ssize_t) size) !=
1357  cfg_buf,
1358  size))
1359  {
1361  "write",
1362  fn);
1364  (void) GNUNET_DISK_directory_remove (fn);
1365  GNUNET_free (fn);
1366  GNUNET_free (cfg_buf);
1367  cfg->dirty = GNUNET_SYSERR; /* last write failed */
1368  return GNUNET_SYSERR;
1369  }
1372  }
1373  GNUNET_free (fn);
1374  GNUNET_free (cfg_buf);
1375  cfg->dirty = GNUNET_NO; /* last write succeeded */
1376  return GNUNET_OK;
1377 }
enum GNUNET_GenericReturnValue dirty
Modification indication since last save GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on err...
Create file if it doesn&#39;t exist.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1305
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
static char * fn
Filename of the unique file.
Truncate file if it exists.
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
static char * filename
static unsigned int size
Size of the "table".
Definition: peer.c:67
Open the file for writing.
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:482
char * GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
Serializes the given configuration.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1084
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:582
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:1234
Handle used to access files (and pipes).
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_write_diffs()

enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write_diffs ( const struct GNUNET_CONFIGURATION_Handle cfg_default,
const struct GNUNET_CONFIGURATION_Handle cfg_new,
const char *  filename 
)

Write only configuration entries that have been changed to configuration file.

Parameters
cfg_defaultdefault configuration
cfg_newnew configuration
filenamewhere to write the configuration diff between default and new
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 1561 of file configuration.c.

References GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_get_diff(), GNUNET_CONFIGURATION_write(), and ret.

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

1565 {
1566  int ret;
1567  struct GNUNET_CONFIGURATION_Handle *diff;
1568 
1569  diff = GNUNET_CONFIGURATION_get_diff (cfg_default, cfg_new);
1570  ret = GNUNET_CONFIGURATION_write (diff, filename);
1572  return ret;
1573 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_get_diff(const struct GNUNET_CONFIGURATION_Handle *cfg_default, const struct GNUNET_CONFIGURATION_Handle *cfg_new)
Compute configuration with only entries that have been changed.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
static char * filename
configuration data
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_diff()

struct GNUNET_CONFIGURATION_Handle* GNUNET_CONFIGURATION_get_diff ( const struct GNUNET_CONFIGURATION_Handle cfg_default,
const struct GNUNET_CONFIGURATION_Handle cfg_new 
)

Compute configuration with only entries that have been changed.

Parameters
cfg_defaultoriginal configuration
cfg_newnew configuration
Returns
configuration with only the differences, never NULL

Definition at line 1547 of file configuration.c.

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

Referenced by conclude_autoconfig_request(), GNUNET_CONFIGURATION_write_diffs(), and next_phase().

1550 {
1551  struct DiffHandle diffHandle;
1552 
1553  diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
1554  diffHandle.cfg_default = cfg_default;
1555  GNUNET_CONFIGURATION_iterate (cfg_new, &compare_entries, &diffHandle);
1556  return diffHandle.cfgDiff;
1557 }
void GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over all options in the configuration.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create()
Create a new configuration object.
struct GNUNET_CONFIGURATION_Handle * cfgDiff
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
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 1070 of file configuration.c.

References GNUNET_CONFIGURATION_Handle::dirty.

Referenced by auto_config_cb().

1071 {
1072  return cfg->dirty;
1073 }
enum GNUNET_GenericReturnValue dirty
Modification indication since last save GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on err...
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 331 of file configuration.c.

References cfg, GNUNET_break, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_load(), GNUNET_OK, GNUNET_SYSERR, and ret.

Referenced by GNUNET_DISK_purge_cfg_dir().

334 {
337 
340  {
341  GNUNET_break (0);
343  return GNUNET_SYSERR;
344  }
345  ret = cb (cb_cls, cfg);
347  return ret;
348 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
int GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration (starts with defaults, then loads system-specific configuration).
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:83
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create()
Create a new configuration object.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
static char * filename
configuration data
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_enable_diagnostics()

void GNUNET_CONFIGURATION_enable_diagnostics ( struct GNUNET_CONFIGURATION_Handle cfg)

Enable extra diagnostics.

Will produce more log output and allocate more memory.

Parameters
cfgconfiguration handle

Definition at line 218 of file configuration.c.

References GNUNET_CONFIGURATION_Handle::diagnostics.

Referenced by run().

220 {
221  cfg->diagnostics = true;
222 }
bool diagnostics
Enable diagnostics.
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 1381 of file configuration.c.

References 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_().

1384 {
1385  for (struct ConfigSection *spos = cfg->sections;
1386  NULL != spos;
1387  spos = spos->next)
1388  for (struct ConfigEntry *epos = spos->entries;
1389  NULL != epos;
1390  epos = epos->next)
1391  if (NULL != epos->val)
1392  iter (iter_cls,
1393  spos->name,
1394  epos->key,
1395  epos->val);
1396 }
configuration entry
Definition: configuration.c:42
struct ConfigSection * sections
Configuration sections.
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:47
configuration section
Definition: configuration.c:74
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:79
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_iterate_sections()

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

Iterate over all sections in the configuration.

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

Definition at line 1429 of file configuration.c.

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

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

1433 {
1434  struct ConfigSection *spos;
1435  struct ConfigSection *next;
1436 
1437  next = cfg->sections;
1438  while (next != NULL)
1439  {
1440  spos = next;
1441  next = spos->next;
1442  iter (iter_cls, spos->name);
1443  }
1444 }
char * name
name of the section
Definition: configuration.c:89
struct ConfigSection * sections
Configuration sections.
configuration section
Definition: configuration.c:74
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:79
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 1448 of file configuration.c.

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

Referenced by GNUNET_CONFIGURATION_destroy(), and GNUNET_TESTING_peer_configure().

1450 {
1451  struct ConfigSection *spos;
1452  struct ConfigSection *prev;
1453  struct ConfigEntry *ent;
1454 
1455  prev = NULL;
1456  spos = cfg->sections;
1457  while (NULL != spos)
1458  {
1459  if (0 == strcasecmp (section, spos->name))
1460  {
1461  if (NULL == prev)
1462  cfg->sections = spos->next;
1463  else
1464  prev->next = spos->next;
1465  while (NULL != (ent = spos->entries))
1466  {
1467  spos->entries = ent->next;
1468  GNUNET_free (ent->key);
1469  GNUNET_free (ent->val);
1470  GNUNET_free (ent->hint_filename);
1471  GNUNET_free (ent);
1472  cfg->dirty = GNUNET_YES;
1473  }
1474  GNUNET_free (spos->name);
1476  GNUNET_free (spos->hint_secret_stat);
1478  GNUNET_free (spos);
1479  return;
1480  }
1481  prev = spos;
1482  spos = spos->next;
1483  }
1484 }
enum GNUNET_GenericReturnValue dirty
Modification indication since last save GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on err...
struct ConfigEntry * entries
entries in the section
Definition: configuration.c:84
configuration entry
Definition: configuration.c:42
char * hint_filename
Diagnostics information for the filename.
Definition: configuration.c:62
static char * section
Name of the section.
Definition: gnunet-config.c:33
char * name
name of the section
Definition: configuration.c:89
struct ConfigSection * sections
Configuration sections.
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:47
configuration section
Definition: configuration.c:74
char * hint_secret_stat
Extra information regarding permissions of the secret file.
char * key
key for this entry
Definition: configuration.c:52
char * hint_secret_filename
Diagnostics hint for the secret file.
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:79
char * val
current, committed value
Definition: configuration.c:57
#define GNUNET_free(ptr)
Wrapper around free.
char * hint_inlined_from_filename
For secret sections: Where was this inlined from?
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 1632 of file configuration.c.

References dummy, e, find_entry(), GNUNET_OK, GNUNET_SYSERR, and ConfigEntry::val.

Referenced by client_configure_plugin(), event_cb(), GCD_init(), GCO_init(), GDS_NEIGHBOURS_init(), GDS_NSE_init(), get_server_addresses(), GNUNET_ATS_solvers_experimentation_load(), GNUNET_ATS_solvers_load_quotas(), GNUNET_ATS_TEST_experimentation_load(), GNUNET_CLIENT_connect(), GNUNET_CLIENT_test(), GNUNET_HOSTLIST_server_start(), GNUNET_NAT_AUTO_test_start(), GNUNET_PROGRAM_run2(), GNUNET_REVOCATION_revoke(), GNUNET_SERVICE_run_(), GNUNET_SOCKS_do_connect(), GNUNET_TESTBED_controller_connect(), GNUNET_TESTBED_run(), GNUNET_TRANSPORT_communicator_connect(), GSF_cadet_start_server(), GSF_pending_request_init_(), GST_plugins_load(), iopen(), LEGACY_SERVICE_get_server_addresses(), LEGACY_SERVICE_run(), libgnunet_plugin_block_revocation_init(), libgnunet_plugin_datastore_heap_init(), libgnunet_plugin_dhtu_ip_init(), LIBGNUNET_PLUGIN_TRANSPORT_INIT(), libgnunet_plugin_transport_tcp_init(), libgnunet_plugin_transport_udp_init(), load_episode(), 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().

1637 {
1638  struct ConfigEntry *e;
1639  char dummy[2];
1640 
1641  if (NULL == (e = find_entry (cfg, section, option)))
1642  return GNUNET_SYSERR;
1643  if (NULL == e->val)
1644  return GNUNET_SYSERR;
1645  if (1 != sscanf (e->val, "%llu%1s", number, dummy))
1646  return GNUNET_SYSERR;
1647  return GNUNET_OK;
1648 }
static struct Experiment * e
configuration entry
Definition: configuration.c:42
static struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
uint32_t number
static char * section
Name of the section.
Definition: gnunet-config.c:33
static char * option
Name of the option.
Definition: gnunet-config.c:38
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
char * val
current, committed value
Definition: configuration.c:57
Here is the call graph for this function:

◆ GNUNET_CONFIGURATION_get_value_float()

enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_float ( const struct GNUNET_CONFIGURATION_Handle cfg,
const char *  section,
const char *  option,
float *  number 
)

Get a configuration value that should be a floating point number.

Parameters
cfgconfiguration to inspect
sectionsection of interest
optionoption of interest
numberwhere to store the floating value of the option
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 1652 of file configuration.c.

References dummy, e, find_entry(), GNUNET_OK, GNUNET_SYSERR, and ConfigEntry::val.

Referenced by GNUNET_RPS_connect(), and libgnunet_plugin_ats_proportional_init().

1657 {
1658  struct ConfigEntry *e;
1659  char dummy[2];
1660 
1661  if (NULL == (e = find_entry (cfg, section, option)))
1662  return GNUNET_SYSERR;
1663  if (NULL == e->val)
1664  return GNUNET_SYSERR;
1665  if (1 != sscanf (e->val, "%f%1s", number, dummy))
1666  return GNUNET_SYSERR;
1667  return GNUNET_OK;
1668 }
static struct Experiment * e
configuration entry
Definition: configuration.c:42
static struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
uint32_t number
static char * section
Name of the section.
Definition: gnunet-config.c:33
static char * option
Name of the option.
Definition: gnunet-config.c:38
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
char * val
current, committed value
Definition: configuration.c:57
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_value_time()

enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time ( const struct GNUNET_CONFIGURATION_Handle cfg,
const char *  section,
const char *  option,
struct GNUNET_TIME_Relative time 
)

Get a configuration value that should be a relative time.

Parameters
cfgconfiguration to inspect
sectionsection of interest
optionoption of interest
timeset to the time value stored in the configuration
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 1672 of file configuration.c.

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

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

1677 {
1678  struct ConfigEntry *e;
1679  int ret;
1680 
1681  if (NULL == (e = find_entry (cfg, section, option)))
1682  return GNUNET_SYSERR;
1683  if (NULL == e->val)
1684  return GNUNET_SYSERR;
1685  ret = GNUNET_STRINGS_fancy_time_to_relative (e->val, time);
1686  if (GNUNET_OK != ret)
1688  section,
1689  option,
1690  _ ("Not a valid relative time specification"));
1691  return ret;
1692 }
int GNUNET_STRINGS_fancy_time_to_relative(const char *fancy_time, struct GNUNET_TIME_Relative *rtime)
Convert a given fancy human-readable time to our internal representation.
Definition: strings.c:284
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct Experiment * e
configuration entry
Definition: configuration.c:42
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.
static struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
static char * section
Name of the section.
Definition: gnunet-config.c:33
static char * option
Name of the option.
Definition: gnunet-config.c:38
char * val
current, committed value
Definition: configuration.c:57
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_value_size()

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

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

Parameters
cfgconfiguration to inspect
sectionsection of interest
optionoption of interest
sizeset to the size in bytes as stored in the configuration
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 1696 of file configuration.c.

References e, find_entry(), GNUNET_STRINGS_fancy_size_to_bytes(), GNUNET_SYSERR, and ConfigEntry::val.

Referenced by GNUNET_DATACACHE_create(), and run().

1701 {
1702  struct ConfigEntry *e;
1703 
1704  if (NULL == (e = find_entry (cfg, section, option)))
1705  return GNUNET_SYSERR;
1706  if (NULL == e->val)
1707  return GNUNET_SYSERR;
1709 }
static struct Experiment * e
int GNUNET_STRINGS_fancy_size_to_bytes(const char *fancy_size, unsigned long long *size)
Convert a given fancy human-readable size to bytes.
Definition: strings.c:260
configuration entry
Definition: configuration.c:42
static struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
static char * section
Name of the section.
Definition: gnunet-config.c:33
static char * option
Name of the option.
Definition: gnunet-config.c:38
static unsigned int size
Size of the "table".
Definition: peer.c:67
char * val
current, committed value
Definition: configuration.c:57
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_have_value()

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

Test if we have a value for a particular option.

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

Definition at line 1805 of file configuration.c.

References e, find_entry(), GNUNET_NO, GNUNET_YES, and ConfigEntry::val.

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

1808 {
1809  struct ConfigEntry *e;
1810 
1811  if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1812  return GNUNET_NO;
1813  return GNUNET_YES;
1814 }
static struct Experiment * e
configuration entry
Definition: configuration.c:42
static struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
static char * section
Name of the section.
Definition: gnunet-config.c:33
static char * option
Name of the option.
Definition: gnunet-config.c:38
char * val
current, committed value
Definition: configuration.c:57
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_value_string()

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

Get a configuration value that should be a string.

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

Definition at line 1723 of file configuration.c.

References e, find_entry(), GNUNET_OK, GNUNET_strdup, GNUNET_SYSERR, and ConfigEntry::val.

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

1728 {
1729  struct ConfigEntry *e;
1730 
1731  if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1732  {
1733  *value = NULL;
1734  return GNUNET_SYSERR;
1735  }
1736  *value = GNUNET_strdup (e->val);
1737  return GNUNET_OK;
1738 }
static struct Experiment * e
configuration entry
Definition: configuration.c:42
static struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static char * section
Name of the section.
Definition: gnunet-config.c:33
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
char * val
current, committed value
Definition: configuration.c:57
Here is the call graph for this function:

◆ GNUNET_CONFIGURATION_get_value_filename()

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

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

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

Definition at line 2005 of file configuration.c.

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

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

2010 {
2011  char *tmp;
2012 
2013  if (GNUNET_OK !=
2015  {
2016  LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to retrieve filename\n");
2017  *value = NULL;
2018  return GNUNET_SYSERR;
2019  }
2020  tmp = GNUNET_CONFIGURATION_expand_dollar (cfg, tmp);
2022  GNUNET_free (tmp);
2023  if (*value == NULL)
2024  return GNUNET_SYSERR;
2025  return GNUNET_OK;
2026 }
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.
static char * section
Name of the section.
Definition: gnunet-config.c:33
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
#define LOG(kind,...)
Definition: configuration.c:34
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:482
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_iterate_value_filenames()

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

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

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

Definition at line 2050 of file configuration.c.

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

Referenced by GNUNET_CONFIGURATION_append_value_filename().

2056 {
2057  char *list;
2058  char *pos;
2059  char *end;
2060  char old;
2061  int ret;
2062 
2063  if (GNUNET_OK !=
2065  return 0;
2066  GNUNET_assert (list != NULL);
2067  ret = 0;
2068  pos = list;
2069  while (1)
2070  {
2071  while (pos[0] == ' ')
2072  pos++;
2073  if (strlen (pos) == 0)
2074  break;
2075  end = pos + 1;
2076  while ((end[0] != ' ') && (end[0] != '\0'))
2077  {
2078  if (end[0] == '\\')
2079  {
2080  switch (end[1])
2081  {
2082  case '\\':
2083  case ' ':
2084  memmove (end, &end[1], strlen (&end[1]) + 1);
2085 
2086  case '\0':
2087  /* illegal, but just keep it */
2088  break;
2089 
2090  default:
2091  /* illegal, but just ignore that there was a '/' */
2092  break;
2093  }
2094  }
2095  end++;
2096  }
2097  old = end[0];
2098  end[0] = '\0';
2099  if (strlen (pos) > 0)
2100  {
2101  ret++;
2102  if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos)))
2103  {
2104  ret = GNUNET_SYSERR;
2105  break;
2106  }
2107  }
2108  if (old == '\0')
2109  break;
2110  pos = end + 1;
2111  }
2112  GNUNET_free (list);
2113  return ret;
2114 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
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.
static char * section
Name of the section.
Definition: gnunet-config.c:33
static char * option
Name of the option.
Definition: gnunet-config.c:38
static int list
Set if we should print a list of currently running services.
Definition: gnunet-arm.c:69
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_iterate_section_values()

void GNUNET_CONFIGURATION_iterate_section_values ( const struct GNUNET_CONFIGURATION_Handle cfg,
const char *  section,
GNUNET_CONFIGURATION_Iterator  iter,
void *  iter_cls 
)

Iterate over values of a section in the configuration.

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

Definition at line 1400 of file configuration.c.

References 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_TESTING_system_create_with_portrange(), read_blacklist_configuration(), and run().

1405 {
1406  struct ConfigSection *spos;
1407  struct ConfigEntry *epos;
1408 
1409  spos = cfg->sections;
1410  while ((spos != NULL) && (0 != strcasecmp (spos->name, section)))
1411  spos = spos->next;
1412  if (NULL == spos)
1413  return;
1414  if (spos->inaccessible)
1415  {
1417  "Section '%s' is marked as inaccessible, because the configuration "
1418  " file that contains the section can't be read.\n",
1419  section);
1420  return;
1421  }
1422  for (epos = spos->entries; NULL != epos; epos = epos->next)
1423  if (NULL != epos->val)
1424  iter (iter_cls, spos->name, epos->key, epos->val);
1425 }
struct ConfigEntry * entries
entries in the section
Definition: configuration.c:84
configuration entry
Definition: configuration.c:42
static char * section
Name of the section.
Definition: gnunet-config.c:33
char * name
name of the section
Definition: configuration.c:89
struct ConfigSection * sections
Configuration sections.
#define LOG(kind,...)
Definition: configuration.c:34
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:47
configuration section
Definition: configuration.c:74
bool inaccessible
Is the configuration section marked as inaccessible?
Definition: configuration.c:97
char * key
key for this entry
Definition: configuration.c:52
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:79
char * val
current, committed value
Definition: configuration.c:57
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 1742 of file configuration.c.

References _, e, find_entry(), GNUNET_ERROR_TYPE_ERROR, GNUNET_OK, GNUNET_SYSERR, LOG, and ConfigEntry::val.

Referenced by GNUNET_CONFIGURATION_get_value_yesno(), and start_process().

1748 {
1749  struct ConfigEntry *e;
1750  unsigned int i;
1751 
1752  if (NULL == (e = find_entry (cfg, section, option)))
1753  return GNUNET_SYSERR;
1754  for (i = 0; NULL != choices[i]; i++)
1755  if (0 == strcasecmp (choices[i], e->val))
1756  break;
1757  if (NULL == choices[i])
1758  {
1760  _ ("Configuration value '%s' for '%s'"
1761  " in section '%s' is not in set of legal choices\n"),
1762  e->val,
1763  option,
1764  section);
1765  return GNUNET_SYSERR;
1766  }
1767  *value = choices[i];
1768  return GNUNET_OK;
1769 }
static struct Experiment * e
configuration entry
Definition: configuration.c:42
static struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
static char * section
Name of the section.
Definition: gnunet-config.c:33
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
#define LOG(kind,...)
Definition: configuration.c:34
char * val
current, committed value
Definition: configuration.c:57
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_value_yesno()

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

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

Parameters
cfgconfiguration to inspect
sectionsection of interest
optionoption of interest
Returns
GNUNET_YES, GNUNET_NO or if option has no valid value, GNUNET_SYSERR

Definition at line 2030 of file configuration.c.

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

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

2034 {
2035  static const char *yesno[] = { "YES", "NO", NULL };
2036  const char *val;
2037  int ret;
2038 
2039  ret =
2041  if (ret == GNUNET_SYSERR)
2042  return ret;
2043  if (val == yesno[0])
2044  return GNUNET_YES;
2045  return GNUNET_NO;
2046 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
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.
static char * section
Name of the section.
Definition: gnunet-config.c:33
static char * option
Name of the option.
Definition: gnunet-config.c:38
char * val
current, committed value
Definition: configuration.c:57
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_data()

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

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

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

Definition at line 1773 of file configuration.c.

References data_size, enc, GNUNET_CONFIGURATION_get_value_string(), GNUNET_free, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, and res.

Referenced by callback_scan_for_rooms(), load_member(), load_member_session_next(), and load_operation().

1778 {
1779  char *enc;
1780  int res;
1781  size_t data_size;
1782 
1783  if (GNUNET_OK !=
1784  (res =
1786  return res;
1787  data_size = (strlen (enc) * 5) / 8;
1788  if (data_size != buf_size)
1789  {
1790  GNUNET_free (enc);
1791  return GNUNET_SYSERR;
1792  }
1793  if (GNUNET_OK !=
1794  GNUNET_STRINGS_string_to_data (enc, strlen (enc), buf, buf_size))
1795  {
1796  GNUNET_free (enc);
1797  return GNUNET_SYSERR;
1798  }
1799  GNUNET_free (enc);
1800  return GNUNET_OK;
1801 }
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
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.
static char * section
Name of the section.
Definition: gnunet-config.c:33
static char * option
Name of the option.
Definition: gnunet-config.c:38
static char buf[2048]
static int res
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:775
static OpusEncoder * enc
OPUS encoder.
#define GNUNET_free(ptr)
Wrapper around free.
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 1980 of file configuration.c.

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

Referenced by expand_dollar(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_TESTING_peer_start(), run(), start_arm_service(), and start_process().

1983 {
1984  char *dup;
1985  size_t i;
1986  size_t len;
1987 
1988  for (i = 0; '\0' != orig[i]; i++)
1989  {
1990  if ('$' != orig[i])
1991  continue;
1992  dup = GNUNET_strdup (orig + i);
1993  dup = expand_dollar (cfg, dup, 0);
1994  GNUNET_assert (NULL != dup); /* make compiler happy */
1995  len = strlen (dup) + 1;
1996  orig = GNUNET_realloc (orig, i + len);
1997  GNUNET_memcpy (orig + i, dup, len);
1998  GNUNET_free (dup);
1999  }
2000  return orig;
2001 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
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_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
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 1619 of file configuration.c.

References GNUNET_CONFIGURATION_set_value_string(), and GNUNET_snprintf().

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

1623 {
1624  char s[64];
1625 
1626  GNUNET_snprintf (s, 64, "%llu", number);
1628 }
uint32_t number
static char * section
Name of the section.
Definition: gnunet-config.c:33
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.
static char * option
Name of the option.
Definition: gnunet-config.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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_set_value_string()

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

Set a configuration value that should be a string.

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

Definition at line 1577 of file configuration.c.

References e, ConfigSection::entries, find_entry(), find_section(), GNUNET_free, GNUNET_new, GNUNET_strdup, ConfigEntry::key, ConfigSection::name, ConfigEntry::next, ConfigSection::next, GNUNET_CONFIGURATION_Handle::sections, and ConfigEntry::val.

Referenced by associate_shared_service(), auto_conf_iter(), auto_config_cb(), cfg_copy_iterator(), compare_entries(), copy_entry(), GNUNET_CONFIGURATION_append_value_filename(), GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_deserialize(), GNUNET_CONFIGURATION_load(), GNUNET_CONFIGURATION_remove_value_filename(), GNUNET_CONFIGURATION_set_value_number(), GNUNET_NAT_autoconfig_start(), GNUNET_PROGRAM_run2(), GNUNET_TESTBED_extract_cfg(), GNUNET_TESTING_configuration_create_(), handle_ego_delete(), handle_ego_rename(), handle_inline(), handle_set_default_message(), identity_cb(), iterate_save_rooms(), next_phase(), process_if(), result_callback(), run(), save_member(), save_member_session(), save_operation(), set_external_ipv4(), set_value(), test_local_ip(), test_upnpc(), update_config(), update_config_sections(), and update_enable_upnpc_option().

1581 {
1582  struct ConfigSection *sec;
1583  struct ConfigEntry *e;
1584  char *nv;
1585 
1586  e = find_entry (cfg, section, option);
1587  if (NULL != e)
1588  {
1589  if (NULL == value)
1590  {
1591  GNUNET_free (e->val);
1592  e->val = NULL;
1593  }
1594  else
1595  {
1596  nv = GNUNET_strdup (value);
1597  GNUNET_free (e->val);
1598  e->val = nv;
1599  }
1600  return;
1601  }
1602  sec = find_section (cfg, section);
1603  if (sec == NULL)
1604  {
1605  sec = GNUNET_new (struct ConfigSection);
1606  sec->name = GNUNET_strdup (section);
1607  sec->next = cfg->sections;
1608  cfg->sections = sec;
1609  }
1610  e = GNUNET_new (struct ConfigEntry);
1611  e->key = GNUNET_strdup (option);
1612  e->val = GNUNET_strdup (value);
1613  e->next = sec->entries;
1614  sec->entries = e;
1615 }
struct ConfigEntry * entries
entries in the section
Definition: configuration.c:84
static struct Experiment * e
configuration entry
Definition: configuration.c:42
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static char * section
Name of the section.
Definition: gnunet-config.c:33
char * name
name of the section
Definition: configuration.c:89
static struct ConfigSection * find_section(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Find a section entry from a configuration.
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
struct ConfigSection * sections
Configuration sections.
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:47
configuration section
Definition: configuration.c:74
char * key
key for this entry
Definition: configuration.c:52
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:79
char * val
current, committed value
Definition: configuration.c:57
#define GNUNET_free(ptr)
Wrapper around free.
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 2207 of file configuration.c.

References end, escape_name(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_free, GNUNET_NO, GNUNET_OK, and list.

2212 {
2213  char *list;
2214  char *pos;
2215  char *end;
2216  char *match;
2217  char old;
2218 
2219  if (GNUNET_OK !=
2221  return GNUNET_NO;
2222  match = escape_name (value);
2223  pos = list;
2224  while (1)
2225  {
2226  while (pos[0] == ' ')
2227  pos++;
2228  if (strlen (pos) == 0)
2229  break;
2230  end = pos + 1;
2231  while ((end[0] != ' ') && (end[0] != '\0'))
2232  {
2233  if (end[0] == '\\')
2234  {
2235  switch (end[1])
2236  {
2237  case '\\':
2238  case ' ':
2239  end++;
2240  break;
2241 
2242  case '\0':
2243  /* illegal, but just keep it */
2244  break;
2245 
2246  default:
2247  /* illegal, but just ignore that there was a '/' */
2248  break;
2249  }
2250  }
2251  end++;
2252  }
2253  old = end[0];
2254  end[0] = '\0';
2255  if (0 == strcmp (pos, match))
2256  {
2257  if (old != '\0')
2258  memmove (pos, &end[1], strlen (&end[1]) + 1);
2259  else
2260  {
2261  if (pos != list)
2262  pos[-1] = '\0';
2263  else
2264  pos[0] = '\0';
2265  }
2267  GNUNET_free (list);
2268  GNUNET_free (match);
2269  return GNUNET_OK;
2270  }
2271  if (old == '\0')
2272  break;
2273  end[0] = old;
2274  pos = end + 1;
2275  }
2276  GNUNET_free (list);
2277  GNUNET_free (match);
2278  return GNUNET_NO;
2279 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
static char * escape_name(const char *value)
FIXME.
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.
static char * section
Name of the section.
Definition: gnunet-config.c:33
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.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.
static int list
Set if we should print a list of currently running services.
Definition: gnunet-arm.c:69
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ GNUNET_CONFIGURATION_append_value_filename()

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

Append a filename to a configuration value that represents a list of filenames.

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

Definition at line 2172 of file configuration.c.

References escape_name(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_iterate_value_filenames(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_free, GNUNET_malloc, GNUNET_NO, GNUNET_OK, GNUNET_strdup, GNUNET_SYSERR, and test_match().

2177 {
2178  char *escaped;
2179  char *old;
2180  char *nw;
2181 
2182  if (GNUNET_SYSERR ==
2184  section,
2185  option,
2186  &test_match,
2187  (void *) value))
2188  return GNUNET_NO; /* already exists */
2189  if (GNUNET_OK !=
2191  old = GNUNET_strdup ("");
2192  escaped = escape_name (value);
2193  nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2);
2194  strcpy (nw, old);
2195  if (strlen (old) > 0)
2196  strcat (nw, " ");
2197  strcat (nw, escaped);
2199  GNUNET_free (old);
2200  GNUNET_free (nw);
2201  GNUNET_free (escaped);
2202  return GNUNET_OK;
2203 }
static enum GNUNET_GenericReturnValue test_match(void *cls, const char *fn)
FIXME.
static char * escape_name(const char *value)
FIXME.
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.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static char * section
Name of the section.
Definition: gnunet-config.c:33
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.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.
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.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function: