GNUnet 0.22.2
Configuration library

Configuration management. More...

Collaboration diagram for Configuration library:

Data Structures

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

Macros

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

Typedefs

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

Functions

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

Detailed Description

Configuration management.

Macro Definition Documentation

◆ GNUNET_CONFIGURATION_CONFIG_OPTIONS

#define GNUNET_CONFIGURATION_CONFIG_OPTIONS (   cs)

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

Parameters
csconfiguration settings to initialize

Definition at line 750 of file gnunet_configuration_lib.h.

Typedef Documentation

◆ GNUNET_CONFIGURATION_Callback

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

Signature of a function to be run with a configuration.

Parameters
clsclosure
cfgthe configuration
Returns
status code

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

◆ GNUNET_CONFIGURATION_SectionIterator

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

Function to iterate over section.

Parameters
clsclosure
sectionname of the section

Definition at line 316 of file gnunet_configuration_lib.h.

Function Documentation

◆ GNUNET_CONFIGURATION_create()

struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create ( const struct GNUNET_OS_ProjectData pd)

Create a new configuration object.

Parameters
pdproject data to use to determine paths
Returns
fresh configuration object

Definition at line 227 of file configuration.c.

228{
230 char *p;
231
233 cfg->pd = pd;
234 /* make certain values from the project data available
235 as PATHS */
238 if (NULL != p)
239 {
241 "PATHS",
242 "DATADIR",
243 p);
244 GNUNET_free (p);
245 }
248 if (NULL != p)
249 {
251 "PATHS",
252 "LIBDIR",
253 p);
254 GNUNET_free (p);
255 }
258 if (NULL != p)
259 {
261 "PATHS",
262 "BINDIR",
263 p);
264 GNUNET_free (p);
265 }
268 if (NULL != p)
269 {
271 "PATHS",
272 "PREFIX",
273 p);
274 GNUNET_free (p);
275 }
278 if (NULL != p)
279 {
281 "PATHS",
282 "LOCALEDIR",
283 p);
284 GNUNET_free (p);
285 }
288 if (NULL != p)
289 {
291 "PATHS",
292 "ICONDIR",
293 p);
294 GNUNET_free (p);
295 }
298 if (NULL != p)
299 {
301 "PATHS",
302 "DOCDIR",
303 p);
304 GNUNET_free (p);
305 }
308 if (NULL != p)
309 {
311 "PATHS",
312 "LIBEXECDIR",
313 p);
314 GNUNET_free (p);
315 }
316 return cfg;
317}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_OS_installation_get_path(const struct GNUNET_OS_ProjectData *pd, enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
@ GNUNET_OS_IPK_ICONDIR
Return the prefix of the path with application icons (share/icons/).
@ GNUNET_OS_IPK_DATADIR
Return the directory where data is installed (share/gnunet/)
@ GNUNET_OS_IPK_DOCDIR
Return the prefix of the path with documentation files, including the license (share/doc/gnunet/).
@ GNUNET_OS_IPK_LOCALEDIR
Return the directory where translations are installed (share/locale/)
@ GNUNET_OS_IPK_LIBDIR
Return the directory where libraries are installed.
@ GNUNET_OS_IPK_PREFIX
Return the "PREFIX" directory given to configure.
@ GNUNET_OS_IPK_BINDIR
Return the directory where the program binaries are installed.
@ GNUNET_OS_IPK_LIBEXECDIR
Return the directory where helper binaries are installed (lib/gnunet/libexec/)
const struct GNUNET_OS_ProjectData * pd
Project data for this configuration object.

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

Referenced by auto_config_cb(), create_unique_cfgs(), gg_load_configuration(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_dup(), GNUNET_CONFIGURATION_get_diff(), GNUNET_CONFIGURATION_parse_and_run(), GNUNET_PROGRAM_conf_and_options(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), GNUNET_TESTING_get_topo_from_string_(), GNUNET_TRANSPORT_TESTING_start_peer(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(), handle_auto_result(), handle_autoconfig_request(), handle_inline(), iter_check_config(), load_member(), load_member_session(), load_member_session_next(), load_operation(), main(), run(), save_member(), save_member_session(), save_operation(), and start_peer_run().

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

1554{
1556
1559 &copy_entry,
1560 ret);
1561 return ret;
1562}
static void copy_entry(void *cls, const char *section, const char *option, const char *value)
Copy a configuration value to the given target configuration.
static int ret
Final status code.
Definition: gnunet-arm.c:93
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(const struct GNUNET_OS_ProjectData *pd)
Create a new configuration object.
void GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over all options in the configuration.

References cfg, copy_entry(), GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_iterate(), GNUNET_CONFIGURATION_Handle::pd, and ret.

Referenced by auto_config_cb(), create_unique_cfgs(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_NAT_autoconfig_start(), handle_autoconfig_request(), run(), and set_cont().

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

322{
323 struct ConfigSection *sec;
324 struct ConfigFile *cf;
325
326 while (NULL != (sec = cfg->sections))
328 while (NULL != (cf = cfg->loaded_files_head))
329 {
334 cf);
335 GNUNET_free (cf);
336 }
339}
void GNUNET_CONFIGURATION_remove_section(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Remove the given section and all options in it.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
char * hint_restrict_section
Was this configuration file parsed via @inline-secret@?
char * source_filename
Source filename.
configuration section
Definition: configuration.c:71
char * name
name of the section
Definition: configuration.c:85
struct ConfigFile * loaded_files_tail
Linked list of loaded files.
struct ConfigSection * sections
Configuration sections.
struct ConfigFile * loaded_files_head
Linked list of loaded files.
char * main_filename
Name of the entry point configuration file.

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

Referenced by auto_config_cb(), clean_node(), conclude_autoconfig_request(), create_unique_cfgs(), do_shutdown(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_parse_and_run(), GNUNET_CONFIGURATION_write_diffs(), GNUNET_NAT_autoconfig_cancel(), GNUNET_PROGRAM_conf_and_options(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), GNUNET_TESTING_get_topo_from_string_(), GNUNET_TRANSPORT_TESTING_start_peer(), GNUNET_TRANSPORT_TESTING_stop_peer(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop(), handle_auto_result(), handle_autoconfig_request(), handle_inline(), load_member(), load_member_session(), load_member_session_next(), load_operation(), main(), next_phase(), save_member(), save_member_session(), save_operation(), shutdown_task(), start_peer_cleanup(), and start_peer_run().

Here is the call graph for this function:
Here is the caller 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
[in,out]cfgconfiguration to update
filenamename of the configuration file, NULL to load defaults
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 2509 of file configuration.c.

2512{
2513 char *baseconfig;
2514 const char *base_config_varname;
2515
2516 if (cfg->load_called)
2517 {
2518 /* FIXME: Make this a GNUNET_assert later */
2519 GNUNET_break (0);
2521 }
2522 cfg->load_called = true;
2523 if (NULL != filename)
2524 {
2527 }
2528
2529 base_config_varname = cfg->pd->base_config_varname;
2530
2531 if ((NULL != base_config_varname)
2532 && (NULL != (baseconfig = getenv (base_config_varname))))
2533 {
2534 baseconfig = GNUNET_strdup (baseconfig);
2535 }
2536 else
2537 {
2538 char *ipath;
2539
2542 if (NULL == ipath)
2543 {
2544 GNUNET_break (0);
2545 return GNUNET_SYSERR;
2546 }
2547 GNUNET_asprintf (&baseconfig,
2548 "%s%s",
2549 ipath,
2550 "config.d");
2551 GNUNET_free (ipath);
2552 }
2553
2554 {
2555 char *dname = GNUNET_STRINGS_filename_expand (baseconfig);
2556
2557 GNUNET_free (baseconfig);
2558
2559 if ((GNUNET_YES ==
2561 GNUNET_YES)) &&
2562 (GNUNET_SYSERR ==
2564 dname)))
2565 {
2567 "Failed to load base configuration from '%s'\n",
2568 filename);
2569 GNUNET_free (dname);
2570 return GNUNET_SYSERR; /* no configuration at all found */
2571 }
2572 GNUNET_free (dname);
2573 }
2574 if ((NULL != filename) &&
2575 (GNUNET_OK !=
2577 filename)))
2578 {
2579 /* specified configuration not found */
2581 "Failed to load configuration from file '%s'\n",
2582 filename);
2583 return GNUNET_SYSERR;
2584 }
2585 if (((GNUNET_YES !=
2587 "PATHS",
2588 "DEFAULTCONFIG"))) &&
2589 (filename != NULL))
2591 "PATHS",
2592 "DEFAULTCONFIG",
2593 filename);
2594 return GNUNET_OK;
2595}
#define LOG(kind,...)
Definition: configuration.c:30
char * getenv()
static char * filename
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Parse a configuration file, add all of the options in the file to the configuration environment.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load_from(struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d)
Load default configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:427
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:504
bool load_called
Was the configuration ever loaded via GNUNET_CONFIGURATION_load?
const char * base_config_varname
Name of an environment variable that can be used to override the location from which default configur...

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

Referenced by auto_config_cb(), create_unique_cfgs(), gg_load_configuration(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_parse_and_run(), GNUNET_PROGRAM_conf_and_options(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), GNUNET_TRANSPORT_TESTING_start_peer(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(), iter_check_config(), main(), and start_peer_run().

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

◆ GNUNET_CONFIGURATION_load_from()

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

Load default configuration.

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

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

Definition at line 2412 of file configuration.c.

2415{
2416 struct CollectFilesContext files_context = {
2417 .files = NULL,
2418 .files_length = 0,
2419 };
2420 enum GNUNET_GenericReturnValue fun_ret;
2421
2422 if (GNUNET_SYSERR ==
2423 GNUNET_DISK_directory_scan (defaults_d,
2425 &files_context))
2426 return GNUNET_SYSERR; /* no configuration at all found */
2427 qsort (files_context.files,
2428 files_context.files_length,
2429 sizeof (char *),
2430 pstrcmp);
2431 for (unsigned int i = 0; i < files_context.files_length; i++)
2432 {
2433 char *ext;
2434 const char *filename = files_context.files[i];
2435
2436 /* Examine file extension */
2437 ext = strrchr (filename, '.');
2438 if ((NULL == ext) || (0 != strcmp (ext, ".conf")))
2439 {
2441 "Skipping file `%s'\n",
2442 filename);
2443 fun_ret = GNUNET_OK;
2444 goto cleanup;
2445 }
2447 filename);
2448 if (fun_ret != GNUNET_OK)
2449 break;
2450 }
2451cleanup:
2452 if (files_context.files_length > 0)
2453 {
2454 for (size_t i = 0; i < files_context.files_length; i++)
2455 GNUNET_free (files_context.files[i]);
2456 GNUNET_array_grow (files_context.files,
2457 files_context.files_length,
2458 0);
2459 }
2460 return fun_ret;
2461}
static int pstrcmp(const void *a, const void *b)
static enum GNUNET_GenericReturnValue collect_files_cb(void *cls, const char *filename)
Function called with a filename.
static void cleanup(void *cls)
Disconnect and shutdown.
Definition: gnunet-did.c:130
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:811
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
Closure to collect_files_cb.
char ** files
Collected files from globbing.
unsigned int files_length
Size of the files array.

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

Referenced by GNUNET_CONFIGURATION_load().

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

◆ GNUNET_CONFIGURATION_default_filename()

char * GNUNET_CONFIGURATION_default_filename ( const struct GNUNET_OS_ProjectData pd)

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

Parameters
pdproject data to use to determine paths
Returns
NULL if no default configuration file can be located, a newly allocated string otherwise

Definition at line 2465 of file configuration.c.

2467{
2468 char *cfg_fn;
2469 const char *xdg = getenv ("XDG_CONFIG_HOME");
2470
2471 if (NULL != xdg)
2472 GNUNET_asprintf (&cfg_fn,
2473 "%s%s%s",
2474 xdg,
2476 pd->config_file);
2477 else
2478 cfg_fn = GNUNET_strdup (pd->user_config_file);
2479
2480 if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2481 return cfg_fn;
2482 GNUNET_free (cfg_fn);
2483
2484 /* Fall back to /etc/ for the default configuration.
2485 Should be okay to use forward slashes here. */
2486
2487 GNUNET_asprintf (&cfg_fn,
2488 "/etc/%s",
2489 pd->config_file);
2490 if (GNUNET_OK ==
2492 return cfg_fn;
2493 GNUNET_free (cfg_fn);
2494
2495 GNUNET_asprintf (&cfg_fn,
2496 "/etc/%s/%s",
2497 pd->project_dirname,
2498 pd->config_file);
2499 if (GNUNET_OK ==
2501 return cfg_fn;
2502
2503 GNUNET_free (cfg_fn);
2504 return NULL;
2505}
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test_read(const char *fil)
Check that fil corresponds to a filename and the file has read permissions.
Definition: disk.c:513
#define DIR_SEPARATOR_STR
Definition: platform.h:166
const char * project_dirname
Name of the project that is used in the "libexec" prefix, For example, "gnunet".
const char * user_config_file
Configuration file name to use (if $XDG_CONFIG_HOME is not set).
const char * config_file
Configuration file name (in $XDG_CONFIG_HOME) to use.

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

Referenced by GNUNET_PROGRAM_run2(), and main().

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

◆ GNUNET_CONFIGURATION_parse()

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

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

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

Definition at line 989 of file configuration.c.

991{
992 uint64_t fs64;
993 size_t fs;
994 char *fn;
995 char *mem;
996 int dirty;
998 ssize_t sret;
999
1001 LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to parse config file `%s'\n", fn);
1002 if (NULL == fn)
1003 return GNUNET_SYSERR;
1004
1005
1006 /* Check for cycles */
1007 {
1008 unsigned int lvl = cfg->current_nest_level;
1009 struct ConfigFile *cf = cfg->loaded_files_tail;
1010 struct ConfigFile *parent = NULL;
1011
1012
1013 for (; NULL != cf; parent = cf, cf = cf->prev)
1014 {
1015 /* Check parents based on level, skipping children of siblings. */
1016 if (cf->level >= lvl)
1017 continue;
1018 lvl = cf->level;
1019 if ( (NULL == cf->source_filename) || (NULL == filename))
1020 continue;
1021 if (0 == strcmp (cf->source_filename, filename))
1022 {
1023 if (NULL == parent)
1024 {
1026 "Forbidden direct cyclic configuration import (%s -> %s)\n",
1027 cf->source_filename,
1028 filename);
1029 }
1030 else
1032 "Forbidden indirect cyclic configuration import (%s -> ... -> %s -> %s)\n",
1033 cf->source_filename,
1034 parent->source_filename,
1035 filename);
1036 GNUNET_free (fn);
1037 return GNUNET_SYSERR;
1038 }
1039 }
1040
1041 }
1042
1043 /* Keep track of loaded files.*/
1044 {
1045 struct ConfigFile *cf = GNUNET_new (struct ConfigFile);
1046
1048 cf->source_filename = GNUNET_strdup (filename ? filename : "<input>");
1051 cf);
1052 }
1053
1054 dirty = cfg->dirty; /* back up value! */
1055 if (GNUNET_SYSERR ==
1057 &fs64,
1058 GNUNET_YES,
1059 GNUNET_YES))
1060 {
1062 "Error while determining the file size of `%s'\n",
1063 fn);
1064 GNUNET_free (fn);
1065 return GNUNET_SYSERR;
1066 }
1067 if (fs64 > SIZE_MAX)
1068 {
1069 GNUNET_break (0); /* File size is more than the heap size */
1070 GNUNET_free (fn);
1071 return GNUNET_SYSERR;
1072 }
1073 fs = fs64;
1074 mem = GNUNET_malloc (fs);
1075 sret = GNUNET_DISK_fn_read (fn, mem, fs);
1076 if ((sret < 0) || (fs != (size_t) sret))
1077 {
1079 "Error while reading file `%s'\n",
1080 fn);
1081 GNUNET_free (fn);
1082 GNUNET_free (mem);
1083 return GNUNET_SYSERR;
1084 }
1086 "Deserializing contents of file `%s'\n",
1087 fn);
1089 mem,
1090 fs,
1091 fn);
1092 if (GNUNET_SYSERR == ret)
1093 {
1095 _ ("Failed to parse configuration file `%s'\n"),
1096 fn);
1097 }
1098 GNUNET_free (fn);
1099 GNUNET_free (mem);
1100 /* restore dirty flag - anything we set in the meantime
1101 * came from disk */
1102 cfg->dirty = dirty;
1103 return ret;
1104}
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:35
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *source_filename)
De-serializes configuration.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition: disk.c:222
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:660
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_malloc(size)
Wrapper around malloc.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
#define SIZE_MAX
Definition: platform.h:208
struct ConfigFile * prev
unsigned int level
Level in the tree of loaded config files.
unsigned int current_nest_level
Current nesting level of file loading.
enum GNUNET_GenericReturnValue dirty
Modification indication since last save GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on err...

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

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

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

1152{
1153 char *mem;
1154 char *cbuf;
1155 char *val;
1156 char *pos;
1157 size_t m_size;
1158 size_t c_size;
1159
1160 /* Pass1 : calculate the buffer size required */
1161 m_size = 0;
1162 for (struct ConfigSection *sec = cfg->sections;
1163 NULL != sec;
1164 sec = sec->next)
1165 {
1166 if (sec->inaccessible)
1167 continue;
1168 /* For each section we need to add 3 characters: {'[',']','\n'} */
1169 m_size += strlen (sec->name) + 3;
1170 for (struct ConfigEntry *ent = sec->entries;
1171 NULL != ent;
1172 ent = ent->next)
1173 {
1174 if (do_skip (sec->name,
1175 ent->key))
1176 continue;
1177 if (NULL != ent->val)
1178 {
1179 /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */
1180 pos = ent->val;
1181 while (NULL != (pos = strstr (pos, "\n")))
1182 {
1183 m_size++;
1184 pos++;
1185 }
1186 /* For each key = value pair we need to add 4 characters (2
1187 spaces and 1 equal-to character and 1 new line) */
1188 m_size += strlen (ent->key) + strlen (ent->val) + 4;
1189 }
1190 }
1191 /* A new line after section end */
1192 m_size++;
1193 }
1194
1195 /* Pass2: Allocate memory and write the configuration to it */
1196 mem = GNUNET_malloc (m_size);
1197 c_size = 0;
1198 *size = c_size;
1199 for (struct ConfigSection *sec = cfg->sections;
1200 NULL != sec;
1201 sec = sec->next)
1202 {
1203 int len;
1204
1205 len = GNUNET_asprintf (&cbuf,
1206 "[%s]\n",
1207 sec->name);
1208 GNUNET_assert (0 < len);
1209 GNUNET_memcpy (mem + c_size,
1210 cbuf,
1211 len);
1212 c_size += len;
1213 GNUNET_free (cbuf);
1214 for (struct ConfigEntry *ent = sec->entries;
1215 NULL != ent;
1216 ent = ent->next)
1217 {
1218 if (do_skip (sec->name,
1219 ent->key))
1220 continue;
1221 if (NULL != ent->val)
1222 {
1223 val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1224 strcpy (val, ent->val);
1225 while (NULL != (pos = strstr (val, "\n")))
1226 {
1227 memmove (&pos[2], &pos[1], strlen (&pos[1]));
1228 pos[0] = '\\';
1229 pos[1] = 'n';
1230 }
1231 len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
1232 GNUNET_free (val);
1233 GNUNET_memcpy (mem + c_size, cbuf, len);
1234 c_size += len;
1235 GNUNET_free (cbuf);
1236 }
1237 }
1238 GNUNET_memcpy (mem + c_size, "\n", 1);
1239 c_size++;
1240 }
1241 GNUNET_assert (c_size == m_size);
1242 *size = c_size;
1243 return mem;
1244}
static bool do_skip(const char *sec, const char *key)
Should we skip this configuration entry when serializing?
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static unsigned int size
Size of the "table".
Definition: peer.c:68
configuration entry
Definition: configuration.c:39
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:43
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:75

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

Referenced by conclude_autoconfig_request(), GNUNET_CONFIGURATION_write(), and GNUNET_NAT_AUTO_autoconfig_start().

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

◆ GNUNET_CONFIGURATION_serialize_diagnostics()

char * GNUNET_CONFIGURATION_serialize_diagnostics ( const struct GNUNET_CONFIGURATION_Handle cfg)

Serializes the given configuration with diagnostics information.

Diagnostics information will only be available if diagnostics have been enabled before parsing.

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

Definition at line 1248 of file configuration.c.

1250{
1251 struct GNUNET_Buffer buf = { 0 };
1252
1254 "#\n# Configuration file diagnostics\n#\n");
1256 "# Entry point: %s\n",
1258 "<none>");
1260 "#\n# Files Loaded:\n");
1261
1262 for (struct ConfigFile *cfil = cfg->loaded_files_head;
1263 NULL != cfil;
1264 cfil = cfil->next)
1265 {
1267 "# ");
1268 for (unsigned int i = 0; i < cfil->level; i++)
1270 "+");
1271 if (0 != cfil->level)
1273 " ");
1274
1276 "%s",
1277 cfil->source_filename);
1278
1279 if (NULL != cfil->hint_restrict_section)
1281 " (%s secret section %s)",
1282 cfil->hint_inaccessible
1283 ? "inaccessible"
1284 : "loaded",
1285 cfil->hint_restrict_section);
1286
1288 "\n");
1289 }
1290
1292 "#\n\n");
1293
1294 for (struct ConfigSection *sec = cfg->sections;
1295 NULL != sec;
1296 sec = sec->next)
1297 {
1298 if (sec->hint_secret_filename)
1300 "# secret section from %s\n# secret file stat %s\n",
1301 sec->hint_secret_filename,
1302 sec->hint_secret_stat);
1303 if (sec->hint_inlined_from_filename)
1304 {
1306 "# inlined from %s:%u\n",
1307 sec->hint_inlined_from_filename,
1308 sec->hint_inlined_from_line);
1309 }
1311 "[%s]\n\n",
1312 sec->name);
1313 if (sec->inaccessible)
1314 {
1316 "# <section contents inaccessible>\n\n\n");
1317 continue;
1318 }
1319 for (struct ConfigEntry *ent = sec->entries;
1320 NULL != ent;
1321 ent = ent->next)
1322 {
1323 if (do_skip (sec->name,
1324 ent->key))
1325 continue;
1326 if (NULL != ent->val)
1327 {
1328 char *pos;
1329 char *val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1330 strcpy (val, ent->val);
1331 while (NULL != (pos = strstr (val, "\n")))
1332 {
1333 memmove (&pos[2], &pos[1], strlen (&pos[1]));
1334 pos[0] = '\\';
1335 pos[1] = 'n';
1336 }
1337 if (NULL != ent->hint_filename)
1338 {
1340 "# %s:%u\n",
1341 ent->hint_filename,
1342 ent->hint_lineno);
1343 }
1345 "%s = %s\n",
1346 ent->key,
1347 val);
1348 GNUNET_free (val);
1349 }
1350 GNUNET_buffer_write_str (&buf, "\n");
1351 }
1352 GNUNET_buffer_write_str (&buf, "\n");
1353 }
1354 return GNUNET_buffer_reap_str (&buf);
1355}
char * GNUNET_buffer_reap_str(struct GNUNET_Buffer *buf)
Clear the buffer and return the string it contained.
Definition: buffer.c:123
void GNUNET_buffer_write_fstr(struct GNUNET_Buffer *buf, const char *fmt,...) __attribute__((format(printf
Write a 0-terminated formatted string to a buffer, excluding the 0-terminator.
void GNUNET_buffer_write_str(struct GNUNET_Buffer *buf, const char *str)
Write a 0-terminated string to a buffer, excluding the 0-terminator.
Definition: buffer.c:103
struct ConfigFile * next
Dynamically growing buffer.

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

Referenced by GNUNET_CONFIGURATION_config_tool_run().

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

◆ GNUNET_CONFIGURATION_deserialize()

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

De-serializes configuration.

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

Definition at line 724 of file configuration.c.

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

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

Referenced by GNUNET_CONFIGURATION_parse(), GNUNET_TESTING_get_topo_from_string_(), handle_auto_result(), handle_autoconfig_request(), and main().

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

1362{
1363 char *fn;
1364 char *cfg_buf;
1365 size_t size;
1366
1368 if (fn == NULL)
1369 return GNUNET_SYSERR;
1371 {
1372 GNUNET_free (fn);
1373 return GNUNET_SYSERR;
1374 }
1376 &size);
1377 {
1378 struct GNUNET_DISK_FileHandle *h;
1379
1388 if (NULL == h)
1389 {
1390 GNUNET_free (fn);
1391 GNUNET_free (cfg_buf);
1392 return GNUNET_SYSERR;
1393 }
1394 if (((ssize_t) size) !=
1396 cfg_buf,
1397 size))
1398 {
1400 "write",
1401 fn);
1403 (void) GNUNET_DISK_directory_remove (fn);
1404 GNUNET_free (fn);
1405 GNUNET_free (cfg_buf);
1406 cfg->dirty = GNUNET_SYSERR; /* last write failed */
1407 return GNUNET_SYSERR;
1408 }
1411 }
1412 GNUNET_free (fn);
1413 GNUNET_free (cfg_buf);
1414 cfg->dirty = GNUNET_NO; /* last write succeeded */
1415 return GNUNET_OK;
1416}
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:98
char * GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
Serializes the given configuration.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1215
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:682
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1065
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1289
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:606
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_OPEN_TRUNCATE
Truncate file if it exists.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_GROUP_READ
Group can read.
@ GNUNET_DISK_PERM_GROUP_WRITE
Group can write.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
Handle used to access files (and pipes).

References cfg, GNUNET_CONFIGURATION_Handle::dirty, filename, 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 create_unique_cfgs(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_write_diffs(), handle_delete_message(), handle_rename_message(), save_member(), save_member_session(), save_operation(), set_cont(), and start_peer_run().

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

1617{
1618 int ret;
1619 struct GNUNET_CONFIGURATION_Handle *diff;
1620
1621 diff = GNUNET_CONFIGURATION_get_diff (cfg_default, cfg_new);
1624 return ret;
1625}
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_get_diff(const struct GNUNET_CONFIGURATION_Handle *cfg_default, const struct GNUNET_CONFIGURATION_Handle *cfg_new)
Compute configuration with only entries that have been changed.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.

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

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

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

1599{
1600 struct DiffHandle diffHandle;
1601
1602 GNUNET_break (cfg_default->pd == cfg_new->pd);
1603 diffHandle.cfgDiff = GNUNET_CONFIGURATION_create (cfg_new->pd);
1604 diffHandle.cfg_default = cfg_default;
1607 &diffHandle);
1608 return diffHandle.cfgDiff;
1609}
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

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

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

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

◆ GNUNET_CONFIGURATION_is_dirty()

enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_is_dirty ( const struct GNUNET_CONFIGURATION_Handle cfg)

Test if there are configuration options that were changed since the last save.

Parameters
cfgconfiguration to inspect
Returns
GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error (i.e. last save failed)

Definition at line 1108 of file configuration.c.

1109{
1110 return cfg->dirty;
1111}

References cfg, and GNUNET_CONFIGURATION_Handle::dirty.

Referenced by auto_config_cb().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_parse_and_run()

enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse_and_run ( const struct GNUNET_OS_ProjectData pd,
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
pdproject data to use to determine paths
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 343 of file configuration.c.

347{
350
352 if (GNUNET_OK !=
354 filename))
355 {
356 GNUNET_break (0);
358 return GNUNET_SYSERR;
359 }
360 ret = cb (cb_cls,
361 cfg);
363 return ret;
364}
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.

References cfg, filename, GNUNET_break, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_load(), GNUNET_OK, GNUNET_SYSERR, GNUNET_CONFIGURATION_Handle::pd, and ret.

Referenced by GNUNET_DISK_purge_cfg_dir().

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

◆ GNUNET_CONFIGURATION_enable_diagnostics()

void GNUNET_CONFIGURATION_enable_diagnostics ( struct GNUNET_CONFIGURATION_Handle cfg)

Enable extra diagnostics.

Will produce more log output and allocate more memory.

Parameters
cfgconfiguration handle

Definition at line 219 of file configuration.c.

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

References cfg, and GNUNET_CONFIGURATION_Handle::diagnostics.

Referenced by GNUNET_CONFIGURATION_config_tool_run().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_project_data()

const struct GNUNET_OS_ProjectData * GNUNET_CONFIGURATION_get_project_data ( const struct GNUNET_CONFIGURATION_Handle cfg)

Return the project data associated with this configuration.

Parameters
cfga configuration
Returns
associated project data, never NULL

Definition at line 2879 of file configuration.c.

2881{
2882 return cfg->pd;
2883}

References cfg, and GNUNET_CONFIGURATION_Handle::pd.

Referenced by GNUNET_BLOCK_context_create(), and GNUNET_DATACACHE_create().

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

1424{
1425 for (struct ConfigSection *spos = cfg->sections;
1426 NULL != spos;
1427 spos = spos->next)
1428 for (struct ConfigEntry *epos = spos->entries;
1429 NULL != epos;
1430 epos = epos->next)
1431 if (NULL != epos->val)
1432 iter (iter_cls,
1433 spos->name,
1434 epos->key,
1435 epos->val);
1436}

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

Referenced by get_cont(), GNUNET_CONFIGURATION_dup(), GNUNET_CONFIGURATION_get_diff(), and GNUNET_TESTBED_configuration_create().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_iterate_sections()

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

Iterate over all sections in the configuration.

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

Definition at line 1469 of file configuration.c.

1473{
1474 struct ConfigSection *spos;
1475 struct ConfigSection *next;
1476
1477 next = cfg->sections;
1478 while (next != NULL)
1479 {
1480 spos = next;
1481 next = spos->next;
1482 iter (iter_cls, spos->name);
1483 }
1484}

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

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

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_remove_section()

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

Remove the given section and all options in it.

Parameters
cfgconfiguration to inspect
sectionname of the section to remove

Definition at line 1488 of file configuration.c.

1490{
1491 struct ConfigSection *spos;
1492 struct ConfigSection *prev;
1493 struct ConfigEntry *ent;
1494
1495 prev = NULL;
1496 spos = cfg->sections;
1497 while (NULL != spos)
1498 {
1499 if (0 == strcasecmp (section, spos->name))
1500 {
1501 if (NULL == prev)
1502 cfg->sections = spos->next;
1503 else
1504 prev->next = spos->next;
1505 while (NULL != (ent = spos->entries))
1506 {
1507 spos->entries = ent->next;
1508 GNUNET_free (ent->key);
1509 GNUNET_free (ent->val);
1511 GNUNET_free (ent);
1512 cfg->dirty = GNUNET_YES;
1513 }
1514 GNUNET_free (spos->name);
1518 GNUNET_free (spos);
1519 return;
1520 }
1521 prev = spos;
1522 spos = spos->next;
1523 }
1524}
char * hint_filename
Diagnostics information for the filename.
Definition: configuration.c:58
char * key
key for this entry
Definition: configuration.c:48
char * val
current, committed value
Definition: configuration.c:53
char * hint_inlined_from_filename
For secret sections: Where was this inlined from?
struct ConfigEntry * entries
entries in the section
Definition: configuration.c:80
char * hint_secret_filename
Diagnostics hint for the secret file.
Definition: configuration.c:98
char * hint_secret_stat
Extra information regarding permissions of the secret file.

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

Referenced by GNUNET_CONFIGURATION_destroy().

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_NO if option is not set GNUNET_SYSERR on error (value is malformed)

Definition at line 1691 of file configuration.c.

1696{
1697 struct ConfigEntry *e;
1698 char dummy[2];
1699
1700 if (NULL == (e = find_entry (cfg,
1701 section,
1702 option)))
1703 return GNUNET_NO;
1704 if (NULL == e->val)
1705 return GNUNET_NO;
1706 if (1 != sscanf (e->val,
1707 "%llu%1s",
1708 number,
1709 dummy))
1710 return GNUNET_SYSERR;
1711 return GNUNET_OK;
1712}
static struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
uint32_t number

References cfg, dummy, find_entry(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, number, and ConfigEntry::val.

Referenced by create_service(), create_subnets(), DHTU_ip_init(), GCD_init(), GCO_init(), GDS_NEIGHBOURS_init(), get_server_addresses(), 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_TESTING_get_topo_from_string_(), GNUNET_TRANSPORT_communicator_connect(), GSF_cadet_start_server(), GSF_pending_request_init_(), libgnunet_plugin_block_revocation_init(), libgnunet_plugin_datastore_heap_init(), load_member_session(), load_operation(), run(), setup_exit_helper_args(), test_service_configuration(), test_stun(), and update_config().

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

◆ GNUNET_CONFIGURATION_get_value_float()

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

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

Parameters
cfgconfiguration to inspect
sectionsection of interest
optionoption of interest
numberwhere to store the floating value of the option
Returns
GNUNET_OK on success, GNUNET_NO if option is not set GNUNET_SYSERR on error (value is malformed)

Definition at line 1716 of file configuration.c.

1721{
1722 struct ConfigEntry *e;
1723 char dummy[2];
1724
1725 if (NULL == (e = find_entry (cfg,
1726 section,
1727 option)))
1728 return GNUNET_NO;
1729 if (NULL == e->val)
1730 return GNUNET_NO;
1731 if (1 != sscanf (e->val,
1732 "%f%1s",
1733 number,
1734 dummy))
1735 return GNUNET_SYSERR;
1736 return GNUNET_OK;
1737}

References cfg, dummy, find_entry(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, number, and ConfigEntry::val.

Referenced by GNUNET_RPS_connect().

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_NO if option is not set GNUNET_SYSERR on error (value is malformed)

Definition at line 1741 of file configuration.c.

1746{
1747 struct ConfigEntry *e;
1748 int ret;
1749
1750 if (NULL == (e = find_entry (cfg,
1751 section,
1752 option)))
1753 return GNUNET_NO;
1754 if (NULL == e->val)
1755 return GNUNET_NO;
1757 time);
1758 if (GNUNET_OK != ret)
1760 section,
1761 option,
1762 _ ("Not a valid relative time specification"));
1763 return ret;
1764}
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_time_to_relative(const char *fancy_time, struct GNUNET_TIME_Relative *rtime)
Convert a given fancy human-readable time to our internal representation.
Definition: strings.c:259

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

Referenced by GCD_init(), GNUNET_REVOCATION_revoke(), GNUNET_SPEEDUP_start_(), GSF_push_init_(), libgnunet_plugin_block_revocation_init(), RECLAIM_TICKETS_init(), REST_openid_init(), run(), and token_endpoint().

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_NO if option is not set GNUNET_SYSERR on error (value is malformed)

Definition at line 1768 of file configuration.c.

1773{
1774 struct ConfigEntry *e;
1775
1776 if (NULL == (e = find_entry (cfg,
1777 section,
1778 option)))
1779 return GNUNET_NO;
1780 if (NULL == e->val)
1781 return GNUNET_NO;
1783 size);
1784}
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_size_to_bytes(const char *fancy_size, unsigned long long *size)
Convert a given fancy human-readable size to bytes.
Definition: strings.c:235

References cfg, find_entry(), GNUNET_NO, GNUNET_STRINGS_fancy_size_to_bytes(), size, and ConfigEntry::val.

Referenced by GNUNET_DATACACHE_create(), and run().

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

1894{
1895 struct ConfigEntry *e;
1896
1897 if ( (NULL == (e = find_entry (cfg,
1898 section,
1899 option))) ||
1900 (NULL == e->val) )
1901 return GNUNET_NO;
1902 return GNUNET_YES;
1903}

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

Referenced by check_config(), get_server_addresses(), GNUNET_CLIENT_connect(), GNUNET_CLIENT_test(), GNUNET_CONFIGURATION_load(), GNUNET_HOSTLIST_server_start(), GNUNET_PROGRAM_run2(), GNUNET_SOCKS_check_service(), process_acl4(), process_acl6(), run(), setup_service(), start_arm_service(), test_service_configuration(), and update_config_sections().

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_NO if option is not set GNUNET_SYSERR on error (value is malformed)
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 1798 of file configuration.c.

1803{
1804 struct ConfigEntry *e;
1805
1806 if ( (NULL == (e = find_entry (cfg,
1807 section,
1808 option))) ||
1809 (NULL == e->val) )
1810 {
1811 *value = NULL;
1812 return GNUNET_NO;
1813 }
1814 *value = GNUNET_strdup (e->val);
1815 return GNUNET_OK;
1816}

References cfg, find_entry(), GNUNET_NO, GNUNET_OK, GNUNET_strdup, ConfigEntry::val, and value.

Referenced by advertise_dns_exit(), check_authorization(), check_config(), client_connect_cb(), communicator_start(), DHTU_ip_init(), expand_dollar(), get_bootstrap_server(), get_server_addresses(), gg_load_configuration(), GNUNET_CLIENT_connect(), GNUNET_CLIENT_test(), GNUNET_CONFIGURATION_append_value_filename(), GNUNET_CONFIGURATION_config_tool_run(), 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_cfg2(), GNUNET_SOCKS_do_connect(), GNUNET_TESTING_get_topo_from_string_(), handle_ego_delete(), handle_ego_rename(), handle_register(), handle_uri(), identity_continuation(), load_member_session(), load_member_session_next(), login_redirect(), mq_init(), process_acl4(), process_acl6(), read_service_conf(), run(), setup_exit_helper_args(), setup_service(), sock_read(), start_arm_service(), start_peer_run(), start_process(), test_icmp_client(), test_icmp_server(), test_service_configuration(), token_endpoint(), and update_config_sections().

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_NO if option is not set GNUNET_SYSERR on error (value is malformed)

Definition at line 2102 of file configuration.c.

2107{
2108 char *tmp;
2110
2112 section,
2113 option,
2114 &tmp);
2115 if (GNUNET_OK != ret)
2116 {
2118 "Failed to retrieve filename\n");
2119 *value = NULL;
2120 return ret;
2121 }
2123 tmp);
2125 GNUNET_free (tmp);
2126 if (*value == NULL)
2127 return GNUNET_SYSERR;
2128 return GNUNET_OK;
2129}
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.
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...

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

Referenced by create_service(), database_connect(), database_setup(), get_oidc_dir_path(), get_pid_file_name(), get_serialization_file_name(), get_serialization_file_name_in_dir(), get_server_addresses(), get_update_information_directory(), get_user_name(), GNUNET_CLIENT_test(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CRYPTO_eddsa_key_create_from_configuration(), GNUNET_HOSTLIST_client_start(), GNUNET_PQ_connect_with_cfg2(), GNUNET_TIME_absolute_get_monotonic(), load(), load_hostlist_file(), main_init(), new_sub(), print_filename_option(), purge_cfg_dir(), read_index_list(), run(), save(), save_hostlist_file(), setup_service(), start_arm_service(), start_peer_run(), test_service_configuration(), try_unixpath(), write_index_list(), and write_proof().

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

2167{
2168 char *list;
2169 char *pos;
2170 char *end;
2171 char old;
2172 int ret;
2173
2174 if (GNUNET_OK !=
2176 section,
2177 option,
2178 &list))
2179 return 0;
2180 GNUNET_assert (list != NULL);
2181 ret = 0;
2182 pos = list;
2183 while (1)
2184 {
2185 while (pos[0] == ' ')
2186 pos++;
2187 if (strlen (pos) == 0)
2188 break;
2189 end = pos + 1;
2190 while ((end[0] != ' ') && (end[0] != '\0'))
2191 {
2192 if (end[0] == '\\')
2193 {
2194 switch (end[1])
2195 {
2196 case '\\':
2197 case ' ':
2198 memmove (end, &end[1], strlen (&end[1]) + 1);
2199
2200 case '\0':
2201 /* illegal, but just keep it */
2202 break;
2203
2204 default:
2205 /* illegal, but just ignore that there was a '/' */
2206 break;
2207 }
2208 }
2209 end++;
2210 }
2211 old = end[0];
2212 end[0] = '\0';
2213 if (strlen (pos) > 0)
2214 {
2215 ret++;
2216 if ( (NULL != cb) &&
2217 (GNUNET_OK != cb (cb_cls,
2218 pos)))
2219 {
2221 break;
2222 }
2223 }
2224 if (old == '\0')
2225 break;
2226 pos = end + 1;
2227 }
2228 GNUNET_free (list);
2229 return ret;
2230}
static int list
Set if we should print a list of currently running services.
Definition: gnunet-arm.c:68

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

Referenced by GNUNET_CONFIGURATION_append_value_filename().

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

1445{
1446 struct ConfigSection *spos;
1447 struct ConfigEntry *epos;
1448
1449 spos = cfg->sections;
1450 while ((spos != NULL) && (0 != strcasecmp (spos->name, section)))
1451 spos = spos->next;
1452 if (NULL == spos)
1453 return;
1454 if (spos->inaccessible)
1455 {
1457 "Section '%s' is marked as inaccessible, because the configuration "
1458 " file that contains the section can't be read.\n",
1459 section);
1460 return;
1461 }
1462 for (epos = spos->entries; NULL != epos; epos = epos->next)
1463 if (NULL != epos->val)
1464 iter (iter_cls, spos->name, epos->key, epos->val);
1465}
bool inaccessible
Is the configuration section marked as inaccessible?
Definition: configuration.c:93

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

Referenced by authorize_endpoint(), auto_config_cb(), get_cont(), GNUNET_CONFIGURATION_config_tool_run(), and run().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_value_choice()

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

Get a configuration value that should be in a set of predefined strings.

Parameters
cfgconfiguration to inspect
sectionsection of interest
optionoption of interest
choicesNULL-terminated list of legal values
valuewill be set to an entry in the legal list, or NULL if option is not specified and no default given
Returns
GNUNET_OK on success, GNUNET_NO if option is not set GNUNET_SYSERR on error (value not in choices)

Definition at line 1820 of file configuration.c.

1826{
1827 struct ConfigEntry *e;
1828 unsigned int i;
1829
1830 if (NULL == (e = find_entry (cfg,
1831 section,
1832 option)))
1833 return GNUNET_NO;
1834 for (i = 0; NULL != choices[i]; i++)
1835 if (0 == strcasecmp (choices[i], e->val))
1836 break;
1837 if (NULL == choices[i])
1838 {
1840 _ ("Configuration value '%s' for '%s'"
1841 " in section '%s' is not in set of legal choices\n"),
1842 e->val,
1843 option,
1844 section);
1845 return GNUNET_SYSERR;
1846 }
1847 *value = choices[i];
1848 return GNUNET_OK;
1849}

References _, cfg, warningfilter::choices, find_entry(), GNUNET_ERROR_TYPE_ERROR, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, LOG, ConfigEntry::val, and value.

Referenced by GNUNET_CONFIGURATION_get_value_yesno(), and start_process().

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_OK if option is set to "YES" GNUNET_NO if option is not set or "NO" GNUNET_SYSERR on error (neither YES nor NO)

Definition at line 2133 of file configuration.c.

2137{
2138 static const char *yesno[] = {
2139 "YES",
2140 "NO",
2141 NULL
2142 };
2143 const char *val;
2145
2146 ret =
2148 section,
2149 option,
2150 yesno,
2151 &val);
2152 if (GNUNET_OK != ret)
2153 return ret;
2154 if (val == yesno[0])
2155 return GNUNET_YES;
2156 return GNUNET_NO;
2157}
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.

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

Referenced by advertise_dns_exit(), create_listen_socket(), create_service(), database_connect(), GDS_NEIGHBOURS_init(), get_server_addresses(), gg_load_configuration(), GNS_resolver_init(), GNUNET_DATACACHE_create(), GNUNET_STATISTICS_create(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(), GSF_pending_request_init_(), GSF_push_init_(), libgnunet_plugin_datacache_sqlite_init(), load_underlay(), main_init(), parse_ip_options(), run(), setup_service(), sign_ephemeral_key(), start_arm_service(), start_process(), test_icmp_client(), test_icmp_server(), test_master(), udp_address_to_sockaddr(), and update_config().

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

1858{
1859 char *enc;
1860 int res;
1861 size_t data_size;
1862
1863 if (GNUNET_OK !=
1864 (res =
1866 section,
1867 option,
1868 &enc)))
1869 return res;
1870 data_size = (strlen (enc) * 5) / 8;
1871 if (data_size != buf_size)
1872 {
1873 GNUNET_free (enc);
1874 return GNUNET_SYSERR;
1875 }
1876 if (GNUNET_OK !=
1878 strlen (enc),
1879 buf,
1880 buf_size))
1881 {
1882 GNUNET_free (enc);
1883 return GNUNET_SYSERR;
1884 }
1885 GNUNET_free (enc);
1886 return GNUNET_OK;
1887}
static OpusEncoder * enc
OPUS encoder.
static char * res
Currently read line or NULL on EOF.
static size_t data_size
Number of bytes in data.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:812

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

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

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

◆ GNUNET_CONFIGURATION_expand_dollar()

char * GNUNET_CONFIGURATION_expand_dollar ( const struct GNUNET_CONFIGURATION_Handle cfg,
char *  orig 
)

Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" where either in the "PATHS" section or the environment "FOO" is set to "DIRECTORY".

We also support default expansion, i.e. ${VARIABLE:-default} will expand to $VARIABLE if VARIABLE is set in PATHS or the environment, and otherwise to "default". Note that "default" itself can also be a $-expression, thus "${VAR1:-{$VAR2}}" will expand to VAR1 and if that is not defined to VAR2.

Parameters
cfgconfiguration to use for path expansion
origstring to $-expand (will be freed!) Note that multiple $-expressions can be present in this string. They will all be $-expanded.
Returns
$-expanded string

Definition at line 2077 of file configuration.c.

2080{
2081 char *dup;
2082 size_t i;
2083 size_t len;
2084
2085 for (i = 0; '\0' != orig[i]; i++)
2086 {
2087 if ('$' != orig[i])
2088 continue;
2089 dup = GNUNET_strdup (orig + i);
2090 dup = expand_dollar (cfg, dup, 0);
2091 GNUNET_assert (NULL != dup); /* make compiler happy */
2092 len = strlen (dup) + 1;
2093 orig = GNUNET_realloc (orig, i + len);
2094 GNUNET_memcpy (orig + i, dup, len);
2095 GNUNET_free (dup);
2096 }
2097 return orig;
2098}
static char * expand_dollar(const struct GNUNET_CONFIGURATION_Handle *cfg, char *orig, unsigned int depth)
Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" where either in the "PATHS" section or...
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.

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

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

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

◆ GNUNET_CONFIGURATION_set_value_number()

void GNUNET_CONFIGURATION_set_value_number ( struct GNUNET_CONFIGURATION_Handle cfg,
const char *  section,
const char *  option,
unsigned long long  number 
)

Set a configuration value that should be a number.

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

Definition at line 1672 of file configuration.c.

1676{
1677 char s[64];
1678
1679 GNUNET_snprintf (s,
1680 64,
1681 "%llu",
1682 number);
1684 section,
1685 option,
1686 s);
1687}
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.

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

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

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

1634{
1635 struct ConfigSection *sec;
1636 struct ConfigEntry *e;
1637 char *nv;
1638
1639 e = find_entry (cfg, section, option);
1640 if (NULL != e)
1641 {
1642 if (NULL == value)
1643 {
1644 GNUNET_free (e->val);
1645 e->val = NULL;
1646 }
1647 else
1648 {
1649 nv = GNUNET_strdup (value);
1650 GNUNET_free (e->val);
1651 e->val = nv;
1652 }
1653 return;
1654 }
1655 sec = find_section (cfg, section);
1656 if (sec == NULL)
1657 {
1658 sec = GNUNET_new (struct ConfigSection);
1659 sec->name = GNUNET_strdup (section);
1660 sec->next = cfg->sections;
1661 cfg->sections = sec;
1662 }
1663 e = GNUNET_new (struct ConfigEntry);
1664 e->key = GNUNET_strdup (option);
1665 e->val = GNUNET_strdup (value);
1666 e->next = sec->entries;
1667 sec->entries = e;
1668}
static struct ConfigSection * find_section(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Find a section entry from a configuration.

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

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

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

◆ GNUNET_CONFIGURATION_remove_value_filename()

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

Remove a filename from a configuration value that represents a list of filenames.

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

Definition at line 2328 of file configuration.c.

2333{
2334 char *list;
2335 char *pos;
2336 char *end;
2337 char *match;
2338 char old;
2339
2340 if (GNUNET_OK !=
2342 section,
2343 option,
2344 &list))
2345 return GNUNET_NO;
2346 match = escape_name (value);
2347 pos = list;
2348 while (1)
2349 {
2350 while (pos[0] == ' ')
2351 pos++;
2352 if (strlen (pos) == 0)
2353 break;
2354 end = pos + 1;
2355 while ((end[0] != ' ') && (end[0] != '\0'))
2356 {
2357 if (end[0] == '\\')
2358 {
2359 switch (end[1])
2360 {
2361 case '\\':
2362 case ' ':
2363 end++;
2364 break;
2365
2366 case '\0':
2367 /* illegal, but just keep it */
2368 break;
2369
2370 default:
2371 /* illegal, but just ignore that there was a '/' */
2372 break;
2373 }
2374 }
2375 end++;
2376 }
2377 old = end[0];
2378 end[0] = '\0';
2379 if (0 == strcmp (pos, match))
2380 {
2381 if (old != '\0')
2382 memmove (pos,
2383 &end[1],
2384 strlen (&end[1]) + 1);
2385 else
2386 {
2387 if (pos != list)
2388 pos[-1] = '\0';
2389 else
2390 pos[0] = '\0';
2391 }
2393 section,
2394 option,
2395 list);
2396 GNUNET_free (list);
2397 GNUNET_free (match);
2398 return GNUNET_OK;
2399 }
2400 if (old == '\0')
2401 break;
2402 end[0] = old;
2403 pos = end + 1;
2404 }
2405 GNUNET_free (list);
2406 GNUNET_free (match);
2407 return GNUNET_NO;
2408}
static char * escape_name(const char *value)
FIXME.

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

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

2295{
2296 char *escaped;
2297 char *old;
2298 char *nw;
2299
2300 if (GNUNET_SYSERR ==
2302 section,
2303 option,
2304 &test_match,
2305 (void *) value))
2306 return GNUNET_NO; /* already exists */
2307 if (GNUNET_OK !=
2308 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
2309 old = GNUNET_strdup ("");
2310 escaped = escape_name (value);
2311 nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2);
2312 strcpy (nw, old);
2313 if (strlen (old) > 0)
2314 strcat (nw, " ");
2315 strcat (nw, escaped);
2317 section,
2318 option,
2319 nw);
2320 GNUNET_free (old);
2321 GNUNET_free (nw);
2322 GNUNET_free (escaped);
2323 return GNUNET_OK;
2324}
static enum GNUNET_GenericReturnValue test_match(void *cls, const char *fn)
FIXME.
int GNUNET_CONFIGURATION_iterate_value_filenames(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, GNUNET_FileNameCallback cb, void *cb_cls)
Iterate over the set of filenames stored in a configuration value.

References cfg, 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, test_match(), and value.

Here is the call graph for this function:

◆ GNUNET_CONFIGURATION_config_settings_free()

void GNUNET_CONFIGURATION_config_settings_free ( struct GNUNET_CONFIGURATION_ConfigSettings cs)

Free resources associated with cs.

Parameters
[in]cssettings to free (actual memory of cs itself is not released)

Definition at line 2869 of file configuration.c.

2871{
2872 GNUNET_free (cs->option);
2873 GNUNET_free (cs->section);
2874 GNUNET_free (cs->value);
2875}

References GNUNET_free, GNUNET_CONFIGURATION_ConfigSettings::option, GNUNET_CONFIGURATION_ConfigSettings::section, and GNUNET_CONFIGURATION_ConfigSettings::value.

Referenced by main().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_config_tool_run()

void GNUNET_CONFIGURATION_config_tool_run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 
)

Main task to run to perform operations typical for gnunet-config as per the configuration settings given in cls.

Parameters
clsclosure with the struct GNUNET_CONFIGURATION_ConfigSettings
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cfgconfiguration

Definition at line 2677 of file configuration.c.

2682{
2683 struct GNUNET_CONFIGURATION_ConfigSettings *cs = cls;
2684 struct GNUNET_CONFIGURATION_Handle *out = NULL;
2685 struct GNUNET_CONFIGURATION_Handle *ncfg = NULL;
2686
2687 (void) args;
2688 if (cs->diagnostics)
2689 {
2690 /* Re-parse the configuration with diagnostics enabled. */
2693 if (GNUNET_OK !=
2695 cfgfile))
2696 {
2697 fprintf (stderr,
2698 _ ("Failed to load config file `%s'"),
2699 cfgfile);
2700 return;
2701 }
2702 cfg = ncfg;
2703 }
2704
2705 if (cs->full)
2706 cs->rewrite = GNUNET_YES;
2707 if (cs->list_sections)
2708 {
2709 fprintf (stderr,
2710 _ ("The following sections are available:\n"));
2713 NULL);
2714 return;
2715 }
2716 if ( (! cs->rewrite) &&
2717 (NULL == cs->section) )
2718 {
2719 char *serialization;
2720
2721 if (! cs->diagnostics)
2722 {
2723 fprintf (stderr,
2724 _ ("%s, %s or %s argument is required\n"),
2725 "--section",
2726 "--list-sections",
2727 "--diagnostics");
2729 return;
2730 }
2732 fprintf (stdout,
2733 "%s",
2734 serialization);
2735 GNUNET_free (serialization);
2736 }
2737 else if ( (NULL != cs->section) &&
2738 (NULL == cs->value) )
2739 {
2740 if (NULL == cs->option)
2741 {
2743 cfg,
2744 cs->section,
2745 cs->is_filename
2747 : &print_option,
2748 (void *) cfg);
2749 }
2750 else
2751 {
2752 char *value;
2753
2754 if (cs->is_filename)
2755 {
2756 if (GNUNET_OK !=
2758 cs->section,
2759 cs->option,
2760 &value))
2761 {
2763 cs->section,
2764 cs->option);
2766 return;
2767 }
2768 }
2769 else
2770 {
2771 if (GNUNET_OK !=
2773 cs->section,
2774 cs->option,
2775 &value))
2776 {
2778 cs->section,
2779 cs->option);
2781 return;
2782 }
2783 }
2784 fprintf (stdout,
2785 "%s\n",
2786 value);
2788 }
2789 }
2790 else if (NULL != cs->section)
2791 {
2792 if (NULL == cs->option)
2793 {
2794 fprintf (stderr,
2795 _ ("--option argument required to set value\n"));
2797 return;
2798 }
2801 cs->section,
2802 cs->option,
2803 cs->value);
2804 cs->rewrite = GNUNET_YES;
2805 }
2806 if (cs->rewrite)
2807 {
2808 char *cfg_fn = NULL;
2809
2810 if (NULL == out)
2812
2813 if (NULL == cfgfile)
2814 {
2815 const char *xdg = getenv ("XDG_CONFIG_HOME");
2816
2817 if (NULL != xdg)
2818 GNUNET_asprintf (&cfg_fn,
2819 "%s%s%s",
2820 xdg,
2822 cfg->pd->config_file);
2823 else
2824 cfg_fn = GNUNET_strdup (cfg->pd->user_config_file);
2825 cfgfile = cfg_fn;
2826 }
2827
2828 if (! cs->full)
2829 {
2830 struct GNUNET_CONFIGURATION_Handle *def;
2831
2833 if (GNUNET_OK !=
2835 NULL))
2836 {
2837 fprintf (stderr,
2838 _ ("failed to load configuration defaults"));
2839 cs->global_ret = 1;
2842 GNUNET_free (cfg_fn);
2843 return;
2844 }
2845 if (GNUNET_OK !=
2847 out,
2848 cfgfile))
2849 cs->global_ret = 2;
2851 }
2852 else
2853 {
2854 if (GNUNET_OK !=
2856 cfgfile))
2857 cs->global_ret = 2;
2858 }
2859 GNUNET_free (cfg_fn);
2860 }
2861 if (NULL != out)
2863 if (NULL != ncfg)
2865}
static void print_filename_option(void *cls, const char *section, const char *option, const char *value)
Print each option in a given section as a filename.
static void print_section_name(void *cls, const char *section)
Print out given section name.
static void print_option(void *cls, const char *section, const char *option, const char *value)
Print each option in a given section.
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.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
void GNUNET_CONFIGURATION_iterate_sections(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_SectionIterator iter, void *iter_cls)
Iterate over all sections in the configuration.
void GNUNET_CONFIGURATION_iterate_section_values(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over values of a section in the configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write_diffs(const struct GNUNET_CONFIGURATION_Handle *cfg_default, const struct GNUNET_CONFIGURATION_Handle *cfg_new, const char *filename)
Write only configuration entries that have been changed to configuration file.
char * GNUNET_CONFIGURATION_serialize_diagnostics(const struct GNUNET_CONFIGURATION_Handle *cfg)
Serializes the given configuration with diagnostics information.
void GNUNET_CONFIGURATION_enable_diagnostics(struct GNUNET_CONFIGURATION_Handle *cfg)
Enable extra diagnostics.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define EXIT_INVALIDARGUMENT
Definition: platform.h:253
#define EXIT_NOTCONFIGURED
Definition: platform.h:269
Closure for GNUNET_CONFIGURATION_config_tool_run() with settings for what should be done with the con...
int full
Should the generated configuration file contain the whole configuration?
int global_ret
Return value from the operation, to be returned from 'main'.
int diagnostics
Should we give extra diagnostics?
int list_sections
Whether to show the sections.
int rewrite
Should we write out the configuration file, even if no value was changed?
int is_filename
Treat option as a filename.

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

Referenced by main().

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