GNUnet 0.21.0
Configuration library

Configuration management. More...

Collaboration diagram for Configuration library:

Data Structures

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

Macros

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

Typedefs

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

Functions

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

Detailed Description

Configuration management.

Macro Definition Documentation

◆ GNUNET_CONFIGURATION_CONFIG_OPTIONS

#define GNUNET_CONFIGURATION_CONFIG_OPTIONS (   cs)

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

Parameters
csconfiguration settings to initialize

Definition at line 716 of file gnunet_configuration_lib.h.

Typedef Documentation

◆ GNUNET_CONFIGURATION_Callback

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

Signature of a function to be run with a configuration.

Parameters
clsclosure
cfgthe configuration
Returns
status code

Definition at line 236 of file gnunet_configuration_lib.h.

◆ GNUNET_CONFIGURATION_Iterator

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

Function to iterate over options.

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

Definition at line 286 of file gnunet_configuration_lib.h.

◆ GNUNET_CONFIGURATION_SectionIterator

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

Function to iterate over section.

Parameters
clsclosure
sectionname of the section

Definition at line 299 of file gnunet_configuration_lib.h.

Function Documentation

◆ GNUNET_CONFIGURATION_create()

struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create ( void  )

Create a new configuration object.

Returns
fresh configuration object

Definition at line 222 of file configuration.c.

223{
225 char *p;
226
228 /* make certain values from the project data available
229 as PATHS */
231 if (NULL != p)
232 {
234 "PATHS",
235 "DATADIR",
236 p);
237 GNUNET_free (p);
238 }
240 if (NULL != p)
241 {
243 "PATHS",
244 "LIBDIR",
245 p);
246 GNUNET_free (p);
247 }
249 if (NULL != p)
250 {
252 "PATHS",
253 "BINDIR",
254 p);
255 GNUNET_free (p);
256 }
258 if (NULL != p)
259 {
261 "PATHS",
262 "PREFIX",
263 p);
264 GNUNET_free (p);
265 }
267 if (NULL != p)
268 {
270 "PATHS",
271 "LOCALEDIR",
272 p);
273 GNUNET_free (p);
274 }
276 if (NULL != p)
277 {
279 "PATHS",
280 "ICONDIR",
281 p);
282 GNUNET_free (p);
283 }
285 if (NULL != p)
286 {
288 "PATHS",
289 "DOCDIR",
290 p);
291 GNUNET_free (p);
292 }
294 if (NULL != p)
295 {
297 "PATHS",
298 "LIBEXECDIR",
299 p);
300 GNUNET_free (p);
301 }
302 return cfg;
303}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_OS_installation_get_path(enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
@ GNUNET_OS_IPK_ICONDIR
Return the prefix of the path with application icons (share/icons/).
@ GNUNET_OS_IPK_DATADIR
Return the directory where data is installed (share/gnunet/)
@ GNUNET_OS_IPK_DOCDIR
Return the prefix of the path with documentation files, including the license (share/doc/gnunet/).
@ GNUNET_OS_IPK_LOCALEDIR
Return the directory where translations are installed (share/locale/)
@ GNUNET_OS_IPK_LIBDIR
Return the directory where libraries are installed.
@ GNUNET_OS_IPK_PREFIX
Return the "PREFIX" directory given to configure.
@ GNUNET_OS_IPK_BINDIR
Return the directory where the program binaries are installed.
@ GNUNET_OS_IPK_LIBEXECDIR
Return the directory where helper binaries are installed (lib/gnunet/libexec/)

References cfg, GNUNET_CONFIGURATION_set_value_string(), GNUNET_free, GNUNET_new, GNUNET_OS_installation_get_path(), GNUNET_OS_IPK_BINDIR, GNUNET_OS_IPK_DATADIR, GNUNET_OS_IPK_DOCDIR, GNUNET_OS_IPK_ICONDIR, GNUNET_OS_IPK_LIBDIR, GNUNET_OS_IPK_LIBEXECDIR, GNUNET_OS_IPK_LOCALEDIR, GNUNET_OS_IPK_PREFIX, and p.

Referenced by auto_config_cb(), create_unique_cfgs(), gg_load_configuration(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_default(), GNUNET_CONFIGURATION_dup(), GNUNET_CONFIGURATION_get_diff(), GNUNET_CONFIGURATION_parse_and_run(), GNUNET_CRYPTO_eddsa_setup_key(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_main(), GNUNET_SERVICE_run_(), GNUNET_TESTING_service_run(), GNUNET_TESTING_system_create_with_portrange(), GNUNET_TRANSPORT_TESTING_start_peer(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(), handle_auto_result(), handle_autoconfig_request(), handle_inline(), iter_check_config(), 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 1528 of file configuration.c.

1529{
1531
1534 return ret;
1535}
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:94
void GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over all options in the configuration.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create()
Create a new configuration object.

References cfg, copy_entry(), GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_iterate(), and ret.

Referenced by associate_shared_service(), auto_config_cb(), create_unique_cfgs(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_NAT_autoconfig_start(), GNUNET_TESTING_peer_configure(), 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 307 of file configuration.c.

308{
309 struct ConfigSection *sec;
310 struct ConfigFile *cf;
311
312 while (NULL != (sec = cfg->sections))
314 while (NULL != (cf = cfg->loaded_files_head))
315 {
320 cf);
321 GNUNET_free (cf);
322 }
325}
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 associate_shared_service(), auto_config_cb(), clean_node(), conclude_autoconfig_request(), create_unique_cfgs(), do_shutdown(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_default(), GNUNET_CONFIGURATION_parse_and_run(), GNUNET_CONFIGURATION_write_diffs(), GNUNET_CRYPTO_eddsa_setup_key(), GNUNET_NAT_autoconfig_cancel(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_main(), GNUNET_SERVICE_run_(), GNUNET_TESTING_peer_destroy(), GNUNET_TESTING_service_run(), GNUNET_TESTING_system_destroy(), GNUNET_TRANSPORT_TESTING_start_peer(), GNUNET_TRANSPORT_TESTING_stop_peer(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(), GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop(), 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(), 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
cfgconfiguration to update
filenamename of the configuration file, NULL to load defaults
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Load configuration.

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

Definition at line 2495 of file configuration.c.

2497{
2498 char *baseconfig;
2499 const char *base_config_varname;
2500
2501 if (cfg->load_called)
2502 {
2503 /* FIXME: Make this a GNUNET_assert later */
2504 GNUNET_break (0);
2506 }
2507 cfg->load_called = true;
2508 if (NULL != filename)
2509 {
2512 }
2513
2514 base_config_varname = GNUNET_OS_project_data_get ()->base_config_varname;
2515
2516 if ((NULL != base_config_varname)
2517 && (NULL != (baseconfig = getenv (base_config_varname))))
2518 {
2519 baseconfig = GNUNET_strdup (baseconfig);
2520 }
2521 else
2522 {
2523 char *ipath;
2524
2526 if (NULL == ipath)
2527 {
2528 GNUNET_break (0);
2529 return GNUNET_SYSERR;
2530 }
2531 GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d");
2532 GNUNET_free (ipath);
2533 }
2534
2535 char *dname = GNUNET_STRINGS_filename_expand (baseconfig);
2536 GNUNET_free (baseconfig);
2537
2538 if ((GNUNET_YES ==
2540 GNUNET_YES)) &&
2541 (GNUNET_SYSERR ==
2543 dname)))
2544 {
2546 "Failed to load base configuration from '%s'\n",
2547 filename);
2548 GNUNET_free (dname);
2549 return GNUNET_SYSERR; /* no configuration at all found */
2550 }
2551 GNUNET_free (dname);
2552 if ((NULL != filename) &&
2553 (GNUNET_OK !=
2555 filename)))
2556 {
2557 /* specified configuration not found */
2559 "Failed to load configuration from file '%s'\n",
2560 filename);
2561 return GNUNET_SYSERR;
2562 }
2563 if (((GNUNET_YES !=
2565 "PATHS",
2566 "DEFAULTCONFIG"))) &&
2567 (filename != NULL))
2569 "PATHS",
2570 "DEFAULTCONFIG",
2571 filename);
2572 return GNUNET_OK;
2573}
#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:403
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:495
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_OS_project_data_get(), GNUNET_strdup, GNUNET_STRINGS_filename_expand(), GNUNET_SYSERR, GNUNET_YES, GNUNET_CONFIGURATION_Handle::load_called, LOG, and GNUNET_CONFIGURATION_Handle::main_filename.

Referenced by auto_config_cb(), create_unique_cfgs(), gg_load_configuration(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_default(), GNUNET_CONFIGURATION_parse_and_run(), GNUNET_CRYPTO_eddsa_setup_key(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_main(), GNUNET_SERVICE_run_(), GNUNET_TESTING_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 2330 of file configuration.c.

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

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()

struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_default ( void  )

Return GNUnet's default configuration.

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

Returns
a freshly allocated configuration

Definition at line 2420 of file configuration.c.

2421{
2424 const char *xdg = getenv ("XDG_CONFIG_HOME");
2425 char *cfgname = NULL;
2427
2428 /* Makes sure function implicitly looking at the installation directory (for
2429 example GNUNET_CONFIGURATION_load further down) use GNUnet's environment
2430 instead of the caller's. It's done at the start to make sure as many
2431 functions as possible are directed to the proper paths. */
2432 GNUNET_OS_init (dpd);
2433
2435
2436 /* First, try user configuration. */
2437 if (NULL != xdg)
2438 GNUNET_asprintf (&cfgname, "%s/%s", xdg, dpd->config_file);
2439 else
2440 cfgname = GNUNET_strdup (dpd->user_config_file);
2441
2442 /* If user config doesn't exist, try in
2443 /etc/<projdir>/<cfgfile> and /etc/<cfgfile> */
2444 if (GNUNET_OK != GNUNET_DISK_file_test (cfgname))
2445 {
2446 GNUNET_free (cfgname);
2447 GNUNET_asprintf (&cfgname, "/etc/%s", dpd->config_file);
2448 }
2449 if (GNUNET_OK != GNUNET_DISK_file_test (cfgname))
2450 {
2451 GNUNET_free (cfgname);
2452 GNUNET_asprintf (&cfgname,
2453 "/etc/%s/%s",
2454 dpd->project_dirname,
2455 dpd->config_file);
2456 }
2457 if (GNUNET_OK != GNUNET_DISK_file_test (cfgname))
2458 {
2460 "Unable to top-level configuration file.\n");
2461 GNUNET_OS_init (pd);
2463 GNUNET_free (cfgname);
2464 return NULL;
2465 }
2466
2467 /* We found a configuration file that looks good, try to load it. */
2468
2470 "Loading top-level configuration from '%s'\n",
2471 cfgname);
2472 if (GNUNET_OK !=
2473 GNUNET_CONFIGURATION_load (cfg, cfgname))
2474 {
2475 GNUNET_OS_init (pd);
2477 GNUNET_free (cfgname);
2478 return NULL;
2479 }
2480 GNUNET_free (cfgname);
2481 GNUNET_OS_init (pd);
2482 return cfg;
2483}
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration (starts with defaults, then loads system-specific configuration).
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:482
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_default(void)
Return default project data used by 'libgnunetutil' for GNUnet.
void GNUNET_OS_init(const struct GNUNET_OS_ProjectData *pd)
Setup OS subsystem with project data.
Project-specific data used to help the OS subsystem find installation paths.
const char * project_dirname
Name of the project that is used in the "libexec" prefix, For example, "gnunet".
const char * user_config_file
Configuration file name to use (if $XDG_CONFIG_HOME is not set).
const char * config_file
Configuration file name (in $XDG_CONFIG_HOME) to use.

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

Here is the call graph for this function:

◆ GNUNET_CONFIGURATION_default_filename()

char * GNUNET_CONFIGURATION_default_filename ( void  )

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

Returns
NULL if no default configuration file can be located, a newly allocated string otherwise

Definition at line 2378 of file configuration.c.

2379{
2380 char *cfg_fn;
2382 const char *xdg = getenv ("XDG_CONFIG_HOME");
2383
2384 if (NULL != xdg)
2385 GNUNET_asprintf (&cfg_fn,
2386 "%s%s%s",
2387 xdg,
2389 pd->config_file);
2390 else
2391 cfg_fn = GNUNET_strdup (pd->user_config_file);
2392
2393 if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2394 return cfg_fn;
2395 GNUNET_free (cfg_fn);
2396
2397 /* Fall back to /etc/ for the default configuration.
2398 Should be okay to use forward slashes here. */
2399
2400 GNUNET_asprintf (&cfg_fn,
2401 "/etc/%s",
2402 pd->config_file);
2403 if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2404 return cfg_fn;
2405 GNUNET_free (cfg_fn);
2406
2407 GNUNET_asprintf (&cfg_fn,
2408 "/etc/%s/%s",
2409 pd->project_dirname,
2410 pd->config_file);
2411 if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2412 return cfg_fn;
2413
2414 GNUNET_free (cfg_fn);
2415 return NULL;
2416}
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test_read(const char *fil)
Check that fil corresponds to a filename and the file has read permissions.
Definition: disk.c:489
#define DIR_SEPARATOR_STR
Definition: platform.h:166

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

Referenced by GNUNET_PROGRAM_run2().

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

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

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

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

1228{
1229 struct GNUNET_Buffer buf = { 0 };
1230
1232 "#\n# Configuration file diagnostics\n#\n");
1234 "# Entry point: %s\n",
1236 "<none>");
1238 "#\n# Files Loaded:\n");
1239
1240 for (struct ConfigFile *cfil = cfg->loaded_files_head;
1241 NULL != cfil;
1242 cfil = cfil->next)
1243 {
1245 "# ");
1246 for (unsigned int i = 0; i < cfil->level; i++)
1248 "+");
1249 if (0 != cfil->level)
1251 " ");
1252
1254 "%s",
1255 cfil->source_filename);
1256
1257 if (NULL != cfil->hint_restrict_section)
1259 " (%s secret section %s)",
1260 cfil->hint_inaccessible
1261 ? "inaccessible"
1262 : "loaded",
1263 cfil->hint_restrict_section);
1264
1266 "\n");
1267 }
1268
1270 "#\n\n");
1271
1272 for (struct ConfigSection *sec = cfg->sections;
1273 NULL != sec;
1274 sec = sec->next)
1275 {
1276 if (sec->hint_secret_filename)
1278 "# secret section from %s\n# secret file stat %s\n",
1279 sec->hint_secret_filename,
1280 sec->hint_secret_stat);
1281 if (sec->hint_inlined_from_filename)
1282 {
1284 "# inlined from %s:%u\n",
1285 sec->hint_inlined_from_filename,
1286 sec->hint_inlined_from_line);
1287 }
1289 "[%s]\n\n",
1290 sec->name);
1291 if (sec->inaccessible)
1292 {
1294 "# <section contents inaccessible>\n\n\n");
1295 continue;
1296 }
1297 for (struct ConfigEntry *ent = sec->entries;
1298 NULL != ent;
1299 ent = ent->next)
1300 {
1301 if (do_skip (sec->name,
1302 ent->key))
1303 continue;
1304 if (NULL != ent->val)
1305 {
1306 char *pos;
1307 char *val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1308 strcpy (val, ent->val);
1309 while (NULL != (pos = strstr (val, "\n")))
1310 {
1311 memmove (&pos[2], &pos[1], strlen (&pos[1]));
1312 pos[0] = '\\';
1313 pos[1] = 'n';
1314 }
1315 if (NULL != ent->hint_filename)
1316 {
1318 "# %s:%u\n",
1319 ent->hint_filename,
1320 ent->hint_lineno);
1321 }
1323 "%s = %s\n",
1324 ent->key,
1325 val);
1326 GNUNET_free (val);
1327 }
1328 GNUNET_buffer_write_str (&buf, "\n");
1329 }
1330 GNUNET_buffer_write_str (&buf, "\n");
1331 }
1332 return GNUNET_buffer_reap_str (&buf);
1333}
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 700 of file configuration.c.

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

References cfg, GNUNET_CONFIGURATION_Handle::diagnostics, 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(), handle_auto_result(), and handle_autoconfig_request().

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

1339{
1340 char *fn;
1341 char *cfg_buf;
1342 size_t size;
1343
1345 if (fn == NULL)
1346 return GNUNET_SYSERR;
1348 {
1349 GNUNET_free (fn);
1350 return GNUNET_SYSERR;
1351 }
1353 &size);
1354 {
1355 struct GNUNET_DISK_FileHandle *h;
1356
1365 if (NULL == h)
1366 {
1367 GNUNET_free (fn);
1368 GNUNET_free (cfg_buf);
1369 return GNUNET_SYSERR;
1370 }
1371 if (((ssize_t) size) !=
1373 cfg_buf,
1374 size))
1375 {
1377 "write",
1378 fn);
1380 (void) GNUNET_DISK_directory_remove (fn);
1381 GNUNET_free (fn);
1382 GNUNET_free (cfg_buf);
1383 cfg->dirty = GNUNET_SYSERR; /* last write failed */
1384 return GNUNET_SYSERR;
1385 }
1388 }
1389 GNUNET_free (fn);
1390 GNUNET_free (cfg_buf);
1391 cfg->dirty = GNUNET_NO; /* last write succeeded */
1392 return GNUNET_OK;
1393}
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
char * GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
Serializes the given configuration.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1237
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:686
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1087
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:582
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_OPEN_TRUNCATE
Truncate file if it exists.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_GROUP_READ
Group can read.
@ GNUNET_DISK_PERM_GROUP_WRITE
Group can write.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
Handle used to access files (and pipes).

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 associate_shared_service(), create_unique_cfgs(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_write_diffs(), GNUNET_TESTING_peer_configure(), handle_delete_message(), handle_rename_message(), save_member(), save_member_session(), save_operation(), set_cont(), and testing_main().

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

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

1572{
1573 struct DiffHandle diffHandle;
1574
1575 diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
1576 diffHandle.cfg_default = cfg_default;
1577 GNUNET_CONFIGURATION_iterate (cfg_new, &compare_entries, &diffHandle);
1578 return diffHandle.cfgDiff;
1579}
static void compare_entries(void *cls, const char *section, const char *option, const char *value)
A callback function, compares entries from two configurations (default against a new configuration) a...
Used for diffing a configuration object against the default one.
const struct GNUNET_CONFIGURATION_Handle * cfg_default
struct GNUNET_CONFIGURATION_Handle * cfgDiff

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

Referenced by conclude_autoconfig_request(), 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 1086 of file configuration.c.

1087{
1088 return cfg->dirty;
1089}

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 char *  filename,
GNUNET_CONFIGURATION_Callback  cb,
void *  cb_cls 
)

Parse a configuration file filename and run the function cb with the resulting configuration object.

Then free the configuration object and return the status value from cb.

Parameters
filenameconfiguration to parse, NULL for "default"
cbfunction to run
cb_clsclosure for cb
Returns
GNUNET_SYSERR if parsing the configuration failed, otherwise return value from cb.

Definition at line 329 of file configuration.c.

332{
335
337 if (GNUNET_OK !=
339 filename))
340 {
341 GNUNET_break (0);
343 return GNUNET_SYSERR;
344 }
345 ret = cb (cb_cls, cfg);
347 return ret;
348}

References cfg, filename, GNUNET_break, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_load(), GNUNET_OK, GNUNET_SYSERR, 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 214 of file configuration.c.

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

References cfg, and GNUNET_CONFIGURATION_Handle::diagnostics.

Referenced by GNUNET_CONFIGURATION_config_tool_run().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_iterate()

void GNUNET_CONFIGURATION_iterate ( const struct GNUNET_CONFIGURATION_Handle cfg,
GNUNET_CONFIGURATION_Iterator  iter,
void *  iter_cls 
)

Iterate over all options in the configuration.

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

Definition at line 1397 of file configuration.c.

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

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

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

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_iterate_sections()

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

Iterate over all sections in the configuration.

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

Definition at line 1445 of file configuration.c.

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

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

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

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_remove_section()

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

Remove the given section and all options in it.

Parameters
cfgconfiguration to inspect
sectionname of the section to remove

Definition at line 1464 of file configuration.c.

1466{
1467 struct ConfigSection *spos;
1468 struct ConfigSection *prev;
1469 struct ConfigEntry *ent;
1470
1471 prev = NULL;
1472 spos = cfg->sections;
1473 while (NULL != spos)
1474 {
1475 if (0 == strcasecmp (section, spos->name))
1476 {
1477 if (NULL == prev)
1478 cfg->sections = spos->next;
1479 else
1480 prev->next = spos->next;
1481 while (NULL != (ent = spos->entries))
1482 {
1483 spos->entries = ent->next;
1484 GNUNET_free (ent->key);
1485 GNUNET_free (ent->val);
1487 GNUNET_free (ent);
1488 cfg->dirty = GNUNET_YES;
1489 }
1490 GNUNET_free (spos->name);
1494 GNUNET_free (spos);
1495 return;
1496 }
1497 prev = spos;
1498 spos = spos->next;
1499 }
1500}
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(), and GNUNET_TESTING_peer_configure().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_value_number()

enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number ( const struct GNUNET_CONFIGURATION_Handle cfg,
const char *  section,
const char *  option,
unsigned long long *  number 
)

Get a configuration value that should be a number.

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

Definition at line 1660 of file configuration.c.

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

Referenced by create_service(), 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_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_SYSERR on error

Definition at line 1680 of file configuration.c.

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

References cfg, dummy, find_entry(), 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_SYSERR on error

Definition at line 1700 of file configuration.c.

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

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

Referenced by GCD_init(), GNUNET_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_SYSERR on error

Definition at line 1724 of file configuration.c.

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

References cfg, find_entry(), GNUNET_STRINGS_fancy_size_to_bytes(), GNUNET_SYSERR, 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 1833 of file configuration.c.

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

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_SERVICE_run_(), GNUNET_SOCKS_check_service(), GNUNET_TESTING_peer_configure(), process_acl4(), process_acl6(), 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_SYSERR on error

Definition at line 1751 of file configuration.c.

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

References cfg, find_entry(), GNUNET_OK, GNUNET_strdup, GNUNET_SYSERR, 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_SERVICE_run_(), GNUNET_SOCKS_do_connect(), GNUNET_TESTING_peer_configure(), GNUNET_TESTING_service_run(), handle_ego_delete(), handle_ego_rename(), handle_register(), handle_uri(), identity_continuation(), load_member_session(), load_member_session_next(), login_redirect(), mq_init(), plugins_load(), process_acl4(), process_acl6(), read_service_conf(), run(), setup_exit_helper_args(), setup_service(), sock_read(), start_arm_service(), 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_SYSERR on error

Definition at line 2041 of file configuration.c.

2046{
2047 char *tmp;
2048
2049 if (GNUNET_OK !=
2050 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp))
2051 {
2052 LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to retrieve filename\n");
2053 *value = NULL;
2054 return GNUNET_SYSERR;
2055 }
2058 GNUNET_free (tmp);
2059 if (*value == NULL)
2060 return GNUNET_SYSERR;
2061 return GNUNET_OK;
2062}
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, 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_TESTING_peer_configure(), 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(), 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 2086 of file configuration.c.

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

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

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

1421{
1422 struct ConfigSection *spos;
1423 struct ConfigEntry *epos;
1424
1425 spos = cfg->sections;
1426 while ((spos != NULL) && (0 != strcasecmp (spos->name, section)))
1427 spos = spos->next;
1428 if (NULL == spos)
1429 return;
1430 if (spos->inaccessible)
1431 {
1433 "Section '%s' is marked as inaccessible, because the configuration "
1434 " file that contains the section can't be read.\n",
1435 section);
1436 return;
1437 }
1438 for (epos = spos->entries; NULL != epos; epos = epos->next)
1439 if (NULL != epos->val)
1440 iter (iter_cls, spos->name, epos->key, epos->val);
1441}
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 associate_shared_service(), authorize_endpoint(), auto_config_cb(), get_cont(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_TESTING_system_create_with_portrange(), and run().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_get_value_choice()

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

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

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

Definition at line 1770 of file configuration.c.

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

References _, cfg, warningfilter::choices, find_entry(), GNUNET_ERROR_TYPE_ERROR, 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_YES, GNUNET_NO or if option has no valid value, GNUNET_SYSERR

Definition at line 2066 of file configuration.c.

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

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

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

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

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

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

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

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

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

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

Referenced by main().

Here is the caller graph for this function:

◆ GNUNET_CONFIGURATION_config_tool_run()

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

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

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

Definition at line 108 of file configuration_helper.c.

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

Referenced by run().

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