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 220 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 250 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 263 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 753 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().

754 {
756 
759  return ret;
760 }
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_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 1599 of file configuration.c.

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

Referenced by GNUNET_CONFIGURATION_load().

1601 {
1602  if (GNUNET_SYSERR ==
1604  return GNUNET_SYSERR; /* no configuration at all found */
1605  return GNUNET_OK;
1606 }
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 1610 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.

1611 {
1612  const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
1614  const char *xdg = getenv ("XDG_CONFIG_HOME");
1615  char *cfgname = NULL;
1617 
1618  GNUNET_OS_init (dpd);
1619  cfg = GNUNET_CONFIGURATION_create ();
1620  if (NULL != xdg)
1621  GNUNET_asprintf (&cfgname, "%s/%s", xdg, pd->config_file);
1622  else
1623  cfgname = GNUNET_strdup (pd->user_config_file);
1624  if (GNUNET_OK !=
1625  GNUNET_CONFIGURATION_load (cfg, cfgname))
1626  {
1627  GNUNET_OS_init (pd);
1629  GNUNET_free (cfgname);
1630  return NULL;
1631  }
1632  GNUNET_free (cfgname);
1633  GNUNET_OS_init (pd);
1634  return cfg;
1635 }
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:220
#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:184
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:184
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  return GNUNET_SYSERR;
610  }
611  if (((ssize_t) size) !=
613  cfg_buf,
614  size))
615  {
617  "write",
618  fn);
620  (void) GNUNET_DISK_directory_remove (fn);
621  GNUNET_free (fn);
622  GNUNET_free (cfg_buf);
623  cfg->dirty = GNUNET_SYSERR; /* last write failed */
624  return GNUNET_SYSERR;
625  }
628  }
629  GNUNET_free (fn);
630  GNUNET_free (cfg_buf);
631  cfg->dirty = GNUNET_NO; /* last write succeeded */
632  return GNUNET_OK;
633 }
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 850 of file configuration.c.

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

Referenced by auto_config_cb(), and main().

854 {
855  int ret;
856  struct GNUNET_CONFIGURATION_Handle *diff;
857 
858  diff = GNUNET_CONFIGURATION_get_diff (cfg_default, cfg_new);
859  ret = GNUNET_CONFIGURATION_write (diff, filename);
861  return ret;
862 }
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 836 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(), next_phase(), and run().

839 {
840  struct DiffHandle diffHandle;
841 
842  diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
843  diffHandle.cfg_default = cfg_default;
844  GNUNET_CONFIGURATION_iterate (cfg_new, &compare_entries, &diffHandle);
845  return diffHandle.cfgDiff;
846 }
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 637 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_().

640 {
641  for (struct ConfigSection *spos = cfg->sections;
642  NULL != spos;
643  spos = spos->next)
644  for (struct ConfigEntry *epos = spos->entries;
645  NULL != epos;
646  epos = epos->next)
647  if (NULL != epos->val)
648  iter (iter_cls,
649  spos->name,
650  epos->key,
651  epos->val);
652 }
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 677 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().

681 {
682  struct ConfigSection *spos;
683  struct ConfigSection *next;
684 
685  next = cfg->sections;
686  while (next != NULL)
687  {
688  spos = next;
689  next = spos->next;
690  iter (iter_cls, spos->name);
691  }
692 }
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 696 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().

698 {
699  struct ConfigSection *spos;
700  struct ConfigSection *prev;
701  struct ConfigEntry *ent;
702 
703  prev = NULL;
704  spos = cfg->sections;
705  while (NULL != spos)
706  {
707  if (0 == strcasecmp (section, spos->name))
708  {
709  if (NULL == prev)
710  cfg->sections = spos->next;
711  else
712  prev->next = spos->next;
713  while (NULL != (ent = spos->entries))
714  {
715  spos->entries = ent->next;
716  GNUNET_free (ent->key);
717  GNUNET_free (ent->val);
718  GNUNET_free (ent);
719  cfg->dirty = GNUNET_YES;
720  }
721  GNUNET_free (spos->name);
722  GNUNET_free (spos);
723  return;
724  }
725  prev = spos;
726  spos = spos->next;
727  }
728 }
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 921 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().

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

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

966 {
967  struct ConfigEntry *e;
968  int ret;
969 
970  if (NULL == (e = find_entry (cfg, section, option)))
971  return GNUNET_SYSERR;
972  if (NULL == e->val)
973  return GNUNET_SYSERR;
975  if (GNUNET_OK != ret)
977  section,
978  option,
979  _ ("Not a valid relative time specification"));
980  return ret;
981 }
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:184
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 985 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().

990 {
991  struct ConfigEntry *e;
992 
993  if (NULL == (e = find_entry (cfg, section, option)))
994  return GNUNET_SYSERR;
995  if (NULL == e->val)
996  return GNUNET_SYSERR;
998 }
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 1094 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().

1097 {
1098  struct ConfigEntry *e;
1099 
1100  if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1101  return GNUNET_NO;
1102  return GNUNET_YES;
1103 }
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 1012 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().

1017 {
1018  struct ConfigEntry *e;
1019 
1020  if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1021  {
1022  *value = NULL;
1023  return GNUNET_SYSERR;
1024  }
1025  *value = GNUNET_strdup (e->val);
1026  return GNUNET_OK;
1027 }
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 1294 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().

1299 {
1300  char *tmp;
1301 
1302  if (GNUNET_OK !=
1304  {
1305  LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to retrieve filename\n");
1306  *value = NULL;
1307  return GNUNET_SYSERR;
1308  }
1309  tmp = GNUNET_CONFIGURATION_expand_dollar (cfg, tmp);
1311  GNUNET_free (tmp);
1312  if (*value == NULL)
1313  return GNUNET_SYSERR;
1314  return GNUNET_OK;
1315 }
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 1339 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().

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

661 {
662  struct ConfigSection *spos;
663  struct ConfigEntry *epos;
664 
665  spos = cfg->sections;
666  while ((spos != NULL) && (0 != strcasecmp (spos->name, section)))
667  spos = spos->next;
668  if (NULL == spos)
669  return;
670  for (epos = spos->entries; NULL != epos; epos = epos->next)
671  if (NULL != epos->val)
672  iter (iter_cls, spos->name, epos->key, epos->val);
673 }
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 1031 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().

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

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

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

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

912 {
913  char s[64];
914 
915  GNUNET_snprintf (s, 64, "%llu", number);
917 }
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 866 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().

870 {
871  struct ConfigSection *sec;
872  struct ConfigEntry *e;
873  char *nv;
874 
875  e = find_entry (cfg, section, option);
876  if (NULL != e)
877  {
878  if (NULL == value)
879  {
880  GNUNET_free (e->val);
881  e->val = NULL;
882  }
883  else
884  {
885  nv = GNUNET_strdup (value);
886  GNUNET_free (e->val);
887  e->val = nv;
888  }
889  return;
890  }
891  sec = find_section (cfg, section);
892  if (sec == NULL)
893  {
894  sec = GNUNET_new (struct ConfigSection);
895  sec->name = GNUNET_strdup (section);
896  sec->next = cfg->sections;
897  cfg->sections = sec;
898  }
899  e = GNUNET_new (struct ConfigEntry);
900  e->key = GNUNET_strdup (option);
901  e->val = GNUNET_strdup (value);
902  e->next = sec->entries;
903  sec->entries = e;
904 }
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 1496 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.

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

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