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...
 
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...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *basedir)
 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_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 218 of file gnunet_configuration_lib.h.

◆ GNUNET_CONFIGURATION_Iterator

typedef void(* GNUNET_CONFIGURATION_Iterator) (void *cls, const char *section, const char *option, const char *value)

Function to iterate over options.

Parameters
clsclosure
sectionname of the section
optionname of the option
valuevalue of the option

Definition at line 248 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 261 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 113 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_config_(), GNUNET_TESTING_service_run(), GNUNET_TESTING_system_create_with_portrange(), GNUNET_TRANSPORT_TESTING_start_peer(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(), handle_auto_result(), handle_autoconfig_request(), helper_mst(), iter_check_config(), iterate_save_rooms(), LEGACY_SERVICE_run(), load_member(), load_member_session(), load_member_session_next(), load_operation(), main(), run(), save_member(), save_member_session(), save_operation(), and tokenizer_cb().

114 {
116  char *p;
117 
119  /* make certain values from the project data available
120  as PATHS */
122  if (NULL != p)
123  {
125  "PATHS",
126  "DATADIR",
127  p);
128  GNUNET_free (p);
129  }
131  if (NULL != p)
132  {
134  "PATHS",
135  "LIBDIR",
136  p);
137  GNUNET_free (p);
138  }
140  if (NULL != p)
141  {
143  "PATHS",
144  "BINDIR",
145  p);
146  GNUNET_free (p);
147  }
149  if (NULL != p)
150  {
152  "PATHS",
153  "PREFIX",
154  p);
155  GNUNET_free (p);
156  }
158  if (NULL != p)
159  {
161  "PATHS",
162  "LOCALEDIR",
163  p);
164  GNUNET_free (p);
165  }
167  if (NULL != p)
168  {
170  "PATHS",
171  "ICONDIR",
172  p);
173  GNUNET_free (p);
174  }
176  if (NULL != p)
177  {
179  "PATHS",
180  "DOCDIR",
181  p);
182  GNUNET_free (p);
183  }
185  if (NULL != p)
186  {
188  "PATHS",
189  "LIBEXECDIR",
190  p);
191  GNUNET_free (p);
192  }
193  return cfg;
194 }
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
Definition: configuration.c:84
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 754 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().

755 {
757 
760  return ret;
761 }
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
Definition: configuration.c:84
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 198 of file configuration.c.

References GNUNET_CONFIGURATION_remove_section(), GNUNET_free, ConfigSection::name, and GNUNET_CONFIGURATION_Handle::sections.

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_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_link_controllers_result(), helper_mst(), iterate_save_rooms(), LEGACY_SERVICE_run(), load_member(), load_member_session(), load_member_session_next(), load_operation(), main(), next_phase(), oprelease_get_slave_config(), oprelease_peer_getinfo(), oprelease_service_connect(), run(), save_member(), save_member_session(), save_operation(), shutdown_task(), tokenizer_cb(), and update_peer_config().

199 {
200  struct ConfigSection *sec;
201 
202  while (NULL != (sec = cfg->sections))
204  GNUNET_free (cfg);
205 }
char * name
name of the section
Definition: configuration.c:77
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.
Definition: configuration.c:89
configuration section
Definition: configuration.c:62
#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 42 of file configuration_loader.c.

References GNUNET_OS_ProjectData::base_config_varname, getenv(), GNUNET_asprintf(), GNUNET_CONFIGURATION_have_value(), GNUNET_CONFIGURATION_load_from(), GNUNET_CONFIGURATION_parse(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_DISK_directory_test(), 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, and GNUNET_YES.

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

44 {
45  char *baseconfig;
46  const char *base_config_varname;
47 
48  base_config_varname = GNUNET_OS_project_data_get ()->base_config_varname;
49 
50  if (NULL != base_config_varname
51  && NULL != (baseconfig = getenv (base_config_varname)))
52  {
53  baseconfig = GNUNET_strdup (baseconfig);
54  }
55  else
56  {
57  char *ipath;
58 
60  if (NULL == ipath)
61  return GNUNET_SYSERR;
62  GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d");
63  GNUNET_free (ipath);
64  }
65 
66  char *dname = GNUNET_STRINGS_filename_expand (baseconfig);
67  GNUNET_free (baseconfig);
68 
71  {
72  GNUNET_free (dname);
73  return GNUNET_SYSERR; /* no configuration at all found */
74  }
75  GNUNET_free (dname);
76  if ((NULL != filename) &&
78  {
79  /* specified configuration not found */
80  return GNUNET_SYSERR;
81  }
82  if (((GNUNET_YES !=
83  GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) &&
84  (filename != NULL))
85  GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG",
86  filename);
87  return GNUNET_OK;
88 }
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_.
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.
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:618
char * getenv()
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)
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 1600 of file configuration.c.

References GNUNET_DISK_directory_scan(), GNUNET_OK, GNUNET_SYSERR, and parse_configuration_file().

Referenced by GNUNET_CONFIGURATION_load().

1602 {
1603  if (GNUNET_SYSERR ==
1605  return GNUNET_SYSERR; /* no configuration at all found */
1606  return GNUNET_OK;
1607 }
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:794
static enum GNUNET_GenericReturnValue parse_configuration_file(void *cls, const char *filename)
Wrapper around GNUNET_CONFIGURATION_parse.
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 1611 of file configuration.c.

References cfg, GNUNET_OS_ProjectData::config_file, getenv(), GNUNET_asprintf(), GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_load(), GNUNET_free, GNUNET_OK, GNUNET_OS_init(), GNUNET_OS_project_data_default(), GNUNET_OS_project_data_get(), GNUNET_strdup, and GNUNET_OS_ProjectData::user_config_file.

1612 {
1613  const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
1615  const char *xdg = getenv ("XDG_CONFIG_HOME");
1616  char *cfgname = NULL;
1618 
1619  GNUNET_OS_init (dpd);
1620  cfg = GNUNET_CONFIGURATION_create ();
1621  if (NULL != xdg)
1622  GNUNET_asprintf (&cfgname, "%s/%s", xdg, pd->config_file);
1623  else
1624  cfgname = GNUNET_strdup (pd->user_config_file);
1625  if (GNUNET_OK !=
1626  GNUNET_CONFIGURATION_load (cfg, cfgname))
1627  {
1628  GNUNET_OS_init (pd);
1630  GNUNET_free (cfgname);
1631  return NULL;
1632  }
1633  GNUNET_free (cfgname);
1634  GNUNET_OS_init (pd);
1635  return cfg;
1636 }
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
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
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 'libgnunetutil' 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.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
char * getenv()
configuration data
Definition: configuration.c:84
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.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ GNUNET_CONFIGURATION_parse()

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

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

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

Definition at line 383 of file configuration.c.

References _, GNUNET_CONFIGURATION_Handle::dirty, fn, fs, GNUNET_break, GNUNET_CONFIGURATION_deserialize(), GNUNET_DISK_file_size(), GNUNET_DISK_fn_read(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_malloc, GNUNET_STRINGS_filename_expand(), GNUNET_SYSERR, GNUNET_YES, LOG, ret, and SIZE_MAX.

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

385 {
386  uint64_t fs64;
387  size_t fs;
388  char *fn;
389  char *mem;
390  char *endsep;
391  int dirty;
393  ssize_t sret;
394 
396  LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to parse config file `%s'\n", fn);
397  if (NULL == fn)
398  return GNUNET_SYSERR;
399  dirty = cfg->dirty; /* back up value! */
400  if (GNUNET_SYSERR ==
402  {
404  "Error while determining the file size of `%s'\n",
405  fn);
406  GNUNET_free (fn);
407  return GNUNET_SYSERR;
408  }
409  if (fs64 > SIZE_MAX)
410  {
411  GNUNET_break (0); /* File size is more than the heap size */
412  GNUNET_free (fn);
413  return GNUNET_SYSERR;
414  }
415  fs = fs64;
416  mem = GNUNET_malloc (fs);
417  sret = GNUNET_DISK_fn_read (fn, mem, fs);
418  if ((sret < 0) || (fs != (size_t) sret))
419  {
420  LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Error while reading file `%s'\n"), fn);
421  GNUNET_free (fn);
422  GNUNET_free (mem);
423  return GNUNET_SYSERR;
424  }
425  LOG (GNUNET_ERROR_TYPE_DEBUG, "Deserializing contents of file `%s'\n", fn);
426  endsep = strrchr (fn, (int) '/');
427  if (NULL != endsep)
428  *endsep = '\0';
429  ret = GNUNET_CONFIGURATION_deserialize (cfg, mem, fs, fn);
430  GNUNET_free (fn);
431  GNUNET_free (mem);
432  /* restore dirty flag - anything we set in the meantime
433  * came from disk */
434  cfg->dirty = dirty;
435  return ret;
436 }
enum GNUNET_GenericReturnValue dirty
Modification indication since last save GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on err...
Definition: configuration.c:96
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *basedir)
De-serializes 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
#define SIZE_MAX
Definition: platform.h:214
#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
static char * fn
Filename of the unique file.
static char * filename
#define LOG(kind,...)
Definition: configuration.c:32
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:618
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_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:644
#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 482 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().

484 {
485  char *mem;
486  char *cbuf;
487  char *val;
488  char *pos;
489  size_t m_size;
490  size_t c_size;
491 
492  /* Pass1 : calculate the buffer size required */
493  m_size = 0;
494  for (struct ConfigSection *sec = cfg->sections;
495  NULL != sec;
496  sec = sec->next)
497  {
498  /* For each section we need to add 3 characters: {'[',']','\n'} */
499  m_size += strlen (sec->name) + 3;
500  for (struct ConfigEntry *ent = sec->entries;
501  NULL != ent;
502  ent = ent->next)
503  {
504  if (do_skip (sec->name,
505  ent->key))
506  continue;
507  if (NULL != ent->val)
508  {
509  /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */
510  pos = ent->val;
511  while (NULL != (pos = strstr (pos, "\n")))
512  {
513  m_size++;
514  pos++;
515  }
516  /* For each key = value pair we need to add 4 characters (2
517  spaces and 1 equal-to character and 1 new line) */
518  m_size += strlen (ent->key) + strlen (ent->val) + 4;
519  }
520  }
521  /* A new line after section end */
522  m_size++;
523  }
524 
525  /* Pass2: Allocate memory and write the configuration to it */
526  mem = GNUNET_malloc (m_size);
527  c_size = 0;
528  *size = c_size;
529  for (struct ConfigSection *sec = cfg->sections;
530  NULL != sec;
531  sec = sec->next)
532  {
533  int len;
534 
535  len = GNUNET_asprintf (&cbuf,
536  "[%s]\n",
537  sec->name);
538  GNUNET_assert (0 < len);
539  GNUNET_memcpy (mem + c_size,
540  cbuf,
541  len);
542  c_size += len;
543  GNUNET_free (cbuf);
544  for (struct ConfigEntry *ent = sec->entries;
545  NULL != ent;
546  ent = ent->next)
547  {
548  if (do_skip (sec->name,
549  ent->key))
550  continue;
551  if (NULL != ent->val)
552  {
553  val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
554  strcpy (val, ent->val);
555  while (NULL != (pos = strstr (val, "\n")))
556  {
557  memmove (&pos[2], &pos[1], strlen (&pos[1]));
558  pos[0] = '\\';
559  pos[1] = 'n';
560  }
561  len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
562  GNUNET_free (val);
563  GNUNET_memcpy (mem + c_size, cbuf, len);
564  c_size += len;
565  GNUNET_free (cbuf);
566  }
567  }
568  GNUNET_memcpy (mem + c_size, "\n", 1);
569  c_size++;
570  }
571  GNUNET_assert (c_size == m_size);
572  *size = c_size;
573  return mem;
574 }
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:40
struct ConfigSection * sections
Configuration sections.
Definition: configuration.c:89
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:45
configuration section
Definition: configuration.c:62
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:67
#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_deserialize()

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

De-serializes configuration.

Parameters
cfgconfiguration to update
memthe memory block of serialized configuration
sizethe size of the memory block
allow_inlineset to the base directory if we recursively load configuration from inlined configurations; NULL if not and raise warnings when we come across them
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 230 of file configuration.c.

References _, fn, GNUNET_asprintf(), GNUNET_assert, GNUNET_CONFIGURATION_parse(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_NO, GNUNET_OK, GNUNET_strdup, GNUNET_strndup, GNUNET_SYSERR, GNUNET_YES, line, LOG, ret, section, and value.

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

234 {
235  char *line;
236  char *line_orig;
237  size_t line_size;
238  char *pos;
239  unsigned int nr;
240  size_t r_bytes;
241  size_t to_read;
242  size_t i;
243  int emptyline;
245  char *section;
246  char *eq;
247  char *tag;
248  char *value;
249 
250  ret = GNUNET_OK;
251  section = GNUNET_strdup ("");
252  nr = 0;
253  r_bytes = 0;
254  line_orig = NULL;
255  while (r_bytes < size)
256  {
257  GNUNET_free (line_orig);
258  /* fgets-like behaviour on buffer */
259  to_read = size - r_bytes;
260  pos = memchr (&mem[r_bytes], '\n', to_read);
261  if (NULL == pos)
262  {
263  line_orig = GNUNET_strndup (&mem[r_bytes], line_size = to_read);
264  r_bytes += line_size;
265  }
266  else
267  {
268  line_orig =
269  GNUNET_strndup (&mem[r_bytes], line_size = (pos - &mem[r_bytes]));
270  r_bytes += line_size + 1;
271  }
272  line = line_orig;
273  /* increment line number */
274  nr++;
275  /* tabs and '\r' are whitespace */
276  emptyline = GNUNET_YES;
277  for (i = 0; i < line_size; i++)
278  {
279  if (line[i] == '\t')
280  line[i] = ' ';
281  if (line[i] == '\r')
282  line[i] = ' ';
283  if (' ' != line[i])
284  emptyline = GNUNET_NO;
285  }
286  /* ignore empty lines */
287  if (GNUNET_YES == emptyline)
288  continue;
289 
290  /* remove tailing whitespace */
291  for (i = line_size - 1; (i >= 1) && (isspace ((unsigned char) line[i]));
292  i--)
293  line[i] = '\0';
294 
295  /* remove leading whitespace */
296  for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++)
297  ;
298 
299  /* ignore comments */
300  if (('#' == line[0]) || ('%' == line[0]))
301  continue;
302 
303  /* handle special "@INLINE@" directive */
304  if (0 == strncasecmp (line, "@INLINE@ ", strlen ("@INLINE@ ")))
305  {
306  /* @INLINE@ value */
307  value = &line[strlen ("@INLINE@ ")];
308  if (NULL != basedir)
309  {
310  char *fn;
311 
312  GNUNET_asprintf (&fn, "%s/%s", basedir, value);
313  if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, fn))
314  {
315  GNUNET_free (fn);
316  ret = GNUNET_SYSERR; /* failed to parse included config */
317  break;
318  }
319  GNUNET_free (fn);
320  }
321  else
322  {
324  "Ignoring parsing @INLINE@ configurations, not allowed!\n");
325  ret = GNUNET_SYSERR;
326  break;
327  }
328  continue;
329  }
330  if (('[' == line[0]) && (']' == line[line_size - 1]))
331  {
332  /* [value] */
333  line[line_size - 1] = '\0';
334  value = &line[1];
335  GNUNET_free (section);
336  section = GNUNET_strdup (value);
337  continue;
338  }
339  if (NULL != (eq = strchr (line, '=')))
340  {
341  /* tag = value */
342  tag = GNUNET_strndup (line, eq - line);
343  /* remove tailing whitespace */
344  for (i = strlen (tag) - 1; (i >= 1) && (isspace ((unsigned char) tag[i]));
345  i--)
346  tag[i] = '\0';
347 
348  /* Strip whitespace */
349  value = eq + 1;
350  while (isspace ((unsigned char) value[0]))
351  value++;
352  for (i = strlen (value) - 1;
353  (i >= 1) && (isspace ((unsigned char) value[i]));
354  i--)
355  value[i] = '\0';
356 
357  /* remove quotes */
358  i = 0;
359  if (('"' == value[0]) && ('"' == value[strlen (value) - 1]))
360  {
361  value[strlen (value) - 1] = '\0';
362  value++;
363  }
364  GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, &value[i]);
365  GNUNET_free (tag);
366  continue;
367  }
368  /* parse error */
370  _ ("Syntax error while deserializing in line %u\n"),
371  nr);
372  ret = GNUNET_SYSERR;
373  break;
374  }
375  GNUNET_free (line_orig);
376  GNUNET_free (section);
377  GNUNET_assert ((GNUNET_OK != ret) || (r_bytes == size));
378  return ret;
379 }
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_assert(cond)
Use this for fatal errors that cannot be handled.
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.
static char * fn
Filename of the unique file.
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:32
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
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
#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 578 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().

580 {
581  char *fn;
582  char *cfg_buf;
583  size_t size;
584 
586  if (fn == NULL)
587  return GNUNET_SYSERR;
589  {
590  GNUNET_free (fn);
591  return GNUNET_SYSERR;
592  }
593  cfg_buf = GNUNET_CONFIGURATION_serialize (cfg,
594  &size);
595  {
596  struct GNUNET_DISK_FileHandle *h;
597 
598  h = GNUNET_DISK_file_open (fn,
606  if (NULL == h)
607  {
608  GNUNET_free (fn);
609  GNUNET_free (cfg_buf);
610  return GNUNET_SYSERR;
611  }
612  if (((ssize_t) size) !=
614  cfg_buf,
615  size))
616  {
618  "write",
619  fn);
621  (void) GNUNET_DISK_directory_remove (fn);
622  GNUNET_free (fn);
623  GNUNET_free (cfg_buf);
624  cfg->dirty = GNUNET_SYSERR; /* last write failed */
625  return GNUNET_SYSERR;
626  }
629  }
630  GNUNET_free (fn);
631  GNUNET_free (cfg_buf);
632  cfg->dirty = GNUNET_NO; /* last write succeeded */
633  return GNUNET_OK;
634 }
enum GNUNET_GenericReturnValue dirty
Modification indication since last save GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on err...
Definition: configuration.c:96
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:1126
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:666
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:618
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:905
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:562
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:1055
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 851 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().

855 {
856  int ret;
857  struct GNUNET_CONFIGURATION_Handle *diff;
858 
859  diff = GNUNET_CONFIGURATION_get_diff (cfg_default, cfg_new);
860  ret = GNUNET_CONFIGURATION_write (diff, filename);
862  return ret;
863 }
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
Definition: configuration.c:84
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 837 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().

840 {
841  struct DiffHandle diffHandle;
842 
843  diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
844  diffHandle.cfg_default = cfg_default;
845  GNUNET_CONFIGURATION_iterate (cfg_new, &compare_entries, &diffHandle);
846  return diffHandle.cfgDiff;
847 }
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 440 of file configuration.c.

References GNUNET_CONFIGURATION_Handle::dirty.

Referenced by auto_config_cb().

441 {
442  return cfg->dirty;
443 }
enum GNUNET_GenericReturnValue dirty
Modification indication since last save GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on err...
Definition: configuration.c:96
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 209 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().

212 {
215 
218  {
219  GNUNET_break (0);
221  return GNUNET_SYSERR;
222  }
223  ret = cb (cb_cls, cfg);
225  return ret;
226 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load 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
Definition: configuration.c:84
Here is the call graph for this function:
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 638 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_().

641 {
642  for (struct ConfigSection *spos = cfg->sections;
643  NULL != spos;
644  spos = spos->next)
645  for (struct ConfigEntry *epos = spos->entries;
646  NULL != epos;
647  epos = epos->next)
648  if (NULL != epos->val)
649  iter (iter_cls,
650  spos->name,
651  epos->key,
652  epos->val);
653 }
configuration entry
Definition: configuration.c:40
struct ConfigSection * sections
Configuration sections.
Definition: configuration.c:89
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:45
configuration section
Definition: configuration.c:62
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:67
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 678 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().

682 {
683  struct ConfigSection *spos;
684  struct ConfigSection *next;
685 
686  next = cfg->sections;
687  while (next != NULL)
688  {
689  spos = next;
690  next = spos->next;
691  iter (iter_cls, spos->name);
692  }
693 }
char * name
name of the section
Definition: configuration.c:77
struct ConfigSection * sections
Configuration sections.
Definition: configuration.c:89
configuration section
Definition: configuration.c:62
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:67
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 697 of file configuration.c.

References GNUNET_CONFIGURATION_Handle::dirty, ConfigSection::entries, GNUNET_free, GNUNET_YES, 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().

699 {
700  struct ConfigSection *spos;
701  struct ConfigSection *prev;
702  struct ConfigEntry *ent;
703 
704  prev = NULL;
705  spos = cfg->sections;
706  while (NULL != spos)
707  {
708  if (0 == strcasecmp (section, spos->name))
709  {
710  if (NULL == prev)
711  cfg->sections = spos->next;
712  else
713  prev->next = spos->next;
714  while (NULL != (ent = spos->entries))
715  {
716  spos->entries = ent->next;
717  GNUNET_free (ent->key);
718  GNUNET_free (ent->val);
719  GNUNET_free (ent);
720  cfg->dirty = GNUNET_YES;
721  }
722  GNUNET_free (spos->name);
723  GNUNET_free (spos);
724  return;
725  }
726  prev = spos;
727  spos = spos->next;
728  }
729 }
enum GNUNET_GenericReturnValue dirty
Modification indication since last save GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on err...
Definition: configuration.c:96
struct ConfigEntry * entries
entries in the section
Definition: configuration.c:72
configuration entry
Definition: configuration.c:40
static char * section
Name of the section.
Definition: gnunet-config.c:33
char * name
name of the section
Definition: configuration.c:77
struct ConfigSection * sections
Configuration sections.
Definition: configuration.c:89
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:45
configuration section
Definition: configuration.c:62
char * key
key for this entry
Definition: configuration.c:50
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:67
char * val
current, committed value
Definition: configuration.c:55
#define GNUNET_free(ptr)
Wrapper around free.
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 922 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_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(), server_configure_plugin(), server_get_addresses(), setup_exit_helper_args(), test_service_configuration(), test_stun(), testbed_run(), and update_config().

927 {
928  struct ConfigEntry *e;
929  char dummy[2];
930 
931  if (NULL == (e = find_entry (cfg, section, option)))
932  return GNUNET_SYSERR;
933  if (NULL == e->val)
934  return GNUNET_SYSERR;
935  if (1 != sscanf (e->val, "%llu%1s", number, dummy))
936  return GNUNET_SYSERR;
937  return GNUNET_OK;
938 }
static struct Experiment * e
configuration entry
Definition: configuration.c:40
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:55
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 942 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().

947 {
948  struct ConfigEntry *e;
949  char dummy[2];
950 
951  if (NULL == (e = find_entry (cfg, section, option)))
952  return GNUNET_SYSERR;
953  if (NULL == e->val)
954  return GNUNET_SYSERR;
955  if (1 != sscanf (e->val, "%f%1s", number, dummy))
956  return GNUNET_SYSERR;
957  return GNUNET_OK;
958 }
static struct Experiment * e
configuration entry
Definition: configuration.c:40
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:55
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 962 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().

967 {
968  struct ConfigEntry *e;
969  int ret;
970 
971  if (NULL == (e = find_entry (cfg, section, option)))
972  return GNUNET_SYSERR;
973  if (NULL == e->val)
974  return GNUNET_SYSERR;
976  if (GNUNET_OK != ret)
978  section,
979  option,
980  _ ("Not a valid relative time specification"));
981  return ret;
982 }
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:356
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct Experiment * e
configuration entry
Definition: configuration.c:40
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:55
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 986 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().

991 {
992  struct ConfigEntry *e;
993 
994  if (NULL == (e = find_entry (cfg, section, option)))
995  return GNUNET_SYSERR;
996  if (NULL == e->val)
997  return GNUNET_SYSERR;
999 }
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:324
configuration entry
Definition: configuration.c:40
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:55
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 1095 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().

1098 {
1099  struct ConfigEntry *e;
1100 
1101  if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1102  return GNUNET_NO;
1103  return GNUNET_YES;
1104 }
static struct Experiment * e
configuration entry
Definition: configuration.c:40
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:55
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 1013 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_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().

1018 {
1019  struct ConfigEntry *e;
1020 
1021  if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1022  {
1023  *value = NULL;
1024  return GNUNET_SYSERR;
1025  }
1026  *value = GNUNET_strdup (e->val);
1027  return GNUNET_OK;
1028 }
static struct Experiment * e
configuration entry
Definition: configuration.c:40
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:55
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 1295 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(), 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().

1300 {
1301  char *tmp;
1302 
1303  if (GNUNET_OK !=
1305  {
1306  LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to retrieve filename\n");
1307  *value = NULL;
1308  return GNUNET_SYSERR;
1309  }
1310  tmp = GNUNET_CONFIGURATION_expand_dollar (cfg, tmp);
1312  GNUNET_free (tmp);
1313  if (*value == NULL)
1314  return GNUNET_SYSERR;
1315  return GNUNET_OK;
1316 }
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:32
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:618
#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 1340 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().

1346 {
1347  char *list;
1348  char *pos;
1349  char *end;
1350  char old;
1351  int ret;
1352 
1353  if (GNUNET_OK !=
1355  return 0;
1356  GNUNET_assert (list != NULL);
1357  ret = 0;
1358  pos = list;
1359  while (1)
1360  {
1361  while (pos[0] == ' ')
1362  pos++;
1363  if (strlen (pos) == 0)
1364  break;
1365  end = pos + 1;
1366  while ((end[0] != ' ') && (end[0] != '\0'))
1367  {
1368  if (end[0] == '\\')
1369  {
1370  switch (end[1])
1371  {
1372  case '\\':
1373  case ' ':
1374  memmove (end, &end[1], strlen (&end[1]) + 1);
1375 
1376  case '\0':
1377  /* illegal, but just keep it */
1378  break;
1379 
1380  default:
1381  /* illegal, but just ignore that there was a '/' */
1382  break;
1383  }
1384  }
1385  end++;
1386  }
1387  old = end[0];
1388  end[0] = '\0';
1389  if (strlen (pos) > 0)
1390  {
1391  ret++;
1392  if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos)))
1393  {
1394  ret = GNUNET_SYSERR;
1395  break;
1396  }
1397  }
1398  if (old == '\0')
1399  break;
1400  pos = end + 1;
1401  }
1402  GNUNET_free (list);
1403  return ret;
1404 }
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 657 of file configuration.c.

References ConfigSection::entries, ConfigEntry::key, 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().

662 {
663  struct ConfigSection *spos;
664  struct ConfigEntry *epos;
665 
666  spos = cfg->sections;
667  while ((spos != NULL) && (0 != strcasecmp (spos->name, section)))
668  spos = spos->next;
669  if (NULL == spos)
670  return;
671  for (epos = spos->entries; NULL != epos; epos = epos->next)
672  if (NULL != epos->val)
673  iter (iter_cls, spos->name, epos->key, epos->val);
674 }
struct ConfigEntry * entries
entries in the section
Definition: configuration.c:72
configuration entry
Definition: configuration.c:40
static char * section
Name of the section.
Definition: gnunet-config.c:33
char * name
name of the section
Definition: configuration.c:77
struct ConfigSection * sections
Configuration sections.
Definition: configuration.c:89
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:45
configuration section
Definition: configuration.c:62
char * key
key for this entry
Definition: configuration.c:50
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:67
char * val
current, committed value
Definition: configuration.c:55
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 1032 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().

1038 {
1039  struct ConfigEntry *e;
1040  unsigned int i;
1041 
1042  if (NULL == (e = find_entry (cfg, section, option)))
1043  return GNUNET_SYSERR;
1044  for (i = 0; NULL != choices[i]; i++)
1045  if (0 == strcasecmp (choices[i], e->val))
1046  break;
1047  if (NULL == choices[i])
1048  {
1050  _ ("Configuration value '%s' for '%s'"
1051  " in section '%s' is not in set of legal choices\n"),
1052  e->val,
1053  option,
1054  section);
1055  return GNUNET_SYSERR;
1056  }
1057  *value = choices[i];
1058  return GNUNET_OK;
1059 }
static struct Experiment * e
configuration entry
Definition: configuration.c:40
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:32
char * val
current, committed value
Definition: configuration.c:55
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 1320 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().

1324 {
1325  static const char *yesno[] = { "YES", "NO", NULL };
1326  const char *val;
1327  int ret;
1328 
1329  ret =
1331  if (ret == GNUNET_SYSERR)
1332  return ret;
1333  if (val == yesno[0])
1334  return GNUNET_YES;
1335  return GNUNET_NO;
1336 }
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:55
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 1063 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().

1068 {
1069  char *enc;
1070  int res;
1071  size_t data_size;
1072 
1073  if (GNUNET_OK !=
1074  (res =
1076  return res;
1077  data_size = (strlen (enc) * 5) / 8;
1078  if (data_size != buf_size)
1079  {
1080  GNUNET_free (enc);
1081  return GNUNET_SYSERR;
1082  }
1083  if (GNUNET_OK !=
1084  GNUNET_STRINGS_string_to_data (enc, strlen (enc), buf, buf_size))
1085  {
1086  GNUNET_free (enc);
1087  return GNUNET_SYSERR;
1088  }
1089  GNUNET_free (enc);
1090  return GNUNET_OK;
1091 }
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
static OpusEncoder * enc
OPUS encoder.
int 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:972
#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 1270 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().

1273 {
1274  char *dup;
1275  size_t i;
1276  size_t len;
1277 
1278  for (i = 0; '\0' != orig[i]; i++)
1279  {
1280  if ('$' != orig[i])
1281  continue;
1282  dup = GNUNET_strdup (orig + i);
1283  dup = expand_dollar (cfg, dup, 0);
1284  GNUNET_assert (NULL != dup); /* make compiler happy */
1285  len = strlen (dup) + 1;
1286  orig = GNUNET_realloc (orig, i + len);
1287  GNUNET_memcpy (orig + i, dup, len);
1288  GNUNET_free (dup);
1289  }
1290  return orig;
1291 }
#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 909 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().

913 {
914  char s[64];
915 
916  GNUNET_snprintf (s, 64, "%llu", number);
918 }
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 867 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_TESTING_configuration_create_(), handle_ego_delete(), handle_ego_rename(), handle_set_default_message(), helper_mst(), identity_cb(), iterate_save_rooms(), next_phase(), process_if(), result_callback(), run(), save_member(), save_member_session(), save_operation(), set_external_ipv4(), set_value(), test_local_ip(), test_upnpc(), update_config(), update_config_sections(), and update_enable_upnpc_option().

871 {
872  struct ConfigSection *sec;
873  struct ConfigEntry *e;
874  char *nv;
875 
876  e = find_entry (cfg, section, option);
877  if (NULL != e)
878  {
879  if (NULL == value)
880  {
881  GNUNET_free (e->val);
882  e->val = NULL;
883  }
884  else
885  {
886  nv = GNUNET_strdup (value);
887  GNUNET_free (e->val);
888  e->val = nv;
889  }
890  return;
891  }
892  sec = find_section (cfg, section);
893  if (sec == NULL)
894  {
895  sec = GNUNET_new (struct ConfigSection);
896  sec->name = GNUNET_strdup (section);
897  sec->next = cfg->sections;
898  cfg->sections = sec;
899  }
900  e = GNUNET_new (struct ConfigEntry);
901  e->key = GNUNET_strdup (option);
902  e->val = GNUNET_strdup (value);
903  e->next = sec->entries;
904  sec->entries = e;
905 }
struct ConfigEntry * entries
entries in the section
Definition: configuration.c:72
static struct Experiment * e
configuration entry
Definition: configuration.c:40
#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:77
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.
Definition: configuration.c:89
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:45
configuration section
Definition: configuration.c:62
char * key
key for this entry
Definition: configuration.c:50
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:67
char * val
current, committed value
Definition: configuration.c:55
#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 1497 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.

1502 {
1503  char *list;
1504  char *pos;
1505  char *end;
1506  char *match;
1507  char old;
1508 
1509  if (GNUNET_OK !=
1511  return GNUNET_NO;
1512  match = escape_name (value);
1513  pos = list;
1514  while (1)
1515  {
1516  while (pos[0] == ' ')
1517  pos++;
1518  if (strlen (pos) == 0)
1519  break;
1520  end = pos + 1;
1521  while ((end[0] != ' ') && (end[0] != '\0'))
1522  {
1523  if (end[0] == '\\')
1524  {
1525  switch (end[1])
1526  {
1527  case '\\':
1528  case ' ':
1529  end++;
1530  break;
1531 
1532  case '\0':
1533  /* illegal, but just keep it */
1534  break;
1535 
1536  default:
1537  /* illegal, but just ignore that there was a '/' */
1538  break;
1539  }
1540  }
1541  end++;
1542  }
1543  old = end[0];
1544  end[0] = '\0';
1545  if (0 == strcmp (pos, match))
1546  {
1547  if (old != '\0')
1548  memmove (pos, &end[1], strlen (&end[1]) + 1);
1549  else
1550  {
1551  if (pos != list)
1552  pos[-1] = '\0';
1553  else
1554  pos[0] = '\0';
1555  }
1557  GNUNET_free (list);
1558  GNUNET_free (match);
1559  return GNUNET_OK;
1560  }
1561  if (old == '\0')
1562  break;
1563  end[0] = old;
1564  pos = end + 1;
1565  }
1566  GNUNET_free (list);
1567  GNUNET_free (match);
1568  return GNUNET_NO;
1569 }
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 1462 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().

1467 {
1468  char *escaped;
1469  char *old;
1470  char *nw;
1471 
1472  if (GNUNET_SYSERR ==
1474  section,
1475  option,
1476  &test_match,
1477  (void *) value))
1478  return GNUNET_NO; /* already exists */
1479  if (GNUNET_OK !=
1481  old = GNUNET_strdup ("");
1482  escaped = escape_name (value);
1483  nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2);
1484  strcpy (nw, old);
1485  if (strlen (old) > 0)
1486  strcat (nw, " ");
1487  strcat (nw, escaped);
1489  GNUNET_free (old);
1490  GNUNET_free (nw);
1491  GNUNET_free (escaped);
1492  return GNUNET_OK;
1493 }
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: