GNUnet 0.24.1-15-gab6ed22f1
configuration.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_configuration_lib.h"
Include dependency graph for configuration.c:

Go to the source code of this file.

Data Structures

struct  ConfigEntry
 configuration entry More...
 
struct  ConfigSection
 configuration section More...
 
struct  ConfigFile
 
struct  GNUNET_CONFIGURATION_Handle
 configuration data More...
 
struct  DiffHandle
 Used for diffing a configuration object against the default one. More...
 
struct  CollectFilesContext
 Closure to collect_files_cb. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "util", __VA_ARGS__)
 
#define LOG_STRERROR_FILE(kind, syscall, filename)    GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
 

Functions

void GNUNET_CONFIGURATION_enable_diagnostics (struct GNUNET_CONFIGURATION_Handle *cfg)
 Enable extra diagnostics. More...
 
struct GNUNET_CONFIGURATION_HandleGNUNET_CONFIGURATION_create (const struct GNUNET_OS_ProjectData *pd)
 Create a new configuration object. More...
 
void GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
 Destroy configuration object. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse_and_run (const struct GNUNET_OS_ProjectData *pd, const char *filename, GNUNET_CONFIGURATION_Callback cb, void *cb_cls)
 Parse a configuration file filename and run the function cb with the resulting configuration object. More...
 
static enum GNUNET_GenericReturnValue collect_files_cb (void *cls, const char *filename)
 Function called with a filename. More...
 
static struct ConfigSectionfind_section (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
 Find a section entry from a configuration. More...
 
static int pstrcmp (const void *a, const void *b)
 
static enum GNUNET_GenericReturnValue handle_inline (struct GNUNET_CONFIGURATION_Handle *cfg, const char *path_or_glob, bool path_is_glob, const char *restrict_section, const char *source_filename, unsigned int source_lineno)
 Handle an inline directive. More...
 
static struct ConfigEntryfind_entry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
 Find an entry from a configuration. More...
 
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. 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_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...
 
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...
 
static bool do_skip (const char *sec, const char *key)
 Should we skip this configuration entry when serializing? More...
 
char * GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
 Serializes the given configuration. More...
 
static void dump_os_ipk (const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_Buffer *buf, enum GNUNET_OS_InstallationPathKind ipk)
 Dump an os installation path to a buffer. 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_write (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
 Write configuration file. 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_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...
 
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...
 
static void copy_entry (void *cls, const char *section, const char *option, const char *value)
 Copy a configuration value to the given target configuration. More...
 
struct GNUNET_CONFIGURATION_HandleGNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Duplicate an existing configuration object. More...
 
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) and write the diffs in a diff-configuration object (the callback object). 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_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...
 
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...
 
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...
 
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...
 
void GNUNET_CONFIGURATION_set_value_float (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, float number)
 Set a configuration value that should be a float. 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_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_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_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...
 
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...
 
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 the environment "FOO" is set to "DIRECTORY". 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...
 
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...
 
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...
 
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...
 
static char * escape_name (const char *value)
 FIXME. More...
 
static enum GNUNET_GenericReturnValue test_match (void *cls, const char *fn)
 FIXME. 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...
 
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_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d)
 Load default configuration. More...
 
char * GNUNET_CONFIGURATION_default_filename (const struct GNUNET_OS_ProjectData *pd)
 Return the filename of the default configuration filename that is used when no explicit configuration entry point has been specified. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
 Load configuration. More...
 
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. More...
 
static void print_option (void *cls, const char *section, const char *option, const char *value)
 Print each option in a given section. More...
 
static void print_section_name (void *cls, const char *section)
 Print out given section name. 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...
 
void GNUNET_CONFIGURATION_config_settings_free (struct GNUNET_CONFIGURATION_ConfigSettings *cs)
 Free resources associated with cs. More...
 
const struct GNUNET_OS_ProjectDataGNUNET_CONFIGURATION_get_project_data (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Return the project data associated with this configuration. More...
 

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "util", __VA_ARGS__)

Definition at line 30 of file configuration.c.

◆ LOG_STRERROR_FILE

#define LOG_STRERROR_FILE (   kind,
  syscall,
  filename 
)     GNUNET_log_from_strerror_file (kind, "util", syscall, filename)

Definition at line 32 of file configuration.c.

Function Documentation

◆ collect_files_cb()

static enum GNUNET_GenericReturnValue collect_files_cb ( void *  cls,
const char *  filename 
)
static

Function called with a filename.

Parameters
clsclosure
filenamecomplete filename (absolute path)
Returns
GNUNET_OK to continue to iterate, GNUNET_NO to stop iteration with no error, GNUNET_SYSERR to abort iteration with error!

Definition at line 394 of file configuration.c.

396{
397 struct CollectFilesContext *igc = cls;
398
400 igc->files_length,
402 return GNUNET_OK;
403}
static char * filename
@ GNUNET_OK
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
Closure to collect_files_cb.
char ** files
Collected files from globbing.
unsigned int files_length
Size of the files array.

References filename, CollectFilesContext::files, CollectFilesContext::files_length, GNUNET_array_append, GNUNET_OK, and GNUNET_strdup.

Referenced by GNUNET_CONFIGURATION_load_from(), and handle_inline().

Here is the caller graph for this function:

◆ find_section()

static struct ConfigSection * find_section ( const struct GNUNET_CONFIGURATION_Handle cfg,
const char *  section 
)
static

Find a section entry from a configuration.

Parameters
cfgconfiguration to search in
sectionname of the section to look for
Returns
matching entry, NULL if not found

Definition at line 414 of file configuration.c.

416{
417 struct ConfigSection *pos;
418
419 if (NULL == cfg)
420 return NULL;
421 pos = cfg->sections;
422 while ( (NULL != pos) &&
423 (0 != strcasecmp (section,
424 pos->name)) )
425 pos = pos->next;
426 return pos;
427}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
configuration section
Definition: configuration.c:71
char * name
name of the section
Definition: configuration.c:85
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:75
struct ConfigSection * sections
Configuration sections.

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

Referenced by find_entry(), GNUNET_CONFIGURATION_set_value_string(), and handle_inline().

Here is the caller graph for this function:

◆ pstrcmp()

static int pstrcmp ( const void *  a,
const void *  b 
)
static

Definition at line 431 of file configuration.c.

433{
434 return strcmp (*((const char **) a),
435 *((const char **) b));
436}

Referenced by GNUNET_CONFIGURATION_load_from(), and handle_inline().

Here is the caller graph for this function:

◆ handle_inline()

static enum GNUNET_GenericReturnValue handle_inline ( struct GNUNET_CONFIGURATION_Handle cfg,
const char *  path_or_glob,
bool  path_is_glob,
const char *  restrict_section,
const char *  source_filename,
unsigned int  source_lineno 
)
static

Handle an inline directive.

Returns
GNUNET_SYSERR on error, GNUNET_OK otherwise

Definition at line 445 of file configuration.c.

451{
452 char *inline_path = NULL;
453 struct GNUNET_CONFIGURATION_Handle *other_cfg = NULL;
454 struct CollectFilesContext igc = {
455 .files = NULL,
456 .files_length = 0,
457 };
458 enum GNUNET_GenericReturnValue fun_ret;
459 unsigned int old_nest_level = cfg->current_nest_level++;
460
461 /* We support the section restriction only for non-globs */
462 GNUNET_assert (! (path_is_glob && (NULL != restrict_section)));
463
464 if (NULL == source_filename)
465 {
467 "Refusing to parse inline configurations, "
468 "not allowed without source filename!\n");
469 fun_ret = GNUNET_SYSERR;
470 goto cleanup;
471 }
472
473 if ('/' == *path_or_glob)
474 inline_path = GNUNET_strdup (path_or_glob);
475 else
476 {
477 /* We compute the canonical, absolute path first,
478 so that relative imports resolve properly with symlinked
479 config files. */
480 char *source_realpath;
481 char *endsep;
482
483 source_realpath = realpath (source_filename,
484 NULL);
485 if (NULL == source_realpath)
486 {
487 /* Couldn't even resolve path of base dir. */
488 GNUNET_break (0);
489 /* failed to parse included config */
490 fun_ret = GNUNET_SYSERR;
491 goto cleanup;
492 }
493 endsep = strrchr (source_realpath, '/');
494 GNUNET_assert (NULL != endsep);
495 *endsep = '\0';
496 GNUNET_asprintf (&inline_path,
497 "%s/%s",
498 source_realpath,
499 path_or_glob);
500 free (source_realpath);
501 }
502
503 if (path_is_glob)
504 {
505 int nret;
506
508 "processing config glob '%s'\n",
509 inline_path);
510
511 nret = GNUNET_DISK_glob (inline_path,
513 &igc);
514 if (-1 == nret)
515 {
516 fun_ret = GNUNET_SYSERR;
517 goto cleanup;
518 }
519 GNUNET_assert (nret == igc.files_length);
520 qsort (igc.files,
521 igc.files_length,
522 sizeof (char *),
523 &pstrcmp);
524 for (int i = 0; i < nret; i++)
525 {
526 if (GNUNET_OK !=
528 igc.files[i]))
529 {
530 fun_ret = GNUNET_SYSERR;
531 goto cleanup;
532 }
533 }
534 fun_ret = GNUNET_OK;
535 }
536 else if (NULL != restrict_section)
537 {
538 enum GNUNET_GenericReturnValue inner_ret;
539 struct ConfigSection *cs;
540 struct ConfigFile *cf = GNUNET_new (struct ConfigFile);
541
542 inner_ret = GNUNET_DISK_file_test_read (inline_path);
543
544 cs = find_section (cfg, restrict_section);
545
546 if (NULL == cs)
547 {
548 cs = GNUNET_new (struct ConfigSection);
549 cs->name = GNUNET_strdup (restrict_section);
550 cs->next = cfg->sections;
551 cfg->sections = cs;
552 cs->entries = NULL;
553 }
554 if (cfg->diagnostics)
555 {
556 const char *pwname;
557 const char *grname;
558 char *sfn = GNUNET_STRINGS_filename_expand (inline_path);
559 struct stat istat;
560
561 cs->hint_secret_filename = sfn;
562 if (0 == stat (sfn, &istat))
563 {
564 struct passwd *pw = getpwuid (istat.st_uid);
565 struct group *gr = getgrgid (istat.st_gid);
566 pwname = (NULL == pw) ? "<unknown>" : pw->pw_name;
567 grname = (NULL == gr) ? "<unknown>" : gr->gr_name;
568
570 "%s:%s %o",
571 pwname,
572 grname,
573 istat.st_mode);
574 }
575 else
576 {
577 cs->hint_secret_stat = GNUNET_strdup ("<can't stat file>");
578 }
579 if (source_filename)
580 {
581 /* Possible that this secret section has been inlined before */
583 cs->hint_inlined_from_filename = GNUNET_strdup (source_filename);
584 cs->hint_inlined_from_line = source_lineno;
585 }
586 }
587
588 /* Put file in the load list for diagnostics, even if we can't access it. */
589 {
591 cf->source_filename = GNUNET_strdup (inline_path);
592 cf->hint_restrict_section = GNUNET_strdup (restrict_section);
595 cf);
596 }
597
598 if (GNUNET_OK != inner_ret)
599 {
600 cs->inaccessible = true;
601 cf->hint_inaccessible = true;
602 /* File can't be accessed, but that's okay. */
603 fun_ret = GNUNET_OK;
604 goto cleanup;
605 }
606
607 other_cfg = GNUNET_CONFIGURATION_create (cfg->pd);
608 other_cfg->restrict_section = restrict_section;
609 inner_ret = GNUNET_CONFIGURATION_parse (other_cfg,
610 inline_path);
611 if (GNUNET_OK != inner_ret)
612 {
613 cf->hint_inaccessible = true;
614 fun_ret = inner_ret;
615 goto cleanup;
616 }
617
618 cs = find_section (other_cfg,
619 restrict_section);
620 if (NULL == cs)
621 {
623 "Configuration file '%s' loaded with @inline-secret@ "
624 "does not contain section '%s'.\n",
625 inline_path,
626 restrict_section);
627 /* Inlined configuration is accessible but doesn't contain any values.
628 We treat this as if the inlined section was empty, and do not
629 consider it an error. */
630 fun_ret = GNUNET_OK;
631 goto cleanup;
632 }
633 for (struct ConfigEntry *ce = cs->entries;
634 NULL != ce;
635 ce = ce->next)
637 restrict_section,
638 ce->key,
639 ce->val);
640 fun_ret = GNUNET_OK;
641 }
642 else if (GNUNET_OK !=
644 inline_path))
645 {
646 fun_ret = GNUNET_SYSERR;
647 goto cleanup;
648 }
649 else
650 {
651 fun_ret = GNUNET_OK;
652 }
653cleanup:
654 cfg->current_nest_level = old_nest_level;
655 if (NULL != other_cfg)
657 GNUNET_free (inline_path);
658 if (igc.files_length > 0)
659 {
660 for (size_t i = 0; i < igc.files_length; i++)
661 GNUNET_free (igc.files[i]);
663 }
664 return fun_ret;
665}
static struct ConfigSection * find_section(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Find a section entry from a configuration.
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.
#define LOG(kind,...)
Definition: configuration.c:30
static void cleanup(void *cls)
Disconnect and shutdown.
Definition: gnunet-did.c:131
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(const struct GNUNET_OS_ProjectData *pd)
Create a new configuration object.
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.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
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.
int GNUNET_DISK_glob(const char *glob_pattern, GNUNET_FileNameCallback callback, void *callback_cls)
Find all files matching a glob pattern.
Definition: disk.c:1011
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:530
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:504
configuration entry
Definition: configuration.c:39
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:43
char * hint_restrict_section
Was this configuration file parsed via @inline-secret@?
char * source_filename
Source filename.
bool hint_inaccessible
Was this configuration file inaccessible?
unsigned int level
Level in the tree of loaded config files.
char * hint_inlined_from_filename
For secret sections: Where was this inlined from?
struct ConfigEntry * entries
entries in the section
Definition: configuration.c:80
bool inaccessible
Is the configuration section marked as inaccessible?
Definition: configuration.c:93
char * hint_secret_filename
Diagnostics hint for the secret file.
Definition: configuration.c:98
unsigned int hint_inlined_from_line
For secret sections: Where was this inlined from?
char * hint_secret_stat
Extra information regarding permissions of the secret file.
struct ConfigFile * loaded_files_tail
Linked list of loaded files.
unsigned int current_nest_level
Current nesting level of file loading.
const struct GNUNET_OS_ProjectData * pd
Project data for this configuration object.
struct ConfigFile * loaded_files_head
Linked list of loaded files.
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, cleanup(), collect_files_cb(), GNUNET_CONFIGURATION_Handle::current_nest_level, GNUNET_CONFIGURATION_Handle::diagnostics, ConfigSection::entries, CollectFilesContext::files, CollectFilesContext::files_length, find_section(), GNUNET_array_grow, GNUNET_asprintf(), GNUNET_assert, GNUNET_break, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_parse(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_CONTAINER_DLL_insert_tail, GNUNET_DISK_file_test_read(), GNUNET_DISK_glob(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_new, GNUNET_OK, GNUNET_strdup, GNUNET_STRINGS_filename_expand(), GNUNET_SYSERR, ConfigFile::hint_inaccessible, ConfigSection::hint_inlined_from_filename, ConfigSection::hint_inlined_from_line, ConfigFile::hint_restrict_section, ConfigSection::hint_secret_filename, ConfigSection::hint_secret_stat, ConfigSection::inaccessible, ConfigFile::level, GNUNET_CONFIGURATION_Handle::loaded_files_head, GNUNET_CONFIGURATION_Handle::loaded_files_tail, LOG, ConfigSection::name, ConfigEntry::next, ConfigSection::next, GNUNET_CONFIGURATION_Handle::pd, pstrcmp(), GNUNET_CONFIGURATION_Handle::restrict_section, GNUNET_CONFIGURATION_Handle::sections, and ConfigFile::source_filename.

Referenced by GNUNET_CONFIGURATION_deserialize().

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

◆ find_entry()

static struct ConfigEntry * find_entry ( const struct GNUNET_CONFIGURATION_Handle cfg,
const char *  section,
const char *  key 
)
static

Find an entry from a configuration.

Parameters
cfghandle to the configuration
sectionsection the option is in
keythe option
Returns
matching entry, NULL if not found

Definition at line 677 of file configuration.c.

680{
681 struct ConfigSection *sec;
682 struct ConfigEntry *pos;
683
684 if (NULL == (sec = find_section (cfg, section)))
685 return NULL;
686 if (sec->inaccessible)
687 {
689 "Section '%s' is marked as inaccessible, because the configuration "
690 "file that contains the section can't be read. Attempts to use "
691 "option '%s' will fail.\n",
692 section,
693 key);
694 return NULL;
695 }
696 pos = sec->entries;
697 while ((pos != NULL) && (0 != strcasecmp (key, pos->key)))
698 pos = pos->next;
699 return pos;
700}
struct GNUNET_HashCode key
The key used in the DHT.
@ GNUNET_ERROR_TYPE_WARNING
char * key
key for this entry
Definition: configuration.c:48

References cfg, ConfigSection::entries, find_section(), GNUNET_ERROR_TYPE_WARNING, ConfigSection::inaccessible, key, ConfigEntry::key, LOG, and ConfigEntry::next.

Referenced by compare_entries(), GNUNET_CONFIGURATION_get_value_choice(), GNUNET_CONFIGURATION_get_value_float(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_size(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_get_value_time(), GNUNET_CONFIGURATION_have_value(), GNUNET_CONFIGURATION_set_value_string(), and set_entry_hint().

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

◆ set_entry_hint()

static void set_entry_hint ( struct GNUNET_CONFIGURATION_Handle cfg,
const char *  section,
const char *  option,
const char *  hint_filename,
unsigned int  hint_line 
)
static

Set a configuration hint.

Parameters
cfgconfiguration handle
sectionsection
optionconfig option
hint_filename
hint_line

Definition at line 713 of file configuration.c.

718{
719 struct ConfigEntry *e = find_entry (cfg, section, option);
720 if (! cfg->diagnostics)
721 return;
722 if (! e)
723 return;
725 e->hint_lineno = hint_line;
726}
static struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
char * hint_filename
Diagnostics information for the filename.
Definition: configuration.c:58
unsigned int hint_lineno
Diagnostics information for the line number.
Definition: configuration.c:63

References cfg, GNUNET_CONFIGURATION_Handle::diagnostics, find_entry(), GNUNET_strdup, ConfigEntry::hint_filename, and ConfigEntry::hint_lineno.

Referenced by GNUNET_CONFIGURATION_deserialize().

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

◆ do_skip()

static bool do_skip ( const char *  sec,
const char *  key 
)
static

Should we skip this configuration entry when serializing?

Parameters
secsection name
keykey
Returns
true if we should skip it

Definition at line 1134 of file configuration.c.

1136{
1137 if (0 != strcasecmp ("PATHS",
1138 sec))
1139 return false;
1140 return ( (0 == strcasecmp ("DATADIR",
1141 key)) ||
1142 (0 == strcasecmp ("LIBDIR",
1143 key)) ||
1144 (0 == strcasecmp ("BINDIR",
1145 key)) ||
1146 (0 == strcasecmp ("PREFIX",
1147 key)) ||
1148 (0 == strcasecmp ("LOCALEDIR",
1149 key)) ||
1150 (0 == strcasecmp ("ICONDIR",
1151 key)) ||
1152 (0 == strcasecmp ("DOCDIR",
1153 key)) ||
1154 (0 == strcasecmp ("DEFAULTCONFIG",
1155 key)) ||
1156 (0 == strcasecmp ("LIBEXECDIR",
1157 key)) );
1158}

References key.

Referenced by GNUNET_CONFIGURATION_serialize(), and GNUNET_CONFIGURATION_serialize_diagnostics().

Here is the caller graph for this function:

◆ dump_os_ipk()

static void dump_os_ipk ( const struct GNUNET_CONFIGURATION_Handle cfg,
struct GNUNET_Buffer buf,
enum GNUNET_OS_InstallationPathKind  ipk 
)
static

Dump an os installation path to a buffer.

Parameters
cfgconfiguration
bufbuffer to write to
ipkwhich path to print

Definition at line 1268 of file configuration.c.

1272{
1274 ipk);
1275 const char *ipkname;
1276 switch (ipk)
1277 {
1279 ipkname = "IPK_DATADIR";
1280 break;
1282 ipkname = "IPK_BINDIR";
1283 break;
1285 ipkname = "IPK_LIBDIR";
1286 break;
1288 ipkname = "IPK_PREFIX";
1290 ipkname = "IPK_LOCALEDIR";
1291 break;
1293 ipkname = "IPK_ICONDIR";
1295 ipkname = "IPK_DOCDIR";
1296 break;
1298 ipkname = "IPK_LIBEXECDIR";
1299 break;
1301 ipkname = "IPK_SELF_PREFIX";
1302 break;
1303 default:
1304 ipkname = "??";
1305 break;
1306 }
1308 "# %s = %s\n",
1309 ipkname,
1310 v);
1311 GNUNET_free (v);
1312}
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.
char * GNUNET_OS_installation_get_path(const struct GNUNET_OS_ProjectData *pd, enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
@ GNUNET_OS_IPK_SELF_PREFIX
Return the installation directory of this application, not the one of the overall GNUnet installation...
@ 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_buffer_write_fstr(), GNUNET_free, 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, GNUNET_OS_IPK_SELF_PREFIX, and GNUNET_CONFIGURATION_Handle::pd.

Referenced by GNUNET_CONFIGURATION_serialize_diagnostics().

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

◆ copy_entry()

static void copy_entry ( void *  cls,
const char *  section,
const char *  option,
const char *  value 
)
static

Copy a configuration value to the given target configuration.

Overwrites existing entries.

Parameters
clsthe destination configuration (struct GNUNET_CONFIGURATION_Handle *)
sectionsection for the value
optionoption name of the value
valuevalue to copy

Definition at line 1626 of file configuration.c.

1630{
1631 struct GNUNET_CONFIGURATION_Handle *dst = cls;
1632
1634 section,
1635 option,
1636 value);
1637}
static char * value
Value of the record to add/remove.

References GNUNET_CONFIGURATION_set_value_string(), and value.

Referenced by GNUNET_CONFIGURATION_dup().

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

◆ compare_entries()

static void compare_entries ( void *  cls,
const char *  section,
const char *  option,
const char *  value 
)
static

A callback function, compares entries from two configurations (default against a new configuration) and write the diffs in a diff-configuration object (the callback object).

Parameters
clsthe diff configuration (struct DiffHandle *)
sectionsection for the value (of the default conf.)
optionoption name of the value (of the default conf.)
valuevalue to copy (of the default conf.)

Definition at line 1665 of file configuration.c.

1669{
1670 struct DiffHandle *dh = cls;
1671 struct ConfigEntry *entNew;
1672
1673 entNew = find_entry (dh->cfg_default, section, option);
1674 if ((NULL != entNew) && (NULL != entNew->val) &&
1675 (0 == strcmp (entNew->val, value)))
1676 return;
1678 section,
1679 option,
1680 value);
1681}
char * val
current, committed value
Definition: configuration.c:53
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, find_entry(), GNUNET_CONFIGURATION_set_value_string(), ConfigEntry::val, and value.

Referenced by GNUNET_CONFIGURATION_get_diff().

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

◆ expand_dollar()

static char * expand_dollar ( const struct GNUNET_CONFIGURATION_Handle cfg,
char *  orig,
unsigned int  depth 
)
static

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!)
depthrecursion depth, used to detect recursive expansions
Returns
$-expanded string, never NULL unless orig was NULL

Definition at line 2045 of file configuration.c.

2048{
2049 char *prefix;
2050 char *result;
2051 char *start;
2052 const char *post;
2053 const char *env;
2054 char *def;
2055 char *end;
2056 unsigned int lopen;
2057 char erased_char;
2058 char *erased_pos;
2059 size_t len;
2060
2061 if (NULL == orig)
2062 return NULL;
2063 if (depth > 128)
2064 {
2066 "Recursive expansion suspected, aborting $-expansion for term `%s'\n",
2067 orig);
2068 return orig;
2069 }
2071 "Asked to $-expand %s\n",
2072 orig);
2073 if ('$' != orig[0])
2074 {
2076 "Doesn't start with $ - not expanding\n");
2077 return orig;
2078 }
2079 erased_char = 0;
2080 erased_pos = NULL;
2081 if ('{' == orig[1])
2082 {
2083 start = &orig[2];
2084 lopen = 1;
2085 end = &orig[1];
2086 while (lopen > 0)
2087 {
2088 end++;
2089 switch (*end)
2090 {
2091 case '}':
2092 lopen--;
2093 break;
2094
2095 case '{':
2096 lopen++;
2097 break;
2098
2099 case '\0':
2101 "Missing closing `}' in option `%s'\n",
2102 orig);
2103 return orig;
2104
2105 default:
2106 break;
2107 }
2108 }
2109 erased_char = *end;
2110 erased_pos = end;
2111 *end = '\0';
2112 post = end + 1;
2113 def = strchr (orig, ':');
2114 if (NULL != def)
2115 {
2116 *def = '\0';
2117 def++;
2118 if (('-' == *def) || ('=' == *def))
2119 def++;
2120 def = GNUNET_strdup (def);
2121 }
2122 }
2123 else
2124 {
2125 int i;
2126
2127 start = &orig[1];
2128 def = NULL;
2129 i = 0;
2130 while ( (orig[i] != '/') &&
2131 (orig[i] != '\\') &&
2132 (orig[i] != '\0') &&
2133 (orig[i] != ' ') )
2134 i++;
2135 if (orig[i] == '\0')
2136 {
2137 post = "";
2138 }
2139 else
2140 {
2141 erased_char = orig[i];
2142 erased_pos = &orig[i];
2143 orig[i] = '\0';
2144 post = &orig[i + 1];
2145 }
2146 }
2148 "Split into `%s' and `%s' with default %s\n",
2149 start,
2150 post,
2151 def);
2152 if (GNUNET_OK !=
2154 "PATHS",
2155 start,
2156 &prefix))
2157 {
2158 if (NULL == (env = getenv (start)))
2159 {
2160 /* try default */
2161 def = expand_dollar (cfg,
2162 def,
2163 depth + 1);
2164 env = def;
2165 }
2166 if (NULL == env)
2167 {
2169 if (erased_pos)
2170 *erased_pos = erased_char;
2172 "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n",
2173 start,
2174 orig);
2176 return orig;
2177 }
2179 }
2181 prefix);
2182 if ((erased_pos) && ('}' != erased_char))
2183 {
2184 len = strlen (prefix) + 1;
2185 prefix = GNUNET_realloc (prefix, len + 1);
2186 prefix[len - 1] = erased_char;
2187 prefix[len] = '\0';
2188 }
2189 result = GNUNET_malloc (strlen (prefix) + strlen (post) + 1);
2190 strcpy (result, prefix);
2191 strcat (result, post);
2192 GNUNET_free (def);
2194 GNUNET_free (orig);
2195 return result;
2196}
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
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...
char * getenv()
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:38
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:33
static int prefix
If printing the value of PREFIX has been requested.
Definition: gnunet-config.c:65
static int result
Global testing status.
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...
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.

References cfg, end, env, expand_dollar(), getenv(), GNUNET_CONFIGURATION_expand_dollar(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_malloc, GNUNET_OK, GNUNET_realloc, GNUNET_strdup, LOG, prefix, result, and start.

Referenced by expand_dollar(), and GNUNET_CONFIGURATION_expand_dollar().

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

◆ escape_name()

static char * escape_name ( const char *  value)
static

FIXME.

Parameters
valueFIXME
Returns
FIXME

Definition at line 2363 of file configuration.c.

2364{
2365 char *escaped;
2366 const char *rpos;
2367 char *wpos;
2368
2369 escaped = GNUNET_malloc (strlen (value) * 2 + 1);
2370 memset (escaped, 0, strlen (value) * 2 + 1);
2371 rpos = value;
2372 wpos = escaped;
2373 while (rpos[0] != '\0')
2374 {
2375 switch (rpos[0])
2376 {
2377 case '\\':
2378 case ' ':
2379 wpos[0] = '\\';
2380 wpos[1] = rpos[0];
2381 wpos += 2;
2382 break;
2383
2384 default:
2385 wpos[0] = rpos[0];
2386 wpos++;
2387 }
2388 rpos++;
2389 }
2390 return escaped;
2391}

References GNUNET_malloc, and value.

Referenced by GNUNET_CONFIGURATION_append_value_filename(), and GNUNET_CONFIGURATION_remove_value_filename().

Here is the caller graph for this function:

◆ test_match()

static enum GNUNET_GenericReturnValue test_match ( void *  cls,
const char *  fn 
)
static

FIXME.

Parameters
clsstring we compare with (const char*)
fnfilename we are currently looking at
Returns
GNUNET_OK if the names do not match, GNUNET_SYSERR if they do

Definition at line 2402 of file configuration.c.

2404{
2405 const char *of = cls;
2406
2407 return (0 == strcmp (of, fn))
2409 : GNUNET_OK;
2410}

References GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_CONFIGURATION_append_value_filename().

Here is the caller graph for this function:

◆ print_filename_option()

static void print_filename_option ( void *  cls,
const char *  section,
const char *  option,
const char *  value 
)
static

Print each option in a given section as a filename.

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

Definition at line 2733 of file configuration.c.

2737{
2738 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
2739
2740 char *value_fn;
2741 char *fn;
2742
2745 section,
2746 option,
2747 &value_fn));
2748 fn = GNUNET_STRINGS_filename_expand (value_fn);
2749 if (NULL == fn)
2750 fn = value_fn;
2751 else
2752 GNUNET_free (value_fn);
2753 fprintf (stdout,
2754 "%s = %s\n",
2755 option,
2756 fn);
2757 GNUNET_free (fn);
2758}
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.

References cfg, GNUNET_assert, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_free, GNUNET_OK, and GNUNET_STRINGS_filename_expand().

Referenced by GNUNET_CONFIGURATION_config_tool_run().

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

◆ print_option()

static void print_option ( void *  cls,
const char *  section,
const char *  option,
const char *  value 
)
static

Print each option in a given section.

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

Definition at line 2770 of file configuration.c.

2774{
2775 (void) cls;
2776 (void) section;
2777
2778 fprintf (stdout,
2779 "%s = %s\n",
2780 option,
2781 value);
2782}

References value.

Referenced by GNUNET_CONFIGURATION_config_tool_run().

Here is the caller graph for this function:

◆ print_section_name()

static void print_section_name ( void *  cls,
const char *  section 
)
static

Print out given section name.

Parameters
clsunused
sectiona section in the configuration file

Definition at line 2792 of file configuration.c.

2794{
2795 (void) cls;
2796 fprintf (stdout,
2797 "%s\n",
2798 section);
2799}

Referenced by GNUNET_CONFIGURATION_config_tool_run().

Here is the caller graph for this function: