GNUnet  0.20.0
configuration.c File Reference

configuration management More...

#include "gnunet_common.h"
#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 ()
 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 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)
 
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 (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...
 
enum GNUNET_GenericReturnValue 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__)

Definition at line 31 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 33 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 308 of file configuration.c.

381 {
382  struct CollectFilesContext *igc = cls;
383 
385  igc->files_length,
387  return GNUNET_OK;
388 }
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 cfg, GNUNET_CONFIGURATION_remove_section(), GNUNET_CONTAINER_DLL_remove, GNUNET_free, ConfigFile::hint_restrict_section, GNUNET_CONFIGURATION_Handle::loaded_files_head, GNUNET_CONFIGURATION_Handle::loaded_files_tail, GNUNET_CONFIGURATION_Handle::main_filename, ConfigSection::name, GNUNET_CONFIGURATION_Handle::sections, and ConfigFile::source_filename.

Here is the call 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 399 of file configuration.c.

401 {
402  struct ConfigSection *pos;
403 
404  pos = cfg->sections;
405  while ((pos != NULL) && (0 != strcasecmp (section, pos->name)))
406  pos = pos->next;
407  return pos;
408 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
configuration section
Definition: configuration.c:72
char * name
name of the section
Definition: configuration.c:86
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:76
struct ConfigSection * sections
Configuration sections.

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

Referenced by find_entry(), and GNUNET_CONFIGURATION_set_value_string().

Here is the caller graph for this function:

◆ pstrcmp()

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

Definition at line 412 of file configuration.c.

413 {
414  return strcmp (*((const char **) a), *((const char **) b));
415 }

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

430 {
431  char *inline_path = NULL;
432  struct GNUNET_CONFIGURATION_Handle *other_cfg = NULL;
433  struct CollectFilesContext igc = {
434  .files = NULL,
435  .files_length = 0,
436  };
437  enum GNUNET_GenericReturnValue fun_ret;
438  unsigned int old_nest_level = cfg->current_nest_level++;
439 
440  /* We support the section restriction only for non-globs */
441  GNUNET_assert (! (path_is_glob && (NULL != restrict_section)));
442 
443  if (NULL == source_filename)
444  {
446  "Refusing to parse inline configurations, "
447  "not allowed without source filename!\n");
448  fun_ret = GNUNET_SYSERR;
449  goto cleanup;
450  }
451 
452  if ('/' == *path_or_glob)
453  inline_path = GNUNET_strdup (path_or_glob);
454  else
455  {
456  /* We compute the canonical, absolute path first,
457  so that relative imports resolve properly with symlinked
458  config files. */
459  char *source_realpath;
460  char *endsep;
461 
462  source_realpath = realpath (source_filename,
463  NULL);
464  if (NULL == source_realpath)
465  {
466  /* Couldn't even resolve path of base dir. */
467  GNUNET_break (0);
468  /* failed to parse included config */
469  fun_ret = GNUNET_SYSERR;
470  goto cleanup;
471  }
472  endsep = strrchr (source_realpath, '/');
473  GNUNET_assert (NULL != endsep);
474  *endsep = '\0';
475  GNUNET_asprintf (&inline_path,
476  "%s/%s",
477  source_realpath,
478  path_or_glob);
479  free (source_realpath);
480  }
481 
482  if (path_is_glob)
483  {
484  int nret;
485 
487  "processing config glob '%s'\n",
488  inline_path);
489 
490  nret = GNUNET_DISK_glob (inline_path, collect_files_cb, &igc);
491  if (-1 == nret)
492  {
493  fun_ret = GNUNET_SYSERR;
494  goto cleanup;
495  }
496  GNUNET_assert (nret == igc.files_length);
497  qsort (igc.files, igc.files_length, sizeof (char *), pstrcmp);
498  for (int i = 0; i < nret; i++)
499  {
500  if (GNUNET_OK !=
502  igc.files[i]))
503  {
504  fun_ret = GNUNET_SYSERR;
505  goto cleanup;
506  }
507  }
508  fun_ret = GNUNET_OK;
509  }
510  else if (NULL != restrict_section)
511  {
512  enum GNUNET_GenericReturnValue inner_ret;
513  struct ConfigSection *cs;
514  struct ConfigFile *cf = GNUNET_new (struct ConfigFile);
515 
516  inner_ret = GNUNET_DISK_file_test_read (inline_path);
517 
518  cs = find_section (cfg, restrict_section);
519 
520  if (NULL == cs)
521  {
522  cs = GNUNET_new (struct ConfigSection);
523  cs->name = GNUNET_strdup (restrict_section);
524  cs->next = cfg->sections;
525  cfg->sections = cs;
526  cs->entries = NULL;
527  }
528  if (cfg->diagnostics)
529  {
530  char *sfn = GNUNET_STRINGS_filename_expand (inline_path);
531  struct stat istat;
532 
533  cs->hint_secret_filename = sfn;
534  if (0 == stat (sfn, &istat))
535  {
536  struct passwd *pw = getpwuid (istat.st_uid);
537  struct group *gr = getgrgid (istat.st_gid);
538  char *pwname = (NULL == pw) ? "<unknown>" : pw->pw_name;
539  char *grname = (NULL == gr) ? "<unknown>" : gr->gr_name;
540 
542  "%s:%s %o",
543  pwname,
544  grname,
545  istat.st_mode);
546  }
547  else
548  {
549  cs->hint_secret_stat = GNUNET_strdup ("<can't stat file>");
550  }
551  if (source_filename)
552  {
553  /* Possible that this secret section has been inlined before */
555  cs->hint_inlined_from_filename = GNUNET_strdup (source_filename);
556  cs->hint_inlined_from_line = source_lineno;
557  }
558  }
559 
560  /* Put file in the load list for diagnostics, even if we can't access it. */
561  {
563  cf->source_filename = GNUNET_strdup (inline_path);
564  cf->hint_restrict_section = GNUNET_strdup (restrict_section);
567  cf);
568  }
569 
570  if (GNUNET_OK != inner_ret)
571  {
572  cs->inaccessible = true;
573  cf->hint_inaccessible = true;
574  /* File can't be accessed, but that's okay. */
575  fun_ret = GNUNET_OK;
576  goto cleanup;
577  }
578 
579  other_cfg = GNUNET_CONFIGURATION_create ();
580  other_cfg->restrict_section = restrict_section;
581  inner_ret = GNUNET_CONFIGURATION_parse (other_cfg,
582  inline_path);
583  if (GNUNET_OK != inner_ret)
584  {
585  cf->hint_inaccessible = true;
586  fun_ret = inner_ret;
587  goto cleanup;
588  }
589 
590  cs = find_section (other_cfg, restrict_section);
591  if (NULL == cs)
592  {
594  "Configuration file '%s' loaded with @inline-secret@ "
595  "does not contain section '%s'.\n",
596  inline_path,
597  restrict_section);
598  /* Inlined onfiguration is accessible but doesn't contain any values.
599  We treat this as if the inlined section was empty, and do not
600  consider it an error. */
601  fun_ret = GNUNET_OK;
602  goto cleanup;
603  }
604  for (struct ConfigEntry *ce = cs->entries;
605  NULL != ce;
606  ce = ce->next)
608  restrict_section,
609  ce->key,
610  ce->val);
611  fun_ret = GNUNET_OK;
612  }
613  else if (GNUNET_OK !=
615  inline_path))
616  {
617  fun_ret = GNUNET_SYSERR;
618  goto cleanup;
619  }
620  else
621  {
622  fun_ret = GNUNET_OK;
623  }
624 cleanup:
625  cfg->current_nest_level = old_nest_level;
626  if (NULL != other_cfg)
627  GNUNET_CONFIGURATION_destroy (other_cfg);
628  GNUNET_free (inline_path);
629  if (igc.files_length > 0)
630  {
631  for (size_t i = 0; i < igc.files_length; i++)
632  GNUNET_free (igc.files[i]);
633  GNUNET_array_grow (igc.files, igc.files_length, 0);
634  }
635  return fun_ret;
636 }
static int pstrcmp(const void *a, const void *b)
static struct ConfigSection * find_section(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Find a section entry from a configuration.
static enum GNUNET_GenericReturnValue collect_files_cb(void *cls, const char *filename)
Function called with a filename.
#define LOG(kind,...)
Definition: configuration.c:31
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
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 GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create()
Create a new configuration object.
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:1009
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test_read(const char *fil)
Check that fil corresponds to a filename and the file has read permissions.
Definition: disk.c:489
#define 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:494
configuration entry
Definition: configuration.c:40
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:44
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:81
bool inaccessible
Is the configuration section marked as inaccessible?
Definition: configuration.c:94
char * hint_secret_filename
Diagnostics hint for the secret file.
Definition: configuration.c:99
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.
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...

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

651 {
652  struct ConfigSection *sec;
653  struct ConfigEntry *pos;
654 
655  if (NULL == (sec = find_section (cfg, section)))
656  return NULL;
657  if (sec->inaccessible)
658  {
660  "Section '%s' is marked as inaccessible, because the configuration "
661  " file that contains the section can't be read. Attempts to use "
662  "option '%s' will fail.\n",
663  section,
664  key);
665  return NULL;
666  }
667  pos = sec->entries;
668  while ((pos != NULL) && (0 != strcasecmp (key, pos->key)))
669  pos = pos->next;
670  return pos;
671 }
struct GNUNET_HashCode key
The key used in the DHT.
@ GNUNET_ERROR_TYPE_WARNING
char * key
key for this entry
Definition: configuration.c:49

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_deserialize(), and GNUNET_CONFIGURATION_set_value_string().

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

689 {
690  struct ConfigEntry *e = find_entry (cfg, section, option);
691  if (! cfg->diagnostics)
692  return;
693  if (! e)
694  return;
695  e->hint_filename = GNUNET_strdup (hint_filename);
696  e->hint_lineno = hint_line;
697 }
static struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
static struct Experiment * e
char * hint_filename
Diagnostics information for the filename.
Definition: configuration.c:59

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

1103 {
1104  if (0 != strcasecmp ("PATHS",
1105  sec))
1106  return false;
1107  return ( (0 == strcasecmp ("DATADIR",
1108  key)) ||
1109  (0 == strcasecmp ("LIBDIR",
1110  key)) ||
1111  (0 == strcasecmp ("BINDIR",
1112  key)) ||
1113  (0 == strcasecmp ("PREFIX",
1114  key)) ||
1115  (0 == strcasecmp ("LOCALEDIR",
1116  key)) ||
1117  (0 == strcasecmp ("ICONDIR",
1118  key)) ||
1119  (0 == strcasecmp ("DOCDIR",
1120  key)) ||
1121  (0 == strcasecmp ("DEFAULTCONFIG",
1122  key)) ||
1123  (0 == strcasecmp ("LIBEXECDIR",
1124  key)) );
1125 }

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

1518 {
1519  struct GNUNET_CONFIGURATION_Handle *dst = cls;
1520 
1522  section,
1523  option,
1524  value);
1525 }
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 1550 of file configuration.c.

1554 {
1555  struct DiffHandle *dh = cls;
1556  struct ConfigEntry *entNew;
1557 
1558  entNew = find_entry (dh->cfg_default, section, option);
1559  if ((NULL != entNew) && (NULL != entNew->val) &&
1560  (0 == strcmp (entNew->val, value)))
1561  return;
1563  section,
1564  option,
1565  value);
1566 }
char * val
current, committed value
Definition: configuration.c:54
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 1862 of file configuration.c.

1865 {
1866  char *prefix;
1867  char *result;
1868  char *start;
1869  const char *post;
1870  const char *env;
1871  char *def;
1872  char *end;
1873  unsigned int lopen;
1874  char erased_char;
1875  char *erased_pos;
1876  size_t len;
1877 
1878  if (NULL == orig)
1879  return NULL;
1880  if (depth > 128)
1881  {
1883  "Recursive expansion suspected, aborting $-expansion for term `%s'\n",
1884  orig);
1885  return orig;
1886  }
1888  "Asked to $-expand %s\n",
1889  orig);
1890  if ('$' != orig[0])
1891  {
1893  "Doesn't start with $ - not expanding\n");
1894  return orig;
1895  }
1896  erased_char = 0;
1897  erased_pos = NULL;
1898  if ('{' == orig[1])
1899  {
1900  start = &orig[2];
1901  lopen = 1;
1902  end = &orig[1];
1903  while (lopen > 0)
1904  {
1905  end++;
1906  switch (*end)
1907  {
1908  case '}':
1909  lopen--;
1910  break;
1911 
1912  case '{':
1913  lopen++;
1914  break;
1915 
1916  case '\0':
1918  "Missing closing `}' in option `%s'\n",
1919  orig);
1920  return orig;
1921 
1922  default:
1923  break;
1924  }
1925  }
1926  erased_char = *end;
1927  erased_pos = end;
1928  *end = '\0';
1929  post = end + 1;
1930  def = strchr (orig, ':');
1931  if (NULL != def)
1932  {
1933  *def = '\0';
1934  def++;
1935  if (('-' == *def) || ('=' == *def))
1936  def++;
1937  def = GNUNET_strdup (def);
1938  }
1939  }
1940  else
1941  {
1942  int i;
1943 
1944  start = &orig[1];
1945  def = NULL;
1946  i = 0;
1947  while ( (orig[i] != '/') &&
1948  (orig[i] != '\\') &&
1949  (orig[i] != '\0') &&
1950  (orig[i] != ' ') )
1951  i++;
1952  if (orig[i] == '\0')
1953  {
1954  post = "";
1955  }
1956  else
1957  {
1958  erased_char = orig[i];
1959  erased_pos = &orig[i];
1960  orig[i] = '\0';
1961  post = &orig[i + 1];
1962  }
1963  }
1965  "Split into `%s' and `%s' with default %s\n",
1966  start,
1967  post,
1968  def);
1969  if (GNUNET_OK !=
1971  "PATHS",
1972  start,
1973  &prefix))
1974  {
1975  if (NULL == (env = getenv (start)))
1976  {
1977  /* try default */
1978  def = expand_dollar (cfg,
1979  def,
1980  depth + 1);
1981  env = def;
1982  }
1983  if (NULL == env)
1984  {
1986  if (erased_pos)
1987  *erased_pos = erased_char;
1989  "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n",
1990  start,
1991  orig);
1992  GNUNET_free (start);
1993  return orig;
1994  }
1995  prefix = GNUNET_strdup (env);
1996  }
1998  prefix);
1999  if ((erased_pos) && ('}' != erased_char))
2000  {
2001  len = strlen (prefix) + 1;
2002  prefix = GNUNET_realloc (prefix, len + 1);
2003  prefix[len - 1] = erased_char;
2004  prefix[len] = '\0';
2005  }
2006  result = GNUNET_malloc (strlen (prefix) + strlen (post) + 1);
2007  strcpy (result, prefix);
2008  strcat (result, post);
2009  GNUNET_free (def);
2010  GNUNET_free (prefix);
2011  GNUNET_free (orig);
2012  return result;
2013 }
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:39
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
static int prefix
If printing the value of PREFIX has been requested.
Definition: gnunet-config.c:59
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
static int result
Global testing status.
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_malloc(size)
Wrapper around malloc.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.

References cfg, 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, prefix, result, and start.

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

2162 {
2163  char *escaped;
2164  const char *rpos;
2165  char *wpos;
2166 
2167  escaped = GNUNET_malloc (strlen (value) * 2 + 1);
2168  memset (escaped, 0, strlen (value) * 2 + 1);
2169  rpos = value;
2170  wpos = escaped;
2171  while (rpos[0] != '\0')
2172  {
2173  switch (rpos[0])
2174  {
2175  case '\\':
2176  case ' ':
2177  wpos[0] = '\\';
2178  wpos[1] = rpos[0];
2179  wpos += 2;
2180  break;
2181 
2182  default:
2183  wpos[0] = rpos[0];
2184  wpos++;
2185  }
2186  rpos++;
2187  }
2188  return escaped;
2189 }

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

2201 {
2202  const char *of = cls;
2203 
2204  return (0 == strcmp (of, fn)) ? GNUNET_SYSERR : GNUNET_OK;
2205 }