GNUnet  0.11.x
Data Structures | Macros | Functions
configuration.c File Reference

configuration management More...

#include "platform.h"
#include "gnunet_crypto_lib.h"
#include "gnunet_strings_lib.h"
#include "gnunet_os_lib.h"
#include "gnunet_configuration_lib.h"
#include "gnunet_disk_lib.h"
#include "gnunet_buffer_lib.h"
#include "gnunet_container_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 ()
 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 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 int 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)
 
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_Section_Iterator iter, void *iter_cls)
 Iterate over all sections in the configuration. More...
 
void GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
 Remove the given section and all options in it. More...
 
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 (void)
 Return the filename of the default configuration filename that is used when no explicit configuration entry point has been specified. More...
 
struct GNUNET_CONFIGURATION_HandleGNUNET_CONFIGURATION_default (void)
 Return GNUnet's default configuration. More...
 
int GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
 Load configuration (starts with defaults, then loads system-specific configuration). More...
 

Detailed Description

configuration management

Author
Christian Grothoff

Definition in file configuration.c.

Macro Definition Documentation

◆ LOG

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

◆ LOG_STRERROR_FILE

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

Definition at line 36 of file configuration.c.

Function Documentation

◆ collect_files_cb()

static int 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 378 of file configuration.c.

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

Referenced by GNUNET_CONFIGURATION_load_from(), and handle_inline().

380 {
381  struct CollectFilesContext *igc = cls;
382 
384  igc->files_length,
386  return GNUNET_OK;
387 }
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
unsigned int files_length
Size of the files array.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static char * filename
char ** files
Collected files from globbing.
Closure to collect_files_cb.
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 398 of file configuration.c.

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

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

400 {
401  struct ConfigSection *pos;
402 
403  pos = cfg->sections;
404  while ((pos != NULL) && (0 != strcasecmp (section, pos->name)))
405  pos = pos->next;
406  return pos;
407 }
static char * section
Name of the section.
Definition: gnunet-config.c:33
char * name
name of the section
Definition: configuration.c:89
struct ConfigSection * sections
Configuration sections.
configuration section
Definition: configuration.c:74
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:79
Here is the caller graph for this function:

◆ pstrcmp()

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

Definition at line 411 of file configuration.c.

Referenced by GNUNET_CONFIGURATION_load_from(), and handle_inline().

412 {
413  return strcmp (*((const char **) a), *((const char **) b));
414 }
Here is the caller graph for this function:

◆ handle_inline()

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.

Returns
GNUNET_SYSERR on error, GNUNET_OK otherwise

Definition at line 423 of file configuration.c.

References 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_ERROR, 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, pstrcmp(), GNUNET_CONFIGURATION_Handle::restrict_section, GNUNET_CONFIGURATION_Handle::sections, and ConfigFile::source_filename.

Referenced by GNUNET_CONFIGURATION_deserialize().

429 {
430  char *inline_path;
431  struct GNUNET_CONFIGURATION_Handle *other_cfg = NULL;
432  struct CollectFilesContext igc = {
433  .files = NULL,
434  .files_length = 0,
435  };
436  enum GNUNET_GenericReturnValue fun_ret;
437  unsigned int old_nest_level = cfg->current_nest_level++;
438 
439  /* We support the section restriction only for non-globs */
440  GNUNET_assert (! (path_is_glob && (NULL != restrict_section)));
441 
442  if (NULL == source_filename)
443  {
445  "Refusing to parse inline configurations, "
446  "not allowed without source filename!\n");
447  fun_ret = GNUNET_SYSERR;
448  goto cleanup;
449  }
450 
451  if ('/' == *path_or_glob)
452  inline_path = GNUNET_strdup (path_or_glob);
453  else
454  {
455  /* We compute the canonical, absolute path first,
456  so that relative imports resolve properly with symlinked
457  config files. */
458  char *source_realpath;
459  char *endsep;
460 
461  source_realpath = realpath (source_filename,
462  NULL);
463  if (NULL == source_realpath)
464  {
465  /* Couldn't even resolve path of base dir. */
466  GNUNET_break (0);
467  /* failed to parse included config */
468  fun_ret = GNUNET_SYSERR;
469  goto cleanup;
470  }
471  endsep = strrchr (source_realpath, '/');
472  GNUNET_assert (NULL != endsep);
473  *endsep = '\0';
474  GNUNET_asprintf (&inline_path,
475  "%s/%s",
476  source_realpath,
477  path_or_glob);
478  free (source_realpath);
479  }
480 
481  if (path_is_glob)
482  {
483  int nret;
484 
486  "processing config glob '%s'\n",
487  inline_path);
488 
489  nret = GNUNET_DISK_glob (inline_path, collect_files_cb, &igc);
490  if (-1 == nret)
491  {
492  fun_ret = GNUNET_SYSERR;
493  goto cleanup;
494  }
495  GNUNET_assert (nret == igc.files_length);
496  qsort (igc.files, igc.files_length, sizeof (char *), pstrcmp);
497  for (int i = 0; i < nret; i++)
498  {
499  if (GNUNET_OK !=
501  igc.files[i]))
502  {
503  fun_ret = GNUNET_SYSERR;
504  goto cleanup;
505  }
506  }
507  fun_ret = GNUNET_OK;
508  }
509  else if (NULL != restrict_section)
510  {
511  enum GNUNET_GenericReturnValue inner_ret;
512  struct ConfigSection *cs;
513  struct ConfigFile *cf = GNUNET_new (struct ConfigFile);
514 
515  inner_ret = GNUNET_DISK_file_test_read (inline_path);
516 
517  cs = find_section (cfg, restrict_section);
518 
519  if (NULL == cs)
520  {
521  cs = GNUNET_new (struct ConfigSection);
522  cs->name = GNUNET_strdup (restrict_section);
523  cs->next = cfg->sections;
524  cfg->sections = cs;
525  cs->entries = NULL;
526  }
527  if (cfg->diagnostics)
528  {
529  char *sfn = GNUNET_STRINGS_filename_expand (inline_path);
530  struct stat istat;
531 
532  cs->hint_secret_filename = sfn;
533  if (0 == stat (sfn, &istat))
534  {
535  struct passwd *pw = getpwuid (istat.st_uid);
536  struct group *gr = getgrgid (istat.st_gid);
537  char *pwname = (NULL == pw) ? "<unknown>" : pw->pw_name;
538  char *grname = (NULL == gr) ? "<unknown>" : gr->gr_name;
539 
541  "%s:%s %o",
542  pwname,
543  grname,
544  istat.st_mode);
545  }
546  else
547  {
548  cs->hint_secret_stat = GNUNET_strdup ("<can't stat file>");
549  }
550  if (source_filename)
551  {
552  /* Possible that this secret section has been inlined before */
554  cs->hint_inlined_from_filename = GNUNET_strdup (source_filename);
555  cs->hint_inlined_from_line = source_lineno;
556  }
557  }
558 
559  /* Put file in the load list for diagnostics, even if we can't access it. */
560  {
561  cf->level = cfg->current_nest_level;
562  cf->source_filename = GNUNET_strdup (inline_path);
563  cf->hint_restrict_section = GNUNET_strdup (restrict_section);
565  cfg->loaded_files_tail,
566  cf);
567  }
568 
569  if (GNUNET_OK != inner_ret)
570  {
571  cs->inaccessible = true;
572  cf->hint_inaccessible = true;
573  /* File can't be accessed, but that's okay. */
574  fun_ret = GNUNET_OK;
575  goto cleanup;
576  }
577 
578  other_cfg = GNUNET_CONFIGURATION_create ();
579  other_cfg->restrict_section = restrict_section;
580  inner_ret = GNUNET_CONFIGURATION_parse (other_cfg,
581  inline_path);
582  if (GNUNET_OK != inner_ret)
583  {
584  cf->hint_inaccessible = true;
585  fun_ret = inner_ret;
586  goto cleanup;
587  }
588 
589  cs = find_section (other_cfg, restrict_section);
590  if (NULL == cs)
591  {
593  "inlined configuration '%s' does not contain section '%s'\n",
594  inline_path,
595  restrict_section);
596  fun_ret = GNUNET_SYSERR;
597  goto cleanup;
598  }
599  for (struct ConfigEntry *ce = cs->entries;
600  NULL != ce;
601  ce = ce->next)
603  restrict_section,
604  ce->key,
605  ce->val);
606  fun_ret = GNUNET_OK;
607  }
608  else if (GNUNET_OK !=
610  inline_path))
611  {
612  fun_ret = GNUNET_SYSERR;
613  goto cleanup;
614  }
615  else
616  {
617  fun_ret = GNUNET_OK;
618  }
619  cleanup:
620  cfg->current_nest_level = old_nest_level;
621  if (NULL != other_cfg)
622  GNUNET_CONFIGURATION_destroy (other_cfg);
623  GNUNET_free (inline_path);
624  if (igc.files_length > 0)
625  {
626  for (size_t i = 0; i < igc.files_length; i++)
627  GNUNET_free (igc.files[i]);
628  GNUNET_array_grow (igc.files, igc.files_length, 0);
629  }
630  return fun_ret;
631 }
static int collect_files_cb(void *cls, const char *filename)
Function called with a filename.
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
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...
unsigned int level
Level in the tree of loaded config files.
unsigned int files_length
Size of the files array.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
bool diagnostics
Enable diagnostics.
struct ConfigEntry * entries
entries in the section
Definition: configuration.c:84
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:83
configuration entry
Definition: configuration.c:42
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create()
Create a new configuration object.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
char * name
name of the section
Definition: configuration.c:89
unsigned int current_nest_level
Current nesting level of file loading.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
static struct ConfigSection * find_section(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Find a section entry from a configuration.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
int GNUNET_DISK_glob(const char *glob_pattern, GNUNET_FileNameCallback callback, void *callback_cls)
Find all files matching a glob pattern.
Definition: disk.c:1007
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.
struct ConfigSection * sections
Configuration sections.
struct ConfigFile * loaded_files_head
Linked list of loaded files.
#define LOG(kind,...)
Definition: configuration.c:34
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
char * source_filename
Source filename.
unsigned int hint_inlined_from_line
For secret sections: Where was this inlined from?
char * hint_restrict_section
Was this configuration file parsed via -secret@?
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:47
configuration section
Definition: configuration.c:74
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:482
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
bool inaccessible
Is the configuration section marked as inaccessible?
Definition: configuration.c:97
char ** files
Collected files from globbing.
bool hint_inaccessible
Was this configuration file inaccessible?
char * hint_secret_stat
Extra information regarding permissions of the secret file.
configuration data
static int pstrcmp(const void *a, const void *b)
Closure to collect_files_cb.
char * hint_secret_filename
Diagnostics hint for the secret file.
const char * restrict_section
When parsing into this configuration, and this value is non-NULL, only parse sections of the same nam...
struct ConfigFile * loaded_files_tail
Linked list of loaded files.
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:79
#define GNUNET_free(ptr)
Wrapper around free.
char * hint_inlined_from_filename
For secret sections: Where was this inlined from?
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 643 of file configuration.c.

References ConfigSection::entries, find_section(), GNUNET_ERROR_TYPE_WARNING, ConfigSection::inaccessible, 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().

646 {
647  struct ConfigSection *sec;
648  struct ConfigEntry *pos;
649 
650  if (NULL == (sec = find_section (cfg, section)))
651  return NULL;
652  if (sec->inaccessible)
653  {
655  "Section '%s' is marked as inaccessible, because the configuration "
656  " file that contains the section can't be read. Attempts to use "
657  "option '%s' will fail.\n",
658  section,
659  key);
660  return NULL;
661  }
662  pos = sec->entries;
663  while ((pos != NULL) && (0 != strcasecmp (key, pos->key)))
664  pos = pos->next;
665  return pos;
666 }
struct ConfigEntry * entries
entries in the section
Definition: configuration.c:84
configuration entry
Definition: configuration.c:42
static char * section
Name of the section.
Definition: gnunet-config.c:33
static struct ConfigSection * find_section(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Find a section entry from a configuration.
#define LOG(kind,...)
Definition: configuration.c:34
struct GNUNET_HashCode key
The key used in the DHT.
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:47
configuration section
Definition: configuration.c:74
bool inaccessible
Is the configuration section marked as inaccessible?
Definition: configuration.c:97
char * key
key for this entry
Definition: configuration.c:52
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 679 of file configuration.c.

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

Referenced by GNUNET_CONFIGURATION_deserialize().

684 {
685  struct ConfigEntry *e = find_entry (cfg, section, option);
686  if (! cfg->diagnostics)
687  return;
688  if (! e)
689  return;
691  e->hint_lineno = hint_line;
692 }
unsigned int hint_lineno
Diagnostics information for the line number.
Definition: configuration.c:67
bool diagnostics
Enable diagnostics.
static struct Experiment * e
configuration entry
Definition: configuration.c:42
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:62
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static char * section
Name of the section.
Definition: gnunet-config.c:33
static char * option
Name of the option.
Definition: gnunet-config.c:38
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 1080 of file configuration.c.

Referenced by GNUNET_CONFIGURATION_serialize(), and GNUNET_CONFIGURATION_serialize_diagnostics().

1082 {
1083  if (0 != strcasecmp ("PATHS",
1084  sec))
1085  return false;
1086  return ( (0 == strcasecmp ("DATADIR",
1087  key)) ||
1088  (0 == strcasecmp ("LIBDIR",
1089  key)) ||
1090  (0 == strcasecmp ("BINDIR",
1091  key)) ||
1092  (0 == strcasecmp ("PREFIX",
1093  key)) ||
1094  (0 == strcasecmp ("LOCALEDIR",
1095  key)) ||
1096  (0 == strcasecmp ("ICONDIR",
1097  key)) ||
1098  (0 == strcasecmp ("DOCDIR",
1099  key)) ||
1100  (0 == strcasecmp ("DEFAULTCONFIG",
1101  key)) ||
1102  (0 == strcasecmp ("LIBEXECDIR",
1103  key)) );
1104 }
struct GNUNET_HashCode key
The key used in the DHT.
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 1493 of file configuration.c.

References GNUNET_CONFIGURATION_set_value_string().

Referenced by GNUNET_CONFIGURATION_dup().

1497 {
1498  struct GNUNET_CONFIGURATION_Handle *dst = cls;
1499 
1501 }
static char * section
Name of the section.
Definition: gnunet-config.c:33
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
configuration data
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 1526 of file configuration.c.

References DiffHandle::cfg_default, DiffHandle::cfgDiff, find_entry(), GNUNET_CONFIGURATION_set_value_string(), and ConfigEntry::val.

Referenced by GNUNET_CONFIGURATION_get_diff().

1530 {
1531  struct DiffHandle *dh = cls;
1532  struct ConfigEntry *entNew;
1533 
1534  entNew = find_entry (dh->cfg_default, section, option);
1535  if ((NULL != entNew) && (NULL != entNew->val) &&
1536  (0 == strcmp (entNew->val, value)))
1537  return;
1539 }
configuration entry
Definition: configuration.c:42
static struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
struct GNUNET_CONFIGURATION_Handle * cfgDiff
static char * section
Name of the section.
Definition: gnunet-config.c:33
static char * value
Value of the record to add/remove.
static char * option
Name of the option.
Definition: gnunet-config.c:38
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
Used for diffing a configuration object against the default one.
const struct GNUNET_CONFIGURATION_Handle * cfg_default
char * val
current, committed value
Definition: configuration.c:57
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 1829 of file configuration.c.

References _, end, env, 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, len, LOG, result, and start.

Referenced by GNUNET_CONFIGURATION_expand_dollar().

1832 {
1833  char *prefix;
1834  char *result;
1835  char *start;
1836  const char *post;
1837  const char *env;
1838  char *def;
1839  char *end;
1840  unsigned int lopen;
1841  char erased_char;
1842  char *erased_pos;
1843  size_t len;
1844 
1845  if (NULL == orig)
1846  return NULL;
1847  if (depth > 128)
1848  {
1850  _ (
1851  "Recursive expansion suspected, aborting $-expansion for term `%s'\n"),
1852  orig);
1853  return orig;
1854  }
1855  LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to $-expand %s\n", orig);
1856  if ('$' != orig[0])
1857  {
1858  LOG (GNUNET_ERROR_TYPE_DEBUG, "Doesn't start with $ - not expanding\n");
1859  return orig;
1860  }
1861  erased_char = 0;
1862  erased_pos = NULL;
1863  if ('{' == orig[1])
1864  {
1865  start = &orig[2];
1866  lopen = 1;
1867  end = &orig[1];
1868  while (lopen > 0)
1869  {
1870  end++;
1871  switch (*end)
1872  {
1873  case '}':
1874  lopen--;
1875  break;
1876 
1877  case '{':
1878  lopen++;
1879  break;
1880 
1881  case '\0':
1883  _ ("Missing closing `%s' in option `%s'\n"),
1884  "}",
1885  orig);
1886  return orig;
1887 
1888  default:
1889  break;
1890  }
1891  }
1892  erased_char = *end;
1893  erased_pos = end;
1894  *end = '\0';
1895  post = end + 1;
1896  def = strchr (orig, ':');
1897  if (NULL != def)
1898  {
1899  *def = '\0';
1900  def++;
1901  if (('-' == *def) || ('=' == *def))
1902  def++;
1903  def = GNUNET_strdup (def);
1904  }
1905  }
1906  else
1907  {
1908  int i;
1909 
1910  start = &orig[1];
1911  def = NULL;
1912  i = 0;
1913  while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0') &&
1914  (orig[i] != ' '))
1915  i++;
1916  if (orig[i] == '\0')
1917  {
1918  post = "";
1919  }
1920  else
1921  {
1922  erased_char = orig[i];
1923  erased_pos = &orig[i];
1924  orig[i] = '\0';
1925  post = &orig[i + 1];
1926  }
1927  }
1929  "Split into `%s' and `%s' with default %s\n",
1930  start,
1931  post,
1932  def);
1933  if (GNUNET_OK !=
1934  GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", start, &prefix))
1935  {
1936  if (NULL == (env = getenv (start)))
1937  {
1938  /* try default */
1939  def = expand_dollar (cfg, def, depth + 1);
1940  env = def;
1941  }
1942  if (NULL == env)
1943  {
1944  start = GNUNET_strdup (start);
1945  if (erased_pos)
1946  *erased_pos = erased_char;
1948  _ (
1949  "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n"),
1950  start,
1951  orig);
1952  GNUNET_free (start);
1953  return orig;
1954  }
1955  prefix = GNUNET_strdup (env);
1956  }
1957  prefix = GNUNET_CONFIGURATION_expand_dollar (cfg, prefix);
1958  if ((erased_pos) && ('}' != erased_char))
1959  {
1960  len = strlen (prefix) + 1;
1961  prefix = GNUNET_realloc (prefix, len + 1);
1962  prefix[len - 1] = erased_char;
1963  prefix[len] = '\0';
1964  }
1965  result = GNUNET_malloc (strlen (prefix) + strlen (post) + 1);
1966  strcpy (result, prefix);
1967  strcat (result, post);
1968  GNUNET_free (def);
1969  GNUNET_free (prefix);
1970  GNUNET_free (orig);
1971  return result;
1972 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
char * GNUNET_CONFIGURATION_expand_dollar(const struct GNUNET_CONFIGURATION_Handle *cfg, char *orig)
Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" where either in the "PATHS" section or...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
static int result
Global testing status.
#define LOG(kind,...)
Definition: configuration.c:34
char * getenv()
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...
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ escape_name()

static char* escape_name ( const char *  value)
static

FIXME.

Parameters
valueFIXME
Returns
FIXME

Definition at line 2120 of file configuration.c.

References GNUNET_malloc, and value.

Referenced by GNUNET_CONFIGURATION_append_value_filename(), and GNUNET_CONFIGURATION_remove_value_filename().

2121 {
2122  char *escaped;
2123  const char *rpos;
2124  char *wpos;
2125 
2126  escaped = GNUNET_malloc (strlen (value) * 2 + 1);
2127  memset (escaped, 0, strlen (value) * 2 + 1);
2128  rpos = value;
2129  wpos = escaped;
2130  while (rpos[0] != '\0')
2131  {
2132  switch (rpos[0])
2133  {
2134  case '\\':
2135  case ' ':
2136  wpos[0] = '\\';
2137  wpos[1] = rpos[0];
2138  wpos += 2;
2139  break;
2140 
2141  default:
2142  wpos[0] = rpos[0];
2143  wpos++;
2144  }
2145  rpos++;
2146  }
2147  return escaped;
2148 }
static char * value
Value of the record to add/remove.
#define GNUNET_malloc(size)
Wrapper around malloc.
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 2159 of file configuration.c.

References GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_CONFIGURATION_append_value_filename().

2160 {
2161  const char *of = cls;
2162 
2163  return (0 == strcmp (of, fn)) ? GNUNET_SYSERR : GNUNET_OK;
2164 }
static char * fn
Filename of the unique file.
Here is the caller graph for this function: