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

Definition at line 34 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 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 382 of file configuration.c.

384 {
385  struct CollectFilesContext *igc = cls;
386 
388  igc->files_length,
390  return GNUNET_OK;
391 }
static char * filename
@ GNUNET_OK
Definition: gnunet_common.h:95
#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.

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

404 {
405  struct ConfigSection *pos;
406 
407  pos = cfg->sections;
408  while ((pos != NULL) && (0 != strcasecmp (section, pos->name)))
409  pos = pos->next;
410  return pos;
411 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
configuration section
Definition: configuration.c:75
char * name
name of the section
Definition: configuration.c:89
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:79
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 415 of file configuration.c.

416 {
417  return strcmp (*((const char **) a), *((const char **) b));
418 }

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

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

References testconfigure::b.

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

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

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

692 {
693  struct ConfigEntry *e = find_entry (cfg, section, option);
694  if (! cfg->diagnostics)
695  return;
696  if (! e)
697  return;
698  e->hint_filename = GNUNET_strdup (hint_filename);
699  e->hint_lineno = hint_line;
700 }
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:62

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

1091 {
1092  if (0 != strcasecmp ("PATHS",
1093  sec))
1094  return false;
1095  return ( (0 == strcasecmp ("DATADIR",
1096  key)) ||
1097  (0 == strcasecmp ("LIBDIR",
1098  key)) ||
1099  (0 == strcasecmp ("BINDIR",
1100  key)) ||
1101  (0 == strcasecmp ("PREFIX",
1102  key)) ||
1103  (0 == strcasecmp ("LOCALEDIR",
1104  key)) ||
1105  (0 == strcasecmp ("ICONDIR",
1106  key)) ||
1107  (0 == strcasecmp ("DOCDIR",
1108  key)) ||
1109  (0 == strcasecmp ("DEFAULTCONFIG",
1110  key)) ||
1111  (0 == strcasecmp ("LIBEXECDIR",
1112  key)) );
1113 }

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

1506 {
1507  struct GNUNET_CONFIGURATION_Handle *dst = cls;
1508 
1509  GNUNET_CONFIGURATION_set_value_string (dst, section, option, value);
1510 }
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 1535 of file configuration.c.

1539 {
1540  struct DiffHandle *dh = cls;
1541  struct ConfigEntry *entNew;
1542 
1543  entNew = find_entry (dh->cfg_default, section, option);
1544  if ((NULL != entNew) && (NULL != entNew->val) &&
1545  (0 == strcmp (entNew->val, value)))
1546  return;
1547  GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff, section, option, value);
1548 }
char * val
current, committed value
Definition: configuration.c:57
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 1838 of file configuration.c.

1841 {
1842  char *prefix;
1843  char *result;
1844  char *start;
1845  const char *post;
1846  const char *env;
1847  char *def;
1848  char *end;
1849  unsigned int lopen;
1850  char erased_char;
1851  char *erased_pos;
1852  size_t len;
1853 
1854  if (NULL == orig)
1855  return NULL;
1856  if (depth > 128)
1857  {
1859  _ (
1860  "Recursive expansion suspected, aborting $-expansion for term `%s'\n"),
1861  orig);
1862  return orig;
1863  }
1864  LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to $-expand %s\n", orig);
1865  if ('$' != orig[0])
1866  {
1867  LOG (GNUNET_ERROR_TYPE_DEBUG, "Doesn't start with $ - not expanding\n");
1868  return orig;
1869  }
1870  erased_char = 0;
1871  erased_pos = NULL;
1872  if ('{' == orig[1])
1873  {
1874  start = &orig[2];
1875  lopen = 1;
1876  end = &orig[1];
1877  while (lopen > 0)
1878  {
1879  end++;
1880  switch (*end)
1881  {
1882  case '}':
1883  lopen--;
1884  break;
1885 
1886  case '{':
1887  lopen++;
1888  break;
1889 
1890  case '\0':
1892  _ ("Missing closing `%s' in option `%s'\n"),
1893  "}",
1894  orig);
1895  return orig;
1896 
1897  default:
1898  break;
1899  }
1900  }
1901  erased_char = *end;
1902  erased_pos = end;
1903  *end = '\0';
1904  post = end + 1;
1905  def = strchr (orig, ':');
1906  if (NULL != def)
1907  {
1908  *def = '\0';
1909  def++;
1910  if (('-' == *def) || ('=' == *def))
1911  def++;
1912  def = GNUNET_strdup (def);
1913  }
1914  }
1915  else
1916  {
1917  int i;
1918 
1919  start = &orig[1];
1920  def = NULL;
1921  i = 0;
1922  while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0') &&
1923  (orig[i] != ' '))
1924  i++;
1925  if (orig[i] == '\0')
1926  {
1927  post = "";
1928  }
1929  else
1930  {
1931  erased_char = orig[i];
1932  erased_pos = &orig[i];
1933  orig[i] = '\0';
1934  post = &orig[i + 1];
1935  }
1936  }
1938  "Split into `%s' and `%s' with default %s\n",
1939  start,
1940  post,
1941  def);
1942  if (GNUNET_OK !=
1944  {
1945  if (NULL == (env = getenv (start)))
1946  {
1947  /* try default */
1948  def = expand_dollar (cfg, def, depth + 1);
1949  env = def;
1950  }
1951  if (NULL == env)
1952  {
1954  if (erased_pos)
1955  *erased_pos = erased_char;
1957  _ (
1958  "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n"),
1959  start,
1960  orig);
1961  GNUNET_free (start);
1962  return orig;
1963  }
1964  prefix = GNUNET_strdup (env);
1965  }
1967  if ((erased_pos) && ('}' != erased_char))
1968  {
1969  len = strlen (prefix) + 1;
1970  prefix = GNUNET_realloc (prefix, len + 1);
1971  prefix[len - 1] = erased_char;
1972  prefix[len] = '\0';
1973  }
1974  result = GNUNET_malloc (strlen (prefix) + strlen (post) + 1);
1975  strcpy (result, prefix);
1976  strcat (result, post);
1977  GNUNET_free (def);
1978  GNUNET_free (prefix);
1979  GNUNET_free (orig);
1980  return result;
1981 }
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:53
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.
#define _(String)
GNU gettext support macro.
Definition: platform.h:177

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

2130 {
2131  char *escaped;
2132  const char *rpos;
2133  char *wpos;
2134 
2135  escaped = GNUNET_malloc (strlen (value) * 2 + 1);
2136  memset (escaped, 0, strlen (value) * 2 + 1);
2137  rpos = value;
2138  wpos = escaped;
2139  while (rpos[0] != '\0')
2140  {
2141  switch (rpos[0])
2142  {
2143  case '\\':
2144  case ' ':
2145  wpos[0] = '\\';
2146  wpos[1] = rpos[0];
2147  wpos += 2;
2148  break;
2149 
2150  default:
2151  wpos[0] = rpos[0];
2152  wpos++;
2153  }
2154  rpos++;
2155  }
2156  return escaped;
2157 }

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

2169 {
2170  const char *of = cls;
2171 
2172  return (0 == strcmp (of, fn)) ? GNUNET_SYSERR : GNUNET_OK;
2173 }