GNUnet 0.22.2
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...
 
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...
 
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
422 pos = cfg->sections;
423 while ((pos != NULL) && (0 != strcasecmp (section, pos->name)))
424 pos = pos->next;
425 return pos;
426}
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 430 of file configuration.c.

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

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

450{
451 char *inline_path = NULL;
452 struct GNUNET_CONFIGURATION_Handle *other_cfg = NULL;
453 struct CollectFilesContext igc = {
454 .files = NULL,
455 .files_length = 0,
456 };
457 enum GNUNET_GenericReturnValue fun_ret;
458 unsigned int old_nest_level = cfg->current_nest_level++;
459
460 /* We support the section restriction only for non-globs */
461 GNUNET_assert (! (path_is_glob && (NULL != restrict_section)));
462
463 if (NULL == source_filename)
464 {
466 "Refusing to parse inline configurations, "
467 "not allowed without source filename!\n");
468 fun_ret = GNUNET_SYSERR;
469 goto cleanup;
470 }
471
472 if ('/' == *path_or_glob)
473 inline_path = GNUNET_strdup (path_or_glob);
474 else
475 {
476 /* We compute the canonical, absolute path first,
477 so that relative imports resolve properly with symlinked
478 config files. */
479 char *source_realpath;
480 char *endsep;
481
482 source_realpath = realpath (source_filename,
483 NULL);
484 if (NULL == source_realpath)
485 {
486 /* Couldn't even resolve path of base dir. */
487 GNUNET_break (0);
488 /* failed to parse included config */
489 fun_ret = GNUNET_SYSERR;
490 goto cleanup;
491 }
492 endsep = strrchr (source_realpath, '/');
493 GNUNET_assert (NULL != endsep);
494 *endsep = '\0';
495 GNUNET_asprintf (&inline_path,
496 "%s/%s",
497 source_realpath,
498 path_or_glob);
499 free (source_realpath);
500 }
501
502 if (path_is_glob)
503 {
504 int nret;
505
507 "processing config glob '%s'\n",
508 inline_path);
509
510 nret = GNUNET_DISK_glob (inline_path, collect_files_cb, &igc);
511 if (-1 == nret)
512 {
513 fun_ret = GNUNET_SYSERR;
514 goto cleanup;
515 }
516 GNUNET_assert (nret == igc.files_length);
517 qsort (igc.files, igc.files_length, sizeof (char *), pstrcmp);
518 for (int i = 0; i < nret; i++)
519 {
520 if (GNUNET_OK !=
522 igc.files[i]))
523 {
524 fun_ret = GNUNET_SYSERR;
525 goto cleanup;
526 }
527 }
528 fun_ret = GNUNET_OK;
529 }
530 else if (NULL != restrict_section)
531 {
532 enum GNUNET_GenericReturnValue inner_ret;
533 struct ConfigSection *cs;
534 struct ConfigFile *cf = GNUNET_new (struct ConfigFile);
535
536 inner_ret = GNUNET_DISK_file_test_read (inline_path);
537
538 cs = find_section (cfg, restrict_section);
539
540 if (NULL == cs)
541 {
542 cs = GNUNET_new (struct ConfigSection);
543 cs->name = GNUNET_strdup (restrict_section);
544 cs->next = cfg->sections;
545 cfg->sections = cs;
546 cs->entries = NULL;
547 }
548 if (cfg->diagnostics)
549 {
550 const char *pwname;
551 const char *grname;
552 char *sfn = GNUNET_STRINGS_filename_expand (inline_path);
553 struct stat istat;
554
555 cs->hint_secret_filename = sfn;
556 if (0 == stat (sfn, &istat))
557 {
558 struct passwd *pw = getpwuid (istat.st_uid);
559 struct group *gr = getgrgid (istat.st_gid);
560 pwname = (NULL == pw) ? "<unknown>" : pw->pw_name;
561 grname = (NULL == gr) ? "<unknown>" : gr->gr_name;
562
564 "%s:%s %o",
565 pwname,
566 grname,
567 istat.st_mode);
568 }
569 else
570 {
571 cs->hint_secret_stat = GNUNET_strdup ("<can't stat file>");
572 }
573 if (source_filename)
574 {
575 /* Possible that this secret section has been inlined before */
577 cs->hint_inlined_from_filename = GNUNET_strdup (source_filename);
578 cs->hint_inlined_from_line = source_lineno;
579 }
580 }
581
582 /* Put file in the load list for diagnostics, even if we can't access it. */
583 {
585 cf->source_filename = GNUNET_strdup (inline_path);
586 cf->hint_restrict_section = GNUNET_strdup (restrict_section);
589 cf);
590 }
591
592 if (GNUNET_OK != inner_ret)
593 {
594 cs->inaccessible = true;
595 cf->hint_inaccessible = true;
596 /* File can't be accessed, but that's okay. */
597 fun_ret = GNUNET_OK;
598 goto cleanup;
599 }
600
601 other_cfg = GNUNET_CONFIGURATION_create (cfg->pd);
602 other_cfg->restrict_section = restrict_section;
603 inner_ret = GNUNET_CONFIGURATION_parse (other_cfg,
604 inline_path);
605 if (GNUNET_OK != inner_ret)
606 {
607 cf->hint_inaccessible = true;
608 fun_ret = inner_ret;
609 goto cleanup;
610 }
611
612 cs = find_section (other_cfg,
613 restrict_section);
614 if (NULL == cs)
615 {
617 "Configuration file '%s' loaded with @inline-secret@ "
618 "does not contain section '%s'.\n",
619 inline_path,
620 restrict_section);
621 /* Inlined onfiguration is accessible but doesn't contain any values.
622 We treat this as if the inlined section was empty, and do not
623 consider it an error. */
624 fun_ret = GNUNET_OK;
625 goto cleanup;
626 }
627 for (struct ConfigEntry *ce = cs->entries;
628 NULL != ce;
629 ce = ce->next)
631 restrict_section,
632 ce->key,
633 ce->val);
634 fun_ret = GNUNET_OK;
635 }
636 else if (GNUNET_OK !=
638 inline_path))
639 {
640 fun_ret = GNUNET_SYSERR;
641 goto cleanup;
642 }
643 else
644 {
645 fun_ret = GNUNET_OK;
646 }
647cleanup:
648 cfg->current_nest_level = old_nest_level;
649 if (NULL != other_cfg)
651 GNUNET_free (inline_path);
652 if (igc.files_length > 0)
653 {
654 for (size_t i = 0; i < igc.files_length; i++)
655 GNUNET_free (igc.files[i]);
657 }
658 return fun_ret;
659}
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:130
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:988
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test_read(const char *fil)
Check that fil corresponds to a filename and the file has read permissions.
Definition: disk.c:513
#define 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 671 of file configuration.c.

674{
675 struct ConfigSection *sec;
676 struct ConfigEntry *pos;
677
678 if (NULL == (sec = find_section (cfg, section)))
679 return NULL;
680 if (sec->inaccessible)
681 {
683 "Section '%s' is marked as inaccessible, because the configuration "
684 " file that contains the section can't be read. Attempts to use "
685 "option '%s' will fail.\n",
686 section,
687 key);
688 return NULL;
689 }
690 pos = sec->entries;
691 while ((pos != NULL) && (0 != strcasecmp (key, pos->key)))
692 pos = pos->next;
693 return pos;
694}
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 707 of file configuration.c.

712{
713 struct ConfigEntry *e = find_entry (cfg, section, option);
714 if (! cfg->diagnostics)
715 return;
716 if (! e)
717 return;
719 e->hint_lineno = hint_line;
720}
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 1122 of file configuration.c.

1124{
1125 if (0 != strcasecmp ("PATHS",
1126 sec))
1127 return false;
1128 return ( (0 == strcasecmp ("DATADIR",
1129 key)) ||
1130 (0 == strcasecmp ("LIBDIR",
1131 key)) ||
1132 (0 == strcasecmp ("BINDIR",
1133 key)) ||
1134 (0 == strcasecmp ("PREFIX",
1135 key)) ||
1136 (0 == strcasecmp ("LOCALEDIR",
1137 key)) ||
1138 (0 == strcasecmp ("ICONDIR",
1139 key)) ||
1140 (0 == strcasecmp ("DOCDIR",
1141 key)) ||
1142 (0 == strcasecmp ("DEFAULTCONFIG",
1143 key)) ||
1144 (0 == strcasecmp ("LIBEXECDIR",
1145 key)) );
1146}

References key.

Referenced by GNUNET_CONFIGURATION_serialize(), and GNUNET_CONFIGURATION_serialize_diagnostics().

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

1541{
1542 struct GNUNET_CONFIGURATION_Handle *dst = cls;
1543
1545 section,
1546 option,
1547 value);
1548}
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 1576 of file configuration.c.

1580{
1581 struct DiffHandle *dh = cls;
1582 struct ConfigEntry *entNew;
1583
1584 entNew = find_entry (dh->cfg_default, section, option);
1585 if ((NULL != entNew) && (NULL != entNew->val) &&
1586 (0 == strcmp (entNew->val, value)))
1587 return;
1589 section,
1590 option,
1591 value);
1592}
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 1922 of file configuration.c.

1925{
1926 char *prefix;
1927 char *result;
1928 char *start;
1929 const char *post;
1930 const char *env;
1931 char *def;
1932 char *end;
1933 unsigned int lopen;
1934 char erased_char;
1935 char *erased_pos;
1936 size_t len;
1937
1938 if (NULL == orig)
1939 return NULL;
1940 if (depth > 128)
1941 {
1943 "Recursive expansion suspected, aborting $-expansion for term `%s'\n",
1944 orig);
1945 return orig;
1946 }
1948 "Asked to $-expand %s\n",
1949 orig);
1950 if ('$' != orig[0])
1951 {
1953 "Doesn't start with $ - not expanding\n");
1954 return orig;
1955 }
1956 erased_char = 0;
1957 erased_pos = NULL;
1958 if ('{' == orig[1])
1959 {
1960 start = &orig[2];
1961 lopen = 1;
1962 end = &orig[1];
1963 while (lopen > 0)
1964 {
1965 end++;
1966 switch (*end)
1967 {
1968 case '}':
1969 lopen--;
1970 break;
1971
1972 case '{':
1973 lopen++;
1974 break;
1975
1976 case '\0':
1978 "Missing closing `}' in option `%s'\n",
1979 orig);
1980 return orig;
1981
1982 default:
1983 break;
1984 }
1985 }
1986 erased_char = *end;
1987 erased_pos = end;
1988 *end = '\0';
1989 post = end + 1;
1990 def = strchr (orig, ':');
1991 if (NULL != def)
1992 {
1993 *def = '\0';
1994 def++;
1995 if (('-' == *def) || ('=' == *def))
1996 def++;
1997 def = GNUNET_strdup (def);
1998 }
1999 }
2000 else
2001 {
2002 int i;
2003
2004 start = &orig[1];
2005 def = NULL;
2006 i = 0;
2007 while ( (orig[i] != '/') &&
2008 (orig[i] != '\\') &&
2009 (orig[i] != '\0') &&
2010 (orig[i] != ' ') )
2011 i++;
2012 if (orig[i] == '\0')
2013 {
2014 post = "";
2015 }
2016 else
2017 {
2018 erased_char = orig[i];
2019 erased_pos = &orig[i];
2020 orig[i] = '\0';
2021 post = &orig[i + 1];
2022 }
2023 }
2025 "Split into `%s' and `%s' with default %s\n",
2026 start,
2027 post,
2028 def);
2029 if (GNUNET_OK !=
2031 "PATHS",
2032 start,
2033 &prefix))
2034 {
2035 if (NULL == (env = getenv (start)))
2036 {
2037 /* try default */
2038 def = expand_dollar (cfg,
2039 def,
2040 depth + 1);
2041 env = def;
2042 }
2043 if (NULL == env)
2044 {
2046 if (erased_pos)
2047 *erased_pos = erased_char;
2049 "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n",
2050 start,
2051 orig);
2053 return orig;
2054 }
2056 }
2058 prefix);
2059 if ((erased_pos) && ('}' != erased_char))
2060 {
2061 len = strlen (prefix) + 1;
2062 prefix = GNUNET_realloc (prefix, len + 1);
2063 prefix[len - 1] = erased_char;
2064 prefix[len] = '\0';
2065 }
2066 result = GNUNET_malloc (strlen (prefix) + strlen (post) + 1);
2067 strcpy (result, prefix);
2068 strcat (result, post);
2069 GNUNET_free (def);
2071 GNUNET_free (orig);
2072 return result;
2073}
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 2240 of file configuration.c.

2241{
2242 char *escaped;
2243 const char *rpos;
2244 char *wpos;
2245
2246 escaped = GNUNET_malloc (strlen (value) * 2 + 1);
2247 memset (escaped, 0, strlen (value) * 2 + 1);
2248 rpos = value;
2249 wpos = escaped;
2250 while (rpos[0] != '\0')
2251 {
2252 switch (rpos[0])
2253 {
2254 case '\\':
2255 case ' ':
2256 wpos[0] = '\\';
2257 wpos[1] = rpos[0];
2258 wpos += 2;
2259 break;
2260
2261 default:
2262 wpos[0] = rpos[0];
2263 wpos++;
2264 }
2265 rpos++;
2266 }
2267 return escaped;
2268}

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

2280{
2281 const char *of = cls;
2282
2283 return (0 == strcmp (of, fn))
2285 : GNUNET_OK;
2286}

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

2611{
2612 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
2613
2614 char *value_fn;
2615 char *fn;
2616
2619 section,
2620 option,
2621 &value_fn));
2622 fn = GNUNET_STRINGS_filename_expand (value_fn);
2623 if (NULL == fn)
2624 fn = value_fn;
2625 else
2626 GNUNET_free (value_fn);
2627 fprintf (stdout,
2628 "%s = %s\n",
2629 option,
2630 fn);
2631 GNUNET_free (fn);
2632}
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 2644 of file configuration.c.

2648{
2649 (void) cls;
2650 (void) section;
2651
2652 fprintf (stdout,
2653 "%s = %s\n",
2654 option,
2655 value);
2656}

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

2668{
2669 (void) cls;
2670 fprintf (stdout,
2671 "%s\n",
2672 section);
2673}

Referenced by GNUNET_CONFIGURATION_config_tool_run().

Here is the caller graph for this function: