GNUnet 0.26.2-121-g5a30f508f
 
Loading...
Searching...
No Matches
configuration.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_configuration_lib.h"
Include dependency graph for configuration.c:

Go to the source code of this file.

Data Structures

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

Macros

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

Functions

void GNUNET_CONFIGURATION_enable_diagnostics (struct GNUNET_CONFIGURATION_Handle *cfg)
 Enable extra diagnostics.
 
struct GNUNET_CONFIGURATION_HandleGNUNET_CONFIGURATION_create (const struct GNUNET_OS_ProjectData *pd)
 Create a new configuration object.
 
void GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
 Destroy configuration object.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse_and_run (const struct GNUNET_OS_ProjectData *pd, const char *filename, GNUNET_CONFIGURATION_Callback cb, void *cb_cls)
 Parse a configuration file filename and run the function cb with the resulting configuration object.
 
static enum GNUNET_GenericReturnValue collect_files_cb (void *cls, const char *filename)
 Function called with a filename.
 
static struct ConfigSectionfind_section (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
 Find a section entry from a configuration.
 
static int pstrcmp (const void *a, const void *b)
 
static enum GNUNET_GenericReturnValue 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.
 
static struct ConfigEntryfind_entry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
 Find an entry from a configuration.
 
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.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *source_filename)
 De-serializes configuration.
 
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.
 
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.
 
static bool do_skip (const char *sec, const char *key)
 Should we skip this configuration entry when serializing?
 
char * GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
 Serializes the given configuration.
 
static void dump_os_ipk (const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_Buffer *buf, enum GNUNET_OS_InstallationPathKind ipk)
 Dump an os installation path to a buffer.
 
char * GNUNET_CONFIGURATION_serialize_diagnostics (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Serializes the given configuration with diagnostics information.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
 Write configuration file.
 
void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
 Iterate over all options in the configuration.
 
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.
 
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.
 
void GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
 Remove the given section and all options in it.
 
static void copy_entry (void *cls, const char *section, const char *option, const char *value)
 Copy a configuration value to the given target configuration.
 
struct GNUNET_CONFIGURATION_HandleGNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Duplicate an existing configuration object.
 
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).
 
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.
 
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.
 
void GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
 Set a configuration value that should be a string.
 
void GNUNET_CONFIGURATION_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.
 
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.
 
void GNUNET_CONFIGURATION_set_value_float (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, float number)
 Set a configuration value that should be a float.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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".
 
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".
 
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.
 
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".
 
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.
 
static char * escape_name (const char *value)
 FIXME.
 
static enum GNUNET_GenericReturnValue test_match (void *cls, const char *fn)
 FIXME.
 
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.
 
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.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d)
 Load default configuration.
 
char * GNUNET_CONFIGURATION_default_filename (const struct GNUNET_OS_ProjectData *pd)
 Return the filename of the default configuration filename that is used when no explicit configuration entry point has been specified.
 
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
 Load configuration.
 
static void print_filename_option (void *cls, const char *section, const char *option, const char *value)
 Print each option in a given section as a filename.
 
static void print_option (void *cls, const char *section, const char *option, const char *value)
 Print each option in a given section.
 
static void print_section_name (void *cls, const char *section)
 Print out given section name.
 
void GNUNET_CONFIGURATION_config_tool_run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main task to run to perform operations typical for gnunet-config as per the configuration settings given in cls.
 
void GNUNET_CONFIGURATION_config_settings_free (struct GNUNET_CONFIGURATION_ConfigSettings *cs)
 Free resources associated with cs.
 
const struct GNUNET_OS_ProjectDataGNUNET_CONFIGURATION_get_project_data (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Return the project data associated with this configuration.
 

Macro Definition Documentation

◆ LOG

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

Definition at line 30 of file configuration.c.

◆ LOG_STRERROR_FILE

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

Definition at line 32 of file configuration.c.

38{
42 struct ConfigEntry *next;
43
47 char *key;
48
52 char *val;
53
57 char *hint_filename;
58
62 unsigned int hint_lineno;
63};
64
65
69struct ConfigSection
70{
74 struct ConfigSection *next;
75
79 struct ConfigEntry *entries;
80
84 char *name;
85
92 bool inaccessible;
93
98
102 char *hint_secret_stat;
103
108
112 unsigned int hint_inlined_from_line;
113};
114
115struct ConfigFile
116{
120 char *source_filename;
121
125 unsigned int level;
126
127 struct ConfigFile *prev;
128
129 struct ConfigFile *next;
130
136
141};
142
143
148{
152 struct ConfigSection *sections;
153
158
163
167 const struct GNUNET_OS_ProjectData *pd;
168
172 unsigned int current_nest_level;
173
177 bool diagnostics;
178
185
189 bool load_called;
190
194 char *main_filename;
195
201 const char *restrict_section;
202};
203
204
209struct DiffHandle
210{
212
214};
215
216
217void
220{
221 cfg->diagnostics = true;
222}
223
224
227{
229 char *p;
230
232 cfg->pd = pd;
233 /* make certain values from the project data available
234 as PATHS */
237 if (NULL != p)
238 {
240 "PATHS",
241 "DATADIR",
242 p);
243 GNUNET_free (p);
244 }
247 if (NULL != p)
248 {
250 "PATHS",
251 "LIBDIR",
252 p);
253 GNUNET_free (p);
254 }
257 if (NULL != p)
258 {
260 "PATHS",
261 "BINDIR",
262 p);
263 GNUNET_free (p);
264 }
267 if (NULL != p)
268 {
270 "PATHS",
271 "PREFIX",
272 p);
273 GNUNET_free (p);
274 }
277 if (NULL != p)
278 {
280 "PATHS",
281 "LOCALEDIR",
282 p);
283 GNUNET_free (p);
284 }
287 if (NULL != p)
288 {
290 "PATHS",
291 "ICONDIR",
292 p);
293 GNUNET_free (p);
294 }
297 if (NULL != p)
298 {
300 "PATHS",
301 "DOCDIR",
302 p);
303 GNUNET_free (p);
304 }
307 if (NULL != p)
308 {
310 "PATHS",
311 "LIBEXECDIR",
312 p);
313 GNUNET_free (p);
314 }
315 return cfg;
316}
317
318
319void
321{
322 struct ConfigSection *sec;
323 struct ConfigFile *cf;
324
325 while (NULL != (sec = cfg->sections))
327 while (NULL != (cf = cfg->loaded_files_head))
328 {
333 cf);
334 GNUNET_free (cf);
335 }
338}
339
340
343 const char *filename,
345 void *cb_cls)
346{
349
351 if (GNUNET_OK !=
353 filename))
354 {
355 GNUNET_break (0);
357 return GNUNET_SYSERR;
358 }
359 ret = cb (cb_cls,
360 cfg);
362 return ret;
363}
364
365
370{
374 char **files;
375
379 unsigned int files_length;
380};
381
382
393collect_files_cb (void *cls,
394 const char *filename)
395{
396 struct CollectFilesContext *igc = cls;
397
399 igc->files_length,
401 return GNUNET_OK;
402}
403
404
412static struct ConfigSection *
414 const char *section)
415{
416 struct ConfigSection *pos;
417
418 if (NULL == cfg)
419 return NULL;
420 pos = cfg->sections;
421 while ( (NULL != pos) &&
422 (0 != strcasecmp (section,
423 pos->name)) )
424 pos = pos->next;
425 return pos;
426}
427
428
429static int
430pstrcmp (const void *a,
431 const void *b)
432{
433 return strcmp (*((const char **) a),
434 *((const char **) b));
435}
436
437
445 const char *path_or_glob,
446 bool path_is_glob,
447 const char *restrict_section,
448 const char *source_filename,
449 unsigned int source_lineno)
450{
451 char *inline_path = NULL;
452 struct GNUNET_CONFIGURATION_Handle *other_cfg = NULL;
453 struct CollectFilesContext igc = {
454 .files = NULL,
455 .files_length = 0,
456 };
457 enum GNUNET_GenericReturnValue fun_ret;
458 unsigned int old_nest_level = cfg->current_nest_level++;
459
460 /* We support the section restriction only for non-globs */
461 GNUNET_assert (! (path_is_glob && (NULL != restrict_section)));
462
463 if (NULL == source_filename)
464 {
466 "Refusing to parse inline configurations, "
467 "not allowed without source filename!\n");
468 fun_ret = GNUNET_SYSERR;
469 goto cleanup;
470 }
471
472 if ('/' == *path_or_glob)
473 inline_path = GNUNET_strdup (path_or_glob);
474 else
475 {
476 /* We compute the canonical, absolute path first,
477 so that relative imports resolve properly with symlinked
478 config files. */
479 char *source_realpath;
480 char *endsep;
481
482 source_realpath = realpath (source_filename,
483 NULL);
484 if (NULL == source_realpath)
485 {
486 /* Couldn't even resolve path of base dir. */
487 GNUNET_break (0);
488 /* failed to parse included config */
489 fun_ret = GNUNET_SYSERR;
490 goto cleanup;
491 }
492 endsep = strrchr (source_realpath, '/');
493 GNUNET_assert (NULL != endsep);
494 *endsep = '\0';
495 GNUNET_asprintf (&inline_path,
496 "%s/%s",
497 source_realpath,
498 path_or_glob);
499 free (source_realpath);
500 }
501
502 if (path_is_glob)
503 {
504 int nret;
505
507 "processing config glob '%s'\n",
508 inline_path);
509
510 nret = GNUNET_DISK_glob (inline_path,
512 &igc);
513 if (-1 == nret)
514 {
515 fun_ret = GNUNET_SYSERR;
516 goto cleanup;
517 }
518 GNUNET_assert (nret == igc.files_length);
519 qsort (igc.files,
520 igc.files_length,
521 sizeof (char *),
522 &pstrcmp);
523 for (int i = 0; i < nret; i++)
524 {
525 if (GNUNET_OK !=
527 igc.files[i]))
528 {
529 fun_ret = GNUNET_SYSERR;
530 goto cleanup;
531 }
532 }
533 fun_ret = GNUNET_OK;
534 }
535 else if (NULL != restrict_section)
536 {
537 enum GNUNET_GenericReturnValue inner_ret;
538 struct ConfigSection *cs;
539 struct ConfigFile *cf = GNUNET_new (struct ConfigFile);
540
541 inner_ret = GNUNET_DISK_file_test_read (inline_path);
542
543 cs = find_section (cfg, restrict_section);
544
545 if (NULL == cs)
546 {
547 cs = GNUNET_new (struct ConfigSection);
548 cs->name = GNUNET_strdup (restrict_section);
549 cs->next = cfg->sections;
550 cfg->sections = cs;
551 cs->entries = NULL;
552 }
553 if (cfg->diagnostics)
554 {
555 const char *pwname;
556 const char *grname;
557 char *sfn = GNUNET_STRINGS_filename_expand (inline_path);
558 struct stat istat;
559
560 cs->hint_secret_filename = sfn;
561 if (0 == stat (sfn, &istat))
562 {
563 struct passwd *pw = getpwuid (istat.st_uid);
564 struct group *gr = getgrgid (istat.st_gid);
565 pwname = (NULL == pw) ? "<unknown>" : pw->pw_name;
566 grname = (NULL == gr) ? "<unknown>" : gr->gr_name;
567
569 "%s:%s %o",
570 pwname,
571 grname,
572 istat.st_mode);
573 }
574 else
575 {
576 cs->hint_secret_stat = GNUNET_strdup ("<can't stat file>");
577 }
578 if (source_filename)
579 {
580 /* Possible that this secret section has been inlined before */
582 cs->hint_inlined_from_filename = GNUNET_strdup (source_filename);
583 cs->hint_inlined_from_line = source_lineno;
584 }
585 }
586
587 /* Put file in the load list for diagnostics, even if we can't access it. */
588 {
590 cf->source_filename = GNUNET_strdup (inline_path);
591 cf->hint_restrict_section = GNUNET_strdup (restrict_section);
594 cf);
595 }
596
597 if (GNUNET_OK != inner_ret)
598 {
599 cs->inaccessible = true;
600 cf->hint_inaccessible = true;
601 /* File can't be accessed, but that's okay. */
602 fun_ret = GNUNET_OK;
603 goto cleanup;
604 }
605
606 other_cfg = GNUNET_CONFIGURATION_create (cfg->pd);
607 other_cfg->restrict_section = restrict_section;
608 inner_ret = GNUNET_CONFIGURATION_parse (other_cfg,
609 inline_path);
610 if (GNUNET_OK != inner_ret)
611 {
612 cf->hint_inaccessible = true;
613 fun_ret = inner_ret;
614 goto cleanup;
615 }
616
617 cs = find_section (other_cfg,
618 restrict_section);
619 if (NULL == cs)
620 {
622 "Configuration file '%s' loaded with @inline-secret@ "
623 "does not contain section '%s'.\n",
624 inline_path,
625 restrict_section);
626 /* Inlined configuration is accessible but doesn't contain any values.
627 We treat this as if the inlined section was empty, and do not
628 consider it an error. */
629 fun_ret = GNUNET_OK;
630 goto cleanup;
631 }
632 for (struct ConfigEntry *ce = cs->entries;
633 NULL != ce;
634 ce = ce->next)
636 restrict_section,
637 ce->key,
638 ce->val);
639 fun_ret = GNUNET_OK;
640 }
641 else if (GNUNET_OK !=
643 inline_path))
644 {
645 fun_ret = GNUNET_SYSERR;
646 goto cleanup;
647 }
648 else
649 {
650 fun_ret = GNUNET_OK;
651 }
652cleanup:
653 cfg->current_nest_level = old_nest_level;
654 if (NULL != other_cfg)
656 GNUNET_free (inline_path);
657 if (igc.files_length > 0)
658 {
659 for (size_t i = 0; i < igc.files_length; i++)
660 GNUNET_free (igc.files[i]);
662 }
663 return fun_ret;
664}
665
666
675static struct ConfigEntry *
677 const char *section,
678 const char *key)
679{
680 struct ConfigSection *sec;
681
682 if (NULL == (sec = find_section (cfg,
683 section)))
684 return NULL;
685 for (struct ConfigEntry *pos = sec->entries;
686 pos != NULL;
687 pos = pos->next)
688 if (0 == strcasecmp (key,
689 pos->key))
690 return pos;
691 if (sec->inaccessible)
692 {
694 "Section '%s' is marked as inaccessible, because the configuration "
695 "file that contains the section can't be read. Attempts to use "
696 "option '%s' will fail.\n",
697 section,
698 key);
699 return NULL;
700 }
701 return NULL;
702}
703
704
714static void
716 const char *section,
717 const char *option,
718 const char *hint_filename,
719 unsigned int hint_line)
720{
721 struct ConfigEntry *e = find_entry (cfg, section, option);
722 if (! cfg->diagnostics)
723 return;
724 if (! e)
725 return;
727 e->hint_lineno = hint_line;
728}
729
730
733 const char *mem,
734 size_t size,
735 const char *source_filename)
736{
737 size_t line_size;
738 unsigned int nr;
739 size_t r_bytes;
740 size_t to_read;
742 char *section;
743 char *eq;
744 char *tag;
745 char *value;
746 char *line_orig = NULL;
747
748 ret = GNUNET_OK;
749 section = NULL;
750 nr = 0;
751 r_bytes = 0;
752 while (r_bytes < size)
753 {
754 const char *pos;
755 char *line;
756 bool emptyline;
757
758 GNUNET_free (line_orig);
759 /* fgets-like behaviour on buffer */
760 to_read = size - r_bytes;
761 pos = memchr (&mem[r_bytes], '\n', to_read);
762 if (NULL == pos)
763 {
764 line_orig = GNUNET_strndup (&mem[r_bytes],
765 line_size = to_read);
766 r_bytes += line_size;
767 }
768 else
769 {
770 line_orig = GNUNET_strndup (&mem[r_bytes],
771 line_size = (pos - &mem[r_bytes]));
772 r_bytes += line_size + 1;
773 }
774 line = line_orig;
775 /* increment line number */
776 nr++;
777 /* tabs and '\r' are whitespace */
778 emptyline = GNUNET_YES;
779 for (size_t i = 0; i < line_size; i++)
780 {
781 if (line[i] == '\t')
782 line[i] = ' ';
783 if (line[i] == '\r')
784 line[i] = ' ';
785 if (' ' != line[i])
786 emptyline = GNUNET_NO;
787 }
788 /* ignore empty lines */
789 if (GNUNET_YES == emptyline)
790 continue;
791
792 /* remove tailing whitespace */
793 for (size_t i = line_size - 1;
794 (i >= 1) && (isspace ((unsigned char) line[i]));
795 i--)
796 line[i] = '\0';
797
798 /* remove leading whitespace */
799 for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++)
800 ;
801
802 /* ignore comments */
803 if ( ('#' == line[0]) ||
804 ('%' == line[0]) )
805 continue;
806
807 /* Handle special directives. */
808 if ('@' == line[0])
809 {
810 char *end = strchr (line + 1, '@');
811 char *directive;
812 enum GNUNET_GenericReturnValue directive_ret;
813
814 if (NULL != cfg->restrict_section)
815 {
817 "Illegal directive in line %u (parsing restricted section %s)\n",
818 nr,
821 break;
822 }
823
824 if (NULL == end)
825 {
827 "Bad directive in line %u\n",
828 nr);
830 break;
831 }
832 *end = '\0';
833 directive = line + 1;
834
835 if (0 == strcasecmp (directive,
836 "INLINE"))
837 {
838 const char *path = end + 1;
839
840 /* Skip space before path */
841 for (; isspace (*path); path++)
842 ;
843
844 directive_ret = handle_inline (cfg,
845 path,
846 false,
847 NULL,
848 source_filename,
849 nr);
850 }
851 else if (0 == strcasecmp (directive,
852 "INLINE-MATCHING"))
853 {
854 const char *path = end + 1;
855
856 /* Skip space before path */
857 for (; isspace (*path); path++)
858 ;
859
860 directive_ret = handle_inline (cfg,
861 path,
862 true,
863 NULL,
864 source_filename,
865 nr);
866 }
867 else if (0 == strcasecmp (directive,
868 "INLINE-SECRET"))
869 {
870 char *secname = end + 1;
871 char *secname_end;
872 const char *path;
873
874 /* Skip space before secname */
875 for (; isspace (*secname); secname++)
876 ;
877
878 secname_end = strchr (secname, ' ');
879
880 if (NULL == secname_end)
881 {
883 "Bad inline-secret directive in line %u\n",
884 nr);
886 break;
887 }
888 *secname_end = '\0';
889 path = secname_end + 1;
890
891 /* Skip space before path */
892 for (; isspace (*path); path++)
893 ;
894
895 directive_ret = handle_inline (cfg,
896 path,
897 false,
898 secname,
899 source_filename,
900 nr);
901 }
902 else
903 {
905 "Unknown or malformed directive '%s' in line %u\n",
906 directive,
907 nr);
909 break;
910 }
911 if (GNUNET_OK != directive_ret)
912 {
913 ret = directive_ret;
914 break;
915 }
916 continue;
917 }
918 if ( ('[' == line[0]) &&
919 (']' == line[line_size - 1]) )
920 {
921 /* [value] */
922 line[line_size - 1] = '\0';
923 value = &line[1];
924 GNUNET_free (section);
925 section = GNUNET_strdup (value);
926 continue;
927 }
928 if (NULL != (eq = strchr (line, '=')))
929 {
930
931 if (NULL == section)
932 {
934 "Syntax error while deserializing in line %u (option without section)\n",
935 nr);
937 break;
938 }
939
940 /* tag = value */
941 tag = GNUNET_strndup (line, eq - line);
942 /* remove tailing whitespace */
943 for (int i = strlen (tag) - 1;
944 (i >= 1) && (isspace ((unsigned char) tag[i]));
945 i--)
946 tag[i] = '\0';
947
948 /* Strip whitespace */
949 value = eq + 1;
950 while (isspace ((unsigned char) value[0]))
951 value++;
952 for (int i = strlen (value) - 1;
953 (i >= 1) && (isspace ((unsigned char) value[i]));
954 i--)
955 value[i] = '\0';
956
957 /* remove quotes */
958 if ( ('"' == value[0]) &&
959 ('"' == value[strlen (value) - 1]) )
960 {
961 value[strlen (value) - 1] = '\0';
962 value++;
963 }
965 section,
966 tag,
967 value);
968 if (cfg->diagnostics)
969 {
971 section,
972 tag,
973 source_filename
974 ? source_filename
975 : "<input>",
976 nr);
977 }
978 GNUNET_free (tag);
979 continue;
980 }
981 /* parse error */
983 "Syntax error while deserializing in line %u\n",
984 nr);
986 break;
987 }
988 GNUNET_free (line_orig);
989 GNUNET_free (section);
990 GNUNET_assert ( (GNUNET_OK != ret) ||
991 (r_bytes == size) );
992 return ret;
993}
994
995
998 const char *filename)
999{
1000 uint64_t fs64;
1001 size_t fs;
1002 char *fn;
1003 char *mem;
1004 int dirty;
1006 ssize_t sret;
1007
1010 "Asked to parse config file `%s'\n",
1011 fn);
1012 if (NULL == fn)
1013 return GNUNET_SYSERR;
1014
1015
1016 /* Check for cycles */
1017 {
1018 unsigned int lvl = cfg->current_nest_level;
1019 struct ConfigFile *cf = cfg->loaded_files_tail;
1020 struct ConfigFile *parent = NULL;
1021
1022
1023 for (; NULL != cf; parent = cf, cf = cf->prev)
1024 {
1025 /* Check parents based on level, skipping children of siblings. */
1026 if (cf->level >= lvl)
1027 continue;
1028 lvl = cf->level;
1029 if ( (NULL == cf->source_filename) ||
1030 (NULL == filename) )
1031 continue;
1032 if (0 == strcmp (cf->source_filename,
1033 filename))
1034 {
1035 if (NULL == parent)
1036 {
1038 "Forbidden direct cyclic configuration import (%s -> %s)\n",
1039 cf->source_filename,
1040 filename);
1041 }
1042 else
1044 "Forbidden indirect cyclic configuration import (%s -> ... -> %s -> %s)\n",
1045 cf->source_filename,
1046 parent->source_filename,
1047 filename);
1048 GNUNET_free (fn);
1049 return GNUNET_SYSERR;
1050 }
1051 }
1052
1053 }
1054
1055 /* Keep track of loaded files.*/
1056 {
1057 struct ConfigFile *cf = GNUNET_new (struct ConfigFile);
1058
1060 cf->source_filename = GNUNET_strdup (filename ? filename : "<input>");
1063 cf);
1064 }
1065
1066 dirty = cfg->dirty; /* back up value! */
1067 if (GNUNET_SYSERR ==
1069 &fs64,
1070 GNUNET_NO,
1071 GNUNET_YES))
1072 {
1074 "Error while determining the file size of `%s'\n",
1075 fn);
1076 GNUNET_free (fn);
1077 return GNUNET_SYSERR;
1078 }
1079 if (fs64 > SIZE_MAX)
1080 {
1081 GNUNET_break (0); /* File size is more than the heap size */
1082 GNUNET_free (fn);
1083 return GNUNET_SYSERR;
1084 }
1085 fs = fs64;
1086 mem = GNUNET_malloc (fs);
1087 sret = GNUNET_DISK_fn_read (fn,
1088 mem,
1089 fs);
1090 if ((sret < 0) || (fs != (size_t) sret))
1091 {
1093 "Error while reading file `%s'\n",
1094 fn);
1095 GNUNET_free (fn);
1096 GNUNET_free (mem);
1097 return GNUNET_SYSERR;
1098 }
1100 "Deserializing contents of file `%s'\n",
1101 fn);
1103 mem,
1104 fs,
1105 fn);
1106 if (GNUNET_SYSERR == ret)
1107 {
1109 _ ("Failed to parse configuration file `%s'\n"),
1110 fn);
1111 }
1112 GNUNET_free (fn);
1113 GNUNET_free (mem);
1114 /* restore dirty flag - anything we set in the meantime
1115 * came from disk */
1116 cfg->dirty = dirty;
1117 return ret;
1118}
1119
1120
1123{
1124 return cfg->dirty;
1125}
1126
1127
1135static bool
1136do_skip (const char *sec,
1137 const char *key)
1138{
1139 if (0 != strcasecmp ("PATHS",
1140 sec))
1141 return false;
1142 return ( (0 == strcasecmp ("DATADIR",
1143 key)) ||
1144 (0 == strcasecmp ("LIBDIR",
1145 key)) ||
1146 (0 == strcasecmp ("BINDIR",
1147 key)) ||
1148 (0 == strcasecmp ("PREFIX",
1149 key)) ||
1150 (0 == strcasecmp ("LOCALEDIR",
1151 key)) ||
1152 (0 == strcasecmp ("ICONDIR",
1153 key)) ||
1154 (0 == strcasecmp ("DOCDIR",
1155 key)) ||
1156 (0 == strcasecmp ("DEFAULTCONFIG",
1157 key)) ||
1158 (0 == strcasecmp ("LIBEXECDIR",
1159 key)) );
1160}
1161
1162
1163char *
1165 size_t *size)
1166{
1167 char *mem;
1168 char *cbuf;
1169 char *val;
1170 char *pos;
1171 size_t m_size;
1172 size_t c_size;
1173
1174 /* Pass1 : calculate the buffer size required */
1175 m_size = 0;
1176 for (struct ConfigSection *sec = cfg->sections;
1177 NULL != sec;
1178 sec = sec->next)
1179 {
1180 if (sec->inaccessible && (NULL == sec->entries))
1181 continue;
1182 /* For each section we need to add 3 characters: {'[',']','\n'} */
1183 m_size += strlen (sec->name) + 3;
1184 for (struct ConfigEntry *ent = sec->entries;
1185 NULL != ent;
1186 ent = ent->next)
1187 {
1188 if (do_skip (sec->name,
1189 ent->key))
1190 continue;
1191 if (NULL != ent->val)
1192 {
1193 /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */
1194 pos = ent->val;
1195 while (NULL != (pos = strstr (pos, "\n")))
1196 {
1197 m_size++;
1198 pos++;
1199 }
1200 /* For each key = value pair we need to add 4 characters (2
1201 spaces and 1 equal-to character and 1 new line) */
1202 m_size += strlen (ent->key) + strlen (ent->val) + 4;
1203 }
1204 }
1205 /* A new line after section end */
1206 m_size++;
1207 }
1208
1209 /* Pass2: Allocate memory and write the configuration to it */
1210 mem = GNUNET_malloc (m_size);
1211 c_size = 0;
1212 *size = c_size;
1213 for (struct ConfigSection *sec = cfg->sections;
1214 NULL != sec;
1215 sec = sec->next)
1216 {
1217 int len;
1218
1219 len = GNUNET_asprintf (&cbuf,
1220 "[%s]\n",
1221 sec->name);
1222 GNUNET_assert (0 < len);
1223 GNUNET_memcpy (mem + c_size,
1224 cbuf,
1225 len);
1226 c_size += len;
1227 GNUNET_free (cbuf);
1228 for (struct ConfigEntry *ent = sec->entries;
1229 NULL != ent;
1230 ent = ent->next)
1231 {
1232 if (do_skip (sec->name,
1233 ent->key))
1234 continue;
1235 if (NULL != ent->val)
1236 {
1237 val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1238 strcpy (val, ent->val);
1239 while (NULL != (pos = strstr (val, "\n")))
1240 {
1241 memmove (&pos[2], &pos[1], strlen (&pos[1]));
1242 pos[0] = '\\';
1243 pos[1] = 'n';
1244 }
1245 len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
1246 GNUNET_free (val);
1247 GNUNET_memcpy (mem + c_size, cbuf, len);
1248 c_size += len;
1249 GNUNET_free (cbuf);
1250 }
1251 }
1252 GNUNET_memcpy (mem + c_size, "\n", 1);
1253 c_size++;
1254 }
1255 GNUNET_assert (c_size == m_size);
1256 *size = c_size;
1257 return mem;
1258}
1259
1260
1269static void
1271 const struct GNUNET_CONFIGURATION_Handle *cfg,
1272 struct GNUNET_Buffer *buf,
1274{
1276 ipk);
1277 const char *ipkname;
1278 switch (ipk)
1279 {
1281 ipkname = "IPK_DATADIR";
1282 break;
1284 ipkname = "IPK_BINDIR";
1285 break;
1287 ipkname = "IPK_LIBDIR";
1288 break;
1290 ipkname = "IPK_PREFIX";
1292 ipkname = "IPK_LOCALEDIR";
1293 break;
1295 ipkname = "IPK_ICONDIR";
1297 ipkname = "IPK_DOCDIR";
1298 break;
1300 ipkname = "IPK_LIBEXECDIR";
1301 break;
1303 ipkname = "IPK_SELF_PREFIX";
1304 break;
1305 default:
1306 ipkname = "??";
1307 break;
1308 }
1310 "# %s = %s\n",
1311 ipkname,
1312 v);
1313 GNUNET_free (v);
1314}
1315
1316
1317char *
1319 const struct GNUNET_CONFIGURATION_Handle *cfg)
1320{
1321 struct GNUNET_Buffer buf = { 0 };
1322
1324 "#\n# Configuration file diagnostics\n#\n");
1326 "# Entry point: %s\n",
1328 "<none>");
1330 "#\n# Files Loaded:\n");
1331
1332 for (struct ConfigFile *cfil = cfg->loaded_files_head;
1333 NULL != cfil;
1334 cfil = cfil->next)
1335 {
1337 "# ");
1338 for (unsigned int i = 0; i < cfil->level; i++)
1340 "+");
1341 if (0 != cfil->level)
1343 " ");
1344
1346 "%s",
1347 cfil->source_filename);
1348
1349 if (NULL != cfil->hint_restrict_section)
1351 " (%s secret section %s)",
1352 cfil->hint_inaccessible
1353 ? "inaccessible"
1354 : "loaded",
1355 cfil->hint_restrict_section);
1356
1358 "\n");
1359 }
1360
1362 "#\n# Installation paths:\n");
1363
1373
1374
1376 "#\n\n");
1377
1378 for (struct ConfigSection *sec = cfg->sections;
1379 NULL != sec;
1380 sec = sec->next)
1381 {
1382 if (sec->hint_secret_filename)
1384 "# secret section from %s\n# secret file stat %s\n",
1385 sec->hint_secret_filename,
1386 sec->hint_secret_stat);
1387 if (sec->hint_inlined_from_filename)
1388 {
1390 "# inlined from %s:%u\n",
1391 sec->hint_inlined_from_filename,
1392 sec->hint_inlined_from_line);
1393 }
1395 "[%s]\n\n",
1396 sec->name);
1397 if (sec->inaccessible && (NULL == sec->entries))
1398 {
1400 "# <section contents inaccessible>\n\n\n");
1401 continue;
1402 }
1403 for (struct ConfigEntry *ent = sec->entries;
1404 NULL != ent;
1405 ent = ent->next)
1406 {
1407 if (do_skip (sec->name,
1408 ent->key))
1409 continue;
1410 if (NULL != ent->val)
1411 {
1412 char *pos;
1413 char *val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1414 strcpy (val, ent->val);
1415 while (NULL != (pos = strstr (val, "\n")))
1416 {
1417 memmove (&pos[2], &pos[1], strlen (&pos[1]));
1418 pos[0] = '\\';
1419 pos[1] = 'n';
1420 }
1421 if (NULL != ent->hint_filename)
1422 {
1424 "# %s:%u\n",
1425 ent->hint_filename,
1426 ent->hint_lineno);
1427 }
1429 "%s = %s\n",
1430 ent->key,
1431 val);
1432 GNUNET_free (val);
1433 }
1434 GNUNET_buffer_write_str (&buf, "\n");
1435 }
1436 if (sec->inaccessible)
1437 {
1439 "# <additional section contents inaccessible>\n\n\n");
1440 continue;
1441 }
1442
1443 GNUNET_buffer_write_str (&buf, "\n");
1444 }
1445 return GNUNET_buffer_reap_str (&buf);
1446}
1447
1448
1452 const char *filename)
1453{
1454 char *fn;
1455 char *cfg_buf;
1456 size_t size;
1457
1459 if (fn == NULL)
1460 return GNUNET_SYSERR;
1462 {
1463 GNUNET_free (fn);
1464 return GNUNET_SYSERR;
1465 }
1467 &size);
1468 {
1469 struct GNUNET_DISK_FileHandle *h;
1470
1479 if (NULL == h)
1480 {
1481 GNUNET_free (fn);
1482 GNUNET_free (cfg_buf);
1483 return GNUNET_SYSERR;
1484 }
1485 if (((ssize_t) size) !=
1487 cfg_buf,
1488 size))
1489 {
1491 "write",
1492 fn);
1494 (void) GNUNET_DISK_directory_remove (fn);
1495 GNUNET_free (fn);
1496 GNUNET_free (cfg_buf);
1497 cfg->dirty = GNUNET_SYSERR; /* last write failed */
1498 return GNUNET_SYSERR;
1499 }
1502 }
1503 GNUNET_free (fn);
1504 GNUNET_free (cfg_buf);
1505 cfg->dirty = GNUNET_NO; /* last write succeeded */
1506 return GNUNET_OK;
1507}
1508
1509
1510void
1512 const struct GNUNET_CONFIGURATION_Handle *cfg,
1514 void *iter_cls)
1515{
1516 for (struct ConfigSection *spos = cfg->sections;
1517 NULL != spos;
1518 spos = spos->next)
1519 for (struct ConfigEntry *epos = spos->entries;
1520 NULL != epos;
1521 epos = epos->next)
1522 if (NULL != epos->val)
1523 iter (iter_cls,
1524 spos->name,
1525 epos->key,
1526 epos->val);
1527}
1528
1529
1530void
1532 const struct GNUNET_CONFIGURATION_Handle *cfg,
1533 const char *section,
1535 void *iter_cls)
1536{
1537 struct ConfigSection *spos;
1538
1539 spos = cfg->sections;
1540 while ((spos != NULL) && (0 != strcasecmp (spos->name, section)))
1541 spos = spos->next;
1542 if (NULL == spos)
1543 return;
1544 for (struct ConfigEntry *epos = spos->entries;
1545 NULL != epos;
1546 epos = epos->next)
1547 if (NULL != epos->val)
1548 iter (iter_cls,
1549 spos->name,
1550 epos->key,
1551 epos->val);
1552 if (spos->inaccessible)
1553 {
1555 "Section '%s' is marked as inaccessible, because a configuration "
1556 "file that contains the section can't be read.\n",
1557 section);
1558 return;
1559 }
1560}
1561
1562
1563void
1565 const struct GNUNET_CONFIGURATION_Handle *cfg,
1567 void *iter_cls)
1568{
1569 struct ConfigSection *spos;
1570 struct ConfigSection *next;
1571
1572 next = cfg->sections;
1573 while (NULL != next)
1574 {
1575 spos = next;
1576 next = spos->next;
1577 if (spos->inaccessible && (NULL == spos->entries))
1578 continue;
1579 iter (iter_cls,
1580 spos->name);
1581 }
1582}
1583
1584
1585void
1587 const char *section)
1588{
1589 struct ConfigSection *spos;
1590 struct ConfigSection *prev;
1591 struct ConfigEntry *ent;
1592
1593 prev = NULL;
1594 spos = cfg->sections;
1595 while (NULL != spos)
1596 {
1597 if (0 == strcasecmp (section,
1598 spos->name))
1599 {
1600 if (NULL == prev)
1601 cfg->sections = spos->next;
1602 else
1603 prev->next = spos->next;
1604 while (NULL != (ent = spos->entries))
1605 {
1606 spos->entries = ent->next;
1607 GNUNET_free (ent->key);
1608 GNUNET_free (ent->val);
1610 GNUNET_free (ent);
1611 cfg->dirty = GNUNET_YES;
1612 }
1613 GNUNET_free (spos->name);
1617 GNUNET_free (spos);
1618 return;
1619 }
1620 prev = spos;
1621 spos = spos->next;
1622 }
1623}
1624
1625
1635static void
1636copy_entry (void *cls,
1637 const char *section,
1638 const char *option,
1639 const char *value)
1640{
1641 struct GNUNET_CONFIGURATION_Handle *dst = cls;
1642
1644 section,
1645 option,
1646 value);
1647}
1648
1649
1652 const struct GNUNET_CONFIGURATION_Handle *cfg)
1653{
1655
1658 &copy_entry,
1659 ret);
1660 return ret;
1661}
1662
1663
1674static void
1675compare_entries (void *cls,
1676 const char *section,
1677 const char *option,
1678 const char *value)
1679{
1680 struct DiffHandle *dh = cls;
1681 struct ConfigEntry *entNew;
1682
1683 entNew = find_entry (dh->cfg_default, section, option);
1684 if ((NULL != entNew) && (NULL != entNew->val) &&
1685 (0 == strcmp (entNew->val, value)))
1686 return;
1688 section,
1689 option,
1690 value);
1691}
1692
1693
1696 const struct GNUNET_CONFIGURATION_Handle *cfg_default,
1697 const struct GNUNET_CONFIGURATION_Handle *cfg_new)
1698{
1699 struct DiffHandle diffHandle;
1700
1701 GNUNET_break (cfg_default->pd == cfg_new->pd);
1702 diffHandle.cfgDiff = GNUNET_CONFIGURATION_create (cfg_new->pd);
1703 diffHandle.cfg_default = cfg_default;
1706 &diffHandle);
1707 return diffHandle.cfgDiff;
1708}
1709
1710
1714 const struct GNUNET_CONFIGURATION_Handle *cfg_new,
1715 const char *filename)
1716{
1717 int ret;
1718 struct GNUNET_CONFIGURATION_Handle *diff;
1719
1720 diff = GNUNET_CONFIGURATION_get_diff (cfg_default, cfg_new);
1723 return ret;
1724}
1725
1726
1727void
1730 const char *section,
1731 const char *option,
1732 const char *value)
1733{
1734 struct ConfigSection *sec;
1735 struct ConfigEntry *e;
1736 char *nv;
1737
1738 e = find_entry (cfg, section, option);
1739 if (NULL != e)
1740 {
1741 if (NULL == value)
1742 {
1743 GNUNET_free (e->val);
1744 e->val = NULL;
1745 }
1746 else
1747 {
1748 nv = GNUNET_strdup (value);
1749 GNUNET_free (e->val);
1750 e->val = nv;
1751 }
1752 return;
1753 }
1754 sec = find_section (cfg, section);
1755 if (sec == NULL)
1756 {
1757 sec = GNUNET_new (struct ConfigSection);
1758 sec->name = GNUNET_strdup (section);
1759 sec->next = cfg->sections;
1760 cfg->sections = sec;
1761 }
1762 e = GNUNET_new (struct ConfigEntry);
1763 e->key = GNUNET_strdup (option);
1764 e->val = GNUNET_strdup (value);
1765 e->next = sec->entries;
1766 sec->entries = e;
1767}
1768
1769
1770void
1772 const char *section,
1773 const char *option,
1774 unsigned long long number)
1775{
1776 char s[64];
1777
1778 GNUNET_snprintf (s,
1779 64,
1780 "%llu",
1781 number);
1783 section,
1784 option,
1785 s);
1786}
1787
1788
1791 const struct GNUNET_CONFIGURATION_Handle *cfg,
1792 const char *section,
1793 const char *option,
1794 unsigned long long *number)
1795{
1796 struct ConfigEntry *e;
1797 char dummy[2];
1798
1799 if (NULL == (e = find_entry (cfg,
1800 section,
1801 option)))
1802 return GNUNET_NO;
1803 if (NULL == e->val)
1804 return GNUNET_NO;
1805 if (1 != sscanf (e->val,
1806 "%llu%1s",
1807 number,
1808 dummy))
1809 return GNUNET_SYSERR;
1810 return GNUNET_OK;
1811}
1812
1813
1814void
1816 const char *section,
1817 const char *option,
1818 float number)
1819{
1820 char s[64];
1821
1822 /* See: #9369 */
1823 const locale_t cl = newlocale (LC_NUMERIC_MASK,
1824 "C",
1825 (locale_t) 0);
1826 locale_t old_locale = uselocale (cl);
1827 GNUNET_snprintf (s,
1828 64,
1829 "%f",
1830 (double) number);
1831 uselocale (old_locale);
1833 section,
1834 option,
1835 s);
1836}
1837
1838
1841 const struct GNUNET_CONFIGURATION_Handle *cfg,
1842 const char *section,
1843 const char *option,
1844 float *number)
1845{
1846 struct ConfigEntry *e;
1847 char dummy[2];
1848
1849 if (NULL == (e = find_entry (cfg,
1850 section,
1851 option)))
1852 return GNUNET_NO;
1853 if (NULL == e->val)
1854 return GNUNET_NO;
1855 /* See #9369 */
1856 {
1857 const locale_t cl = newlocale (LC_NUMERIC_MASK,
1858 "C",
1859 (locale_t) 0);
1860 locale_t old_locale = uselocale (cl);
1861
1862 if (1 != sscanf (e->val,
1863 "%f%1s",
1864 number,
1865 dummy))
1866 return GNUNET_SYSERR;
1867 uselocale (old_locale);
1868 }
1869 return GNUNET_OK;
1870}
1871
1872
1875 const struct GNUNET_CONFIGURATION_Handle *cfg,
1876 const char *section,
1877 const char *option,
1878 struct GNUNET_TIME_Relative *time)
1879{
1880 struct ConfigEntry *e;
1881 int ret;
1882
1883 if (NULL == (e = find_entry (cfg,
1884 section,
1885 option)))
1886 return GNUNET_NO;
1887 if (NULL == e->val)
1888 return GNUNET_NO;
1890 time);
1891 if (GNUNET_OK != ret)
1893 section,
1894 option,
1895 _ ("Not a valid relative time specification"));
1896 return ret;
1897}
1898
1899
1902 const struct GNUNET_CONFIGURATION_Handle *cfg,
1903 const char *section,
1904 const char *option,
1905 unsigned long long *size)
1906{
1907 struct ConfigEntry *e;
1908
1909 if (NULL == (e = find_entry (cfg,
1910 section,
1911 option)))
1912 return GNUNET_NO;
1913 if (NULL == e->val)
1914 return GNUNET_NO;
1916 size);
1917}
1918
1919
1932 const struct GNUNET_CONFIGURATION_Handle *cfg,
1933 const char *section,
1934 const char *option,
1935 char **value)
1936{
1937 struct ConfigEntry *e;
1938
1939 if ( (NULL == (e = find_entry (cfg,
1940 section,
1941 option))) ||
1942 (NULL == e->val) )
1943 {
1944 *value = NULL;
1945 return GNUNET_NO;
1946 }
1947 *value = GNUNET_strdup (e->val);
1948 return GNUNET_OK;
1949}
1950
1951
1954 const struct GNUNET_CONFIGURATION_Handle *cfg,
1955 const char *section,
1956 const char *option,
1957 const char *const *choices,
1958 const char **value)
1959{
1960 struct ConfigEntry *e;
1961 unsigned int i;
1962
1963 if (NULL == (e = find_entry (cfg,
1964 section,
1965 option)))
1966 return GNUNET_NO;
1967 for (i = 0; NULL != choices[i]; i++)
1968 if (0 == strcasecmp (choices[i], e->val))
1969 break;
1970 if (NULL == choices[i])
1971 {
1973 _ ("Configuration value '%s' for '%s'"
1974 " in section '%s' is not in set of legal choices\n"),
1975 e->val,
1976 option,
1977 section);
1978 return GNUNET_SYSERR;
1979 }
1980 *value = choices[i];
1981 return GNUNET_OK;
1982}
1983
1984
1987 const char *section,
1988 const char *option,
1989 void *buf,
1990 size_t buf_size)
1991{
1992 char *enc;
1993 int res;
1994 size_t data_size;
1995
1996 if (GNUNET_OK !=
1997 (res =
1999 section,
2000 option,
2001 &enc)))
2002 return res;
2003 data_size = (strlen (enc) * 5) / 8;
2004 if (data_size != buf_size)
2005 {
2006 GNUNET_free (enc);
2007 return GNUNET_SYSERR;
2008 }
2009 if (GNUNET_OK !=
2011 strlen (enc),
2012 buf,
2013 buf_size))
2014 {
2015 GNUNET_free (enc);
2016 return GNUNET_SYSERR;
2017 }
2018 GNUNET_free (enc);
2019 return GNUNET_OK;
2020}
2021
2022
2025 const char *section,
2026 const char *option)
2027{
2028 struct ConfigEntry *e;
2029
2030 if ( (NULL == (e = find_entry (cfg,
2031 section,
2032 option))) ||
2033 (NULL == e->val) )
2034 return GNUNET_NO;
2035 return GNUNET_YES;
2036}
2037
2038
2054static char *
2056 char *orig,
2057 unsigned int depth)
2058{
2059 char *prefix;
2060 char *result;
2061 char *start;
2062 const char *post;
2063 const char *env;
2064 char *def;
2065 char *end;
2066 unsigned int lopen;
2067 char erased_char;
2068 char *erased_pos;
2069 size_t len;
2070
2071 if (NULL == orig)
2072 return NULL;
2073 if (depth > 128)
2074 {
2076 "Recursive expansion suspected, aborting $-expansion for term `%s'\n",
2077 orig);
2078 return orig;
2079 }
2081 "Asked to $-expand %s\n",
2082 orig);
2083 if ('$' != orig[0])
2084 {
2086 "Doesn't start with $ - not expanding\n");
2087 return orig;
2088 }
2089 erased_char = 0;
2090 erased_pos = NULL;
2091 if ('{' == orig[1])
2092 {
2093 start = &orig[2];
2094 lopen = 1;
2095 end = &orig[1];
2096 while (lopen > 0)
2097 {
2098 end++;
2099 switch (*end)
2100 {
2101 case '}':
2102 lopen--;
2103 break;
2104
2105 case '{':
2106 lopen++;
2107 break;
2108
2109 case '\0':
2111 "Missing closing `}' in option `%s'\n",
2112 orig);
2113 return orig;
2114
2115 default:
2116 break;
2117 }
2118 }
2119 erased_char = *end;
2120 erased_pos = end;
2121 *end = '\0';
2122 post = end + 1;
2123 def = strchr (orig, ':');
2124 if (NULL != def)
2125 {
2126 *def = '\0';
2127 def++;
2128 if (('-' == *def) || ('=' == *def))
2129 def++;
2130 def = GNUNET_strdup (def);
2131 }
2132 }
2133 else
2134 {
2135 int i;
2136
2137 start = &orig[1];
2138 def = NULL;
2139 i = 0;
2140 while ( (orig[i] != '/') &&
2141 (orig[i] != '\\') &&
2142 (orig[i] != '\0') &&
2143 (orig[i] != ' ') )
2144 i++;
2145 if (orig[i] == '\0')
2146 {
2147 post = "";
2148 }
2149 else
2150 {
2151 erased_char = orig[i];
2152 erased_pos = &orig[i];
2153 orig[i] = '\0';
2154 post = &orig[i + 1];
2155 }
2156 }
2158 "Split into `%s' and `%s' with default %s\n",
2159 start,
2160 post,
2161 def);
2162 if (GNUNET_OK !=
2164 "PATHS",
2165 start,
2166 &prefix))
2167 {
2168 if (NULL == (env = getenv (start)))
2169 {
2170 /* try default */
2171 def = expand_dollar (cfg,
2172 def,
2173 depth + 1);
2174 env = def;
2175 }
2176 if (NULL == env)
2177 {
2179 if (erased_pos)
2180 *erased_pos = erased_char;
2182 "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n",
2183 start,
2184 orig);
2186 return orig;
2187 }
2189 }
2191 prefix);
2192 if ((erased_pos) && ('}' != erased_char))
2193 {
2194 len = strlen (prefix) + 1;
2195 prefix = GNUNET_realloc (prefix, len + 1);
2196 prefix[len - 1] = erased_char;
2197 prefix[len] = '\0';
2198 }
2199 result = GNUNET_malloc (strlen (prefix) + strlen (post) + 1);
2200 strcpy (result, prefix);
2201 strcat (result, post);
2202 GNUNET_free (def);
2204 GNUNET_free (orig);
2205 return result;
2206}
2207
2208
2209char *
2211 const struct GNUNET_CONFIGURATION_Handle *cfg,
2212 char *orig)
2213{
2214 char *dup;
2215 size_t i;
2216 size_t len;
2217
2218 for (i = 0; '\0' != orig[i]; i++)
2219 {
2220 if ('$' != orig[i])
2221 continue;
2222 dup = GNUNET_strdup (orig + i);
2223 dup = expand_dollar (cfg, dup, 0);
2224 GNUNET_assert (NULL != dup); /* make compiler happy */
2225 len = strlen (dup) + 1;
2226 orig = GNUNET_realloc (orig, i + len);
2227 GNUNET_memcpy (orig + i, dup, len);
2228 GNUNET_free (dup);
2229 }
2230 return orig;
2231}
2232
2233
2236 const struct GNUNET_CONFIGURATION_Handle *cfg,
2237 const char *section,
2238 const char *option,
2239 char **value)
2240{
2241 char *tmp;
2243
2245 section,
2246 option,
2247 &tmp);
2248 if (GNUNET_OK != ret)
2249 {
2251 "Failed to retrieve filename\n");
2252 *value = NULL;
2253 return ret;
2254 }
2256 tmp);
2258 GNUNET_free (tmp);
2259 if (*value == NULL)
2260 return GNUNET_SYSERR;
2261 return GNUNET_OK;
2262}
2263
2264
2267 const struct GNUNET_CONFIGURATION_Handle *cfg,
2268 const char *section,
2269 const char *option)
2270{
2271 static const char *yesno[] = {
2272 "YES",
2273 "NO",
2274 NULL
2275 };
2276 const char *val;
2278
2279 ret =
2281 section,
2282 option,
2283 yesno,
2284 &val);
2285 if (GNUNET_OK != ret)
2286 return ret;
2287 if (val == yesno[0])
2288 return GNUNET_YES;
2289 return GNUNET_NO;
2290}
2291
2292
2293int
2295 const struct GNUNET_CONFIGURATION_Handle *cfg,
2296 const char *section,
2297 const char *option,
2299 void *cb_cls)
2300{
2301 char *list;
2302 char *pos;
2303 char *end;
2304 char old;
2305 int ret;
2306
2307 if (GNUNET_OK !=
2309 section,
2310 option,
2311 &list))
2312 return 0;
2313 GNUNET_assert (list != NULL);
2314 ret = 0;
2315 pos = list;
2316 while (1)
2317 {
2318 while (pos[0] == ' ')
2319 pos++;
2320 if (strlen (pos) == 0)
2321 break;
2322 end = pos + 1;
2323 while ((end[0] != ' ') && (end[0] != '\0'))
2324 {
2325 if (end[0] == '\\')
2326 {
2327 switch (end[1])
2328 {
2329 case '\\':
2330 case ' ':
2331 memmove (end, &end[1], strlen (&end[1]) + 1);
2332
2333 case '\0':
2334 /* illegal, but just keep it */
2335 break;
2336
2337 default:
2338 /* illegal, but just ignore that there was a '/' */
2339 break;
2340 }
2341 }
2342 end++;
2343 }
2344 old = end[0];
2345 end[0] = '\0';
2346 if (strlen (pos) > 0)
2347 {
2348 ret++;
2349 if ( (NULL != cb) &&
2350 (GNUNET_OK != cb (cb_cls,
2351 pos)))
2352 {
2354 break;
2355 }
2356 }
2357 if (old == '\0')
2358 break;
2359 pos = end + 1;
2360 }
2361 GNUNET_free (list);
2362 return ret;
2363}
2364
2365
2372static char *
2373escape_name (const char *value)
2374{
2375 char *escaped;
2376 const char *rpos;
2377 char *wpos;
2378
2379 escaped = GNUNET_malloc (strlen (value) * 2 + 1);
2380 memset (escaped, 0, strlen (value) * 2 + 1);
2381 rpos = value;
2382 wpos = escaped;
2383 while (rpos[0] != '\0')
2384 {
2385 switch (rpos[0])
2386 {
2387 case '\\':
2388 case ' ':
2389 wpos[0] = '\\';
2390 wpos[1] = rpos[0];
2391 wpos += 2;
2392 break;
2393
2394 default:
2395 wpos[0] = rpos[0];
2396 wpos++;
2397 }
2398 rpos++;
2399 }
2400 return escaped;
2401}
2402
2403
2411static enum GNUNET_GenericReturnValue
2412test_match (void *cls,
2413 const char *fn)
2414{
2415 const char *of = cls;
2416
2417 return (0 == strcmp (of, fn))
2419 : GNUNET_OK;
2420}
2421
2422
2426 const char *section,
2427 const char *option,
2428 const char *value)
2429{
2430 char *escaped;
2431 char *old;
2432 char *nw;
2433
2434 if (GNUNET_SYSERR ==
2436 section,
2437 option,
2438 &test_match,
2439 (void *) value))
2440 return GNUNET_NO; /* already exists */
2441 if (GNUNET_OK !=
2442 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
2443 old = GNUNET_strdup ("");
2444 escaped = escape_name (value);
2445 nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2);
2446 strcpy (nw, old);
2447 if (strlen (old) > 0)
2448 strcat (nw, " ");
2449 strcat (nw, escaped);
2451 section,
2452 option,
2453 nw);
2454 GNUNET_free (old);
2455 GNUNET_free (nw);
2456 GNUNET_free (escaped);
2457 return GNUNET_OK;
2458}
2459
2460
2464 const char *section,
2465 const char *option,
2466 const char *value)
2467{
2468 char *list;
2469 char *pos;
2470 char *end;
2471 char *match;
2472 char old;
2473
2474 if (GNUNET_OK !=
2476 section,
2477 option,
2478 &list))
2479 return GNUNET_NO;
2480 match = escape_name (value);
2481 pos = list;
2482 while (1)
2483 {
2484 while (pos[0] == ' ')
2485 pos++;
2486 if (strlen (pos) == 0)
2487 break;
2488 end = pos + 1;
2489 while ((end[0] != ' ') && (end[0] != '\0'))
2490 {
2491 if (end[0] == '\\')
2492 {
2493 switch (end[1])
2494 {
2495 case '\\':
2496 case ' ':
2497 end++;
2498 break;
2499
2500 case '\0':
2501 /* illegal, but just keep it */
2502 break;
2503
2504 default:
2505 /* illegal, but just ignore that there was a '/' */
2506 break;
2507 }
2508 }
2509 end++;
2510 }
2511 old = end[0];
2512 end[0] = '\0';
2513 if (0 == strcmp (pos, match))
2514 {
2515 if (old != '\0')
2516 memmove (pos,
2517 &end[1],
2518 strlen (&end[1]) + 1);
2519 else
2520 {
2521 if (pos != list)
2522 pos[-1] = '\0';
2523 else
2524 pos[0] = '\0';
2525 }
2527 section,
2528 option,
2529 list);
2530 GNUNET_free (list);
2531 GNUNET_free (match);
2532 return GNUNET_OK;
2533 }
2534 if (old == '\0')
2535 break;
2536 end[0] = old;
2537 pos = end + 1;
2538 }
2539 GNUNET_free (list);
2540 GNUNET_free (match);
2541 return GNUNET_NO;
2542}
2543
2544
2548 const char *defaults_d)
2549{
2550 struct CollectFilesContext files_context = {
2551 .files = NULL,
2552 .files_length = 0,
2553 };
2554 enum GNUNET_GenericReturnValue fun_ret;
2555
2556 if (GNUNET_SYSERR ==
2557 GNUNET_DISK_directory_scan (defaults_d,
2559 &files_context))
2560 return GNUNET_SYSERR; /* no configuration at all found */
2561 qsort (files_context.files,
2562 files_context.files_length,
2563 sizeof (char *),
2564 &pstrcmp);
2565 for (unsigned int i = 0; i < files_context.files_length; i++)
2566 {
2567 const char *ext;
2568 const char *filename = files_context.files[i];
2569
2570 /* Examine file extension */
2571 ext = strrchr (filename, '.');
2572 if ( (NULL == ext) ||
2573 (0 != strcmp (ext,
2574 ".conf")) )
2575 {
2577 "Skipping file `%s'\n",
2578 filename);
2579 fun_ret = GNUNET_OK;
2580 continue;
2581 }
2583 filename);
2584 if (fun_ret != GNUNET_OK)
2585 break;
2586 }
2587 if (files_context.files_length > 0)
2588 {
2589 for (size_t i = 0; i < files_context.files_length; i++)
2590 GNUNET_free (files_context.files[i]);
2591 GNUNET_array_grow (files_context.files,
2592 files_context.files_length,
2593 0);
2594 }
2595 return fun_ret;
2596}
2597
2598
2599char *
2601 const struct GNUNET_OS_ProjectData *pd)
2602{
2603 char *cfg_fn;
2604 const char *xdg = getenv ("XDG_CONFIG_HOME");
2605
2606 if (NULL != xdg)
2607 GNUNET_asprintf (&cfg_fn,
2608 "%s%s%s",
2609 xdg,
2611 pd->config_file);
2612 else
2613 cfg_fn = GNUNET_strdup (pd->user_config_file);
2614
2615 if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2616 return cfg_fn;
2617 GNUNET_free (cfg_fn);
2618
2619 /* Fall back to /etc/ for the default configuration.
2620 Should be okay to use forward slashes here. */
2621
2622 GNUNET_asprintf (&cfg_fn,
2623 "/etc/%s",
2624 pd->config_file);
2625 if (GNUNET_OK ==
2627 return cfg_fn;
2628 GNUNET_free (cfg_fn);
2629
2630 GNUNET_asprintf (&cfg_fn,
2631 "/etc/%s/%s",
2632 pd->project_dirname,
2633 pd->config_file);
2634 if (GNUNET_OK ==
2636 return cfg_fn;
2637
2638 GNUNET_free (cfg_fn);
2639 return NULL;
2640}
2641
2642
2646 const char *filename)
2647{
2648 char *baseconfig;
2649 const char *base_config_varname;
2650
2651 if (cfg->load_called)
2652 {
2653 /* FIXME: Make this a GNUNET_assert later */
2654 GNUNET_break (0);
2656 }
2657 cfg->load_called = true;
2658 if (NULL != filename)
2659 {
2662 }
2663
2664 base_config_varname = cfg->pd->base_config_varname;
2665
2666 if ((NULL != base_config_varname)
2667 && (NULL != (baseconfig = getenv (base_config_varname))))
2668 {
2669 baseconfig = GNUNET_strdup (baseconfig);
2670 }
2671 else
2672 {
2673 char *ipath;
2674
2677 if (NULL == ipath)
2678 {
2679 GNUNET_break (0);
2680 return GNUNET_SYSERR;
2681 }
2682 GNUNET_asprintf (&baseconfig,
2683 "%s%s",
2684 ipath,
2685 "config.d");
2686 GNUNET_free (ipath);
2687 }
2688
2689 {
2690 char *dname = GNUNET_STRINGS_filename_expand (baseconfig);
2691
2692 GNUNET_free (baseconfig);
2693
2694 if ((GNUNET_YES ==
2696 GNUNET_YES)) &&
2697 (GNUNET_SYSERR ==
2699 dname)))
2700 {
2702 "Failed to load base configuration from '%s'\n",
2703 filename);
2704 GNUNET_free (dname);
2705 return GNUNET_SYSERR; /* no configuration at all found */
2706 }
2707 GNUNET_free (dname);
2708 }
2709 if ((NULL != filename) &&
2710 (GNUNET_OK !=
2712 filename)))
2713 {
2714 /* specified configuration not found */
2716 "Failed to load configuration from file '%s'\n",
2717 filename);
2718 return GNUNET_SYSERR;
2719 }
2720 if (((GNUNET_YES !=
2722 "PATHS",
2723 "DEFAULTCONFIG"))) &&
2724 (filename != NULL))
2726 "PATHS",
2727 "DEFAULTCONFIG",
2728 filename);
2729 return GNUNET_OK;
2730}
2731
2732
2741static void
2742print_filename_option (void *cls,
2743 const char *section,
2744 const char *option,
2745 const char *value)
2746{
2747 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
2748
2749 char *value_fn;
2750 char *fn;
2751
2754 section,
2755 option,
2756 &value_fn));
2757 fn = GNUNET_STRINGS_filename_expand (value_fn);
2758 if (NULL == fn)
2759 fn = value_fn;
2760 else
2761 GNUNET_free (value_fn);
2762 fprintf (stdout,
2763 "%s = %s\n",
2764 option,
2765 fn);
2766 GNUNET_free (fn);
2767}
2768
2769
2778static void
2779print_option (void *cls,
2780 const char *section,
2781 const char *option,
2782 const char *value)
2783{
2784 (void) cls;
2785 (void) section;
2786
2787 fprintf (stdout,
2788 "%s = %s\n",
2789 option,
2790 value);
2791}
2792
2793
2800static void
2801print_section_name (void *cls,
2802 const char *section)
2803{
2804 (void) cls;
2805 fprintf (stdout,
2806 "%s\n",
2807 section);
2808}
2809
2810
2811void
2813 void *cls,
2814 char *const *args,
2815 const char *cfgfile,
2816 const struct GNUNET_CONFIGURATION_Handle *cfg)
2817{
2818 struct GNUNET_CONFIGURATION_ConfigSettings *cs = cls;
2819 struct GNUNET_CONFIGURATION_Handle *out = NULL;
2820 struct GNUNET_CONFIGURATION_Handle *ncfg = NULL;
2821
2822 (void) args;
2823 if (cs->diagnostics)
2824 {
2825 /* Re-parse the configuration with diagnostics enabled. */
2828 if (GNUNET_OK !=
2830 cfgfile))
2831 {
2832 fprintf (stderr,
2833 _ ("Failed to load config file `%s'"),
2834 cfgfile);
2835 return;
2836 }
2837 cfg = ncfg;
2838 }
2839
2840 if (cs->full)
2841 cs->rewrite = GNUNET_YES;
2842 if (cs->list_sections)
2843 {
2844 fprintf (stderr,
2845 _ ("The following sections are available:\n"));
2848 NULL);
2849 return;
2850 }
2851 if ( (! cs->rewrite) &&
2852 (NULL == cs->section) )
2853 {
2854 char *serialization;
2855
2856 if (! cs->diagnostics)
2857 {
2858 fprintf (stderr,
2859 _ ("%s, %s or %s argument is required\n"),
2860 "--section",
2861 "--list-sections",
2862 "--diagnostics");
2864 return;
2865 }
2867 fprintf (stdout,
2868 "%s",
2869 serialization);
2870 GNUNET_free (serialization);
2871 }
2872 else if ( (NULL != cs->section) &&
2873 (NULL == cs->value) )
2874 {
2875 if (NULL == cs->option)
2876 {
2878 cfg,
2879 cs->section,
2880 cs->is_filename
2882 : &print_option,
2883 (void *) cfg);
2884 }
2885 else
2886 {
2887 char *value;
2888
2889 if (cs->is_filename)
2890 {
2891 if (GNUNET_OK !=
2893 cs->section,
2894 cs->option,
2895 &value))
2896 {
2898 cs->section,
2899 cs->option);
2901 return;
2902 }
2903 }
2904 else
2905 {
2906 if (GNUNET_OK !=
2908 cs->section,
2909 cs->option,
2910 &value))
2911 {
2913 cs->section,
2914 cs->option);
2916 return;
2917 }
2918 }
2919 fprintf (stdout,
2920 "%s\n",
2921 value);
2923 }
2924 }
2925 else if (NULL != cs->section)
2926 {
2927 if (NULL == cs->option)
2928 {
2929 fprintf (stderr,
2930 _ ("--option argument required to set value\n"));
2932 return;
2933 }
2936 cs->section,
2937 cs->option,
2938 cs->value);
2939 cs->rewrite = GNUNET_YES;
2940 }
2941 if (cs->rewrite)
2942 {
2943 char *cfg_fn = NULL;
2944
2945 if (NULL == out)
2947
2948 if (NULL == cfgfile)
2949 {
2950 const char *xdg = getenv ("XDG_CONFIG_HOME");
2951
2952 if (NULL != xdg)
2953 GNUNET_asprintf (&cfg_fn,
2954 "%s%s%s",
2955 xdg,
2957 cfg->pd->config_file);
2958 else
2959 cfg_fn = GNUNET_strdup (cfg->pd->user_config_file);
2960 cfgfile = cfg_fn;
2961 }
2962
2963 if (! cs->full)
2964 {
2965 struct GNUNET_CONFIGURATION_Handle *def;
2966
2968 if (GNUNET_OK !=
2970 NULL))
2971 {
2972 fprintf (stderr,
2973 _ ("failed to load configuration defaults"));
2974 cs->global_ret = 1;
2977 GNUNET_free (cfg_fn);
2978 return;
2979 }
2980 if (GNUNET_OK !=
2982 out,
2983 cfgfile))
2984 cs->global_ret = 2;
2986 }
2987 else
2988 {
2989 if (GNUNET_OK !=
2991 cfgfile))
2992 cs->global_ret = 2;
2993 }
2994 GNUNET_free (cfg_fn);
2995 }
2996 if (NULL != out)
2998 if (NULL != ncfg)
3000}
3001
3002
3003void
3006{
3007 GNUNET_free (cs->option);
3008 GNUNET_free (cs->section);
3009 GNUNET_free (cs->value);
3010}
3011
3012
3013const struct GNUNET_OS_ProjectData *
3015 const struct GNUNET_CONFIGURATION_Handle *cfg)
3016{
3017 return cfg->pd;
3018}
3019
3020
3021/* end of configuration.c */
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
static bool do_skip(const char *sec, const char *key)
Should we skip this configuration entry when serializing?
static void print_filename_option(void *cls, const char *section, const char *option, const char *value)
Print each option in a given section as a filename.
static struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
static enum GNUNET_GenericReturnValue handle_inline(struct GNUNET_CONFIGURATION_Handle *cfg, const char *path_or_glob, bool path_is_glob, const char *restrict_section, const char *source_filename, unsigned int source_lineno)
Handle an inline directive.
static void print_section_name(void *cls, const char *section)
Print out given section name.
static char * escape_name(const char *value)
FIXME.
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) a...
static enum GNUNET_GenericReturnValue test_match(void *cls, const char *fn)
FIXME.
static struct ConfigSection * find_section(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Find a section entry from a configuration.
static int pstrcmp(const void *a, const void *b)
static 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...
static enum GNUNET_GenericReturnValue collect_files_cb(void *cls, const char *filename)
Function called with a filename.
#define LOG(kind,...)
static void copy_entry(void *cls, const char *section, const char *option, const char *value)
Copy a configuration value to the given target configuration.
static void print_option(void *cls, const char *section, const char *option, const char *value)
Print each option in a given section.
static void dump_os_ipk(const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_Buffer *buf, enum GNUNET_OS_InstallationPathKind ipk)
Dump an os installation path to a buffer.
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.
char * getenv()
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition gnunet-arm.c:98
static int start
Set if we are to start default services (including ARM).
Definition gnunet-arm.c:38
static int list
Set if we should print a list of currently running services.
Definition gnunet-arm.c:68
static int ret
Final status code.
Definition gnunet-arm.c:93
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static int end
Set if we are to shutdown all services (including ARM).
Definition gnunet-arm.c:33
static int prefix
If printing the value of PREFIX has been requested.
static char * line
Desired phone line (string to be converted to a hash).
struct GNUNET_HashCode key
The key used in the DHT.
static char * filename
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition gnunet-fs.c:35
static OpusEncoder * enc
OPUS encoder.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static char * res
Currently read line or NULL on EOF.
static char * value
Value of the record to add/remove.
static size_t data_size
Number of bytes in data.
static int result
Global testing status.
static void cleanup()
Cleanup task.
static struct GNUNET_Process * p
Helper process we started.
Definition gnunet-uri.c:38
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.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(const struct GNUNET_OS_ProjectData *pd)
Create a new configuration object.
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.
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.
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.
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.
void GNUNET_CONFIGURATION_remove_section(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Remove the given section and all options in it.
enum GNUNET_GenericReturnValue(* GNUNET_CONFIGURATION_Callback)(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Signature of a function to be run with a configuration.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
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.
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.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
void GNUNET_CONFIGURATION_config_settings_free(struct GNUNET_CONFIGURATION_ConfigSettings *cs)
Free resources associated with cs.
void GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over all options in the configuration.
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.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse_and_run(const struct GNUNET_OS_ProjectData *pd, const char *filename, GNUNET_CONFIGURATION_Callback cb, void *cb_cls)
Parse a configuration file filename and run the function cb with the resulting configuration object.
void GNUNET_CONFIGURATION_config_tool_run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main task to run to perform operations typical for gnunet-config as per the configuration settings gi...
void(* GNUNET_CONFIGURATION_SectionIterator)(void *cls, const char *section)
Function to iterate over all configuration sections.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *source_filename)
De-serializes configuration.
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.
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".
char * GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
Serializes the given configuration.
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.
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.
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.
char * GNUNET_CONFIGURATION_default_filename(const struct GNUNET_OS_ProjectData *pd)
Return the filename of the default configuration filename that is used when no explicit configuration...
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...
void GNUNET_CONFIGURATION_set_value_float(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, float number)
Set a configuration value that should be a float.
const struct GNUNET_OS_ProjectData * GNUNET_CONFIGURATION_get_project_data(const struct GNUNET_CONFIGURATION_Handle *cfg)
Return the project data associated with this configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
struct GNUNET_CONFIGURATION_Handle * GNUNET_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.
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.
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.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load_from(struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d)
Load default configuration.
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.
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.
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.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
void(* GNUNET_CONFIGURATION_Iterator)(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
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.
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.
char * GNUNET_CONFIGURATION_serialize_diagnostics(const struct GNUNET_CONFIGURATION_Handle *cfg)
Serializes the given configuration with diagnostics information.
void GNUNET_CONFIGURATION_enable_diagnostics(struct GNUNET_CONFIGURATION_Handle *cfg)
Enable extra diagnostics.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition disk.c:1308
int GNUNET_DISK_glob(const char *glob_pattern, GNUNET_FileNameCallback callback, void *callback_cls)
Find all files matching a glob pattern.
Definition disk.c:1063
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition disk.c:745
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:565
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition disk.c:235
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition disk.c:1140
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition disk.c:466
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition disk.c:1386
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition disk.c:664
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition disk.c:720
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition disk.c:881
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_OPEN_TRUNCATE
Truncate file if it exists.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_GROUP_READ
Group can read.
@ GNUNET_DISK_PERM_GROUP_WRITE
Group can write.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
enum GNUNET_GenericReturnValue(* GNUNET_FileNameCallback)(void *cls, const char *filename)
Function called with a filename.
#define GNUNET_log(kind,...)
char * GNUNET_buffer_reap_str(struct GNUNET_Buffer *buf)
Clear the buffer and return the string it contained.
Definition buffer.c:89
void GNUNET_buffer_write_fstr(struct GNUNET_Buffer *buf, const char *fmt,...) __attribute__((format(printf
Write a 0-terminated formatted string to a buffer, excluding the 0-terminator.
void GNUNET_buffer_write_str(struct GNUNET_Buffer *buf, const char *str)
Write a 0-terminated string to a buffer, excluding the 0-terminator.
Definition buffer.c:77
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ 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.
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ 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_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_OS_installation_get_path(const struct GNUNET_OS_ProjectData *pd, enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
GNUNET_OS_InstallationPathKind
Possible installation paths to request.
@ GNUNET_OS_IPK_SELF_PREFIX
Return the installation directory of this application, not the one of the overall GNUnet installation...
@ GNUNET_OS_IPK_ICONDIR
Return the prefix of the path with application icons (share/icons/).
@ GNUNET_OS_IPK_DATADIR
Return the directory where data is installed (share/gnunet/)
@ GNUNET_OS_IPK_DOCDIR
Return the prefix of the path with documentation files, including the license (share/doc/gnunet/).
@ GNUNET_OS_IPK_LOCALEDIR
Return the directory where translations are installed (share/locale/)
@ GNUNET_OS_IPK_LIBDIR
Return the directory where libraries are installed.
@ GNUNET_OS_IPK_PREFIX
Return the "PREFIX" directory given to configure.
@ GNUNET_OS_IPK_BINDIR
Return the directory where the program binaries are installed.
@ GNUNET_OS_IPK_LIBEXECDIR
Return the directory where helper binaries are installed (lib/gnunet/libexec/)
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition strings.c:525
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition strings.c:837
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_time_to_relative(const char *fancy_time, struct GNUNET_TIME_Relative *rtime)
Convert a given fancy human-readable time to our internal representation.
Definition strings.c:259
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_size_to_bytes(const char *fancy_size, unsigned long long *size)
Convert a given fancy human-readable size to bytes.
Definition strings.c:235
static unsigned int size
Size of the "table".
Definition peer.c:68
#define DIR_SEPARATOR_STR
Definition platform.h:167
#define _(String)
GNU gettext support macro.
Definition platform.h:179
#define SIZE_MAX
Definition platform.h:209
#define EXIT_INVALIDARGUMENT
Definition platform.h:254
#define EXIT_NOTCONFIGURED
Definition platform.h:270
uint32_t number
Closure to collect_files_cb.
char ** files
Collected files from globbing.
unsigned int files_length
Size of the files array.
configuration entry
char * hint_filename
Diagnostics information for the filename.
struct ConfigEntry * next
This is a linked list.
char * key
key for this entry
unsigned int hint_lineno
Diagnostics information for the line number.
char * val
current, committed value
char * hint_restrict_section
Was this configuration file parsed via @inline-secret@?
struct ConfigFile * next
char * source_filename
Source filename.
bool hint_inaccessible
Was this configuration file inaccessible?
struct ConfigFile * prev
unsigned int level
Level in the tree of loaded config files.
configuration section
char * name
name of the section
char * hint_inlined_from_filename
For secret sections: Where was this inlined from?
struct ConfigEntry * entries
entries in the section
bool inaccessible
Is the configuration section marked as inaccessible?
struct ConfigSection * next
This is a linked list.
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.
Used for diffing a configuration object against the default one.
const struct GNUNET_CONFIGURATION_Handle * cfg_default
struct GNUNET_CONFIGURATION_Handle * cfgDiff
Dynamically growing buffer.
Closure for GNUNET_CONFIGURATION_config_tool_run() with settings for what should be done with the con...
int full
Should the generated configuration file contain the whole configuration?
int global_ret
Return value from the operation, to be returned from 'main'.
int diagnostics
Should we give extra diagnostics?
int list_sections
Whether to show the sections.
int rewrite
Should we write out the configuration file, even if no value was changed?
int is_filename
Treat option as a filename.
struct ConfigFile * loaded_files_tail
Linked list of loaded files.
bool load_called
Was the configuration ever loaded via GNUNET_CONFIGURATION_load?
unsigned int current_nest_level
Current nesting level of file loading.
const struct GNUNET_OS_ProjectData * pd
Project data for this configuration object.
struct ConfigSection * sections
Configuration sections.
struct ConfigFile * loaded_files_head
Linked list of loaded files.
char * main_filename
Name of the entry point configuration file.
enum GNUNET_GenericReturnValue dirty
Modification indication since last save GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on err...
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...
Handle used to access files (and pipes).
Project-specific data used to help the OS subsystem find installation paths.
const char * base_config_varname
Name of an environment variable that can be used to override the location from which default configur...
const char * project_dirname
Name of the project that is used in the "libexec" prefix, For example, "gnunet".
const char * user_config_file
Configuration file name to use (if $XDG_CONFIG_HOME is not set).
const char * config_file
Configuration file name (in $XDG_CONFIG_HOME) to use.
Time for relative time used by GNUnet, in microseconds.

Function Documentation

◆ collect_files_cb()

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

Function called with a filename.

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

Definition at line 394 of file configuration.c.

396{
397 struct CollectFilesContext *igc = cls;
398
400 igc->files_length,
402 return GNUNET_OK;
403}

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

Referenced by GNUNET_CONFIGURATION_load_from(), and handle_inline().

Here is the caller graph for this function:

◆ find_section()

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

Find a section entry from a configuration.

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

Definition at line 414 of file configuration.c.

416{
417 struct ConfigSection *pos;
418
419 if (NULL == cfg)
420 return NULL;
421 pos = cfg->sections;
422 while ( (NULL != pos) &&
423 (0 != strcasecmp (section,
424 pos->name)) )
425 pos = pos->next;
426 return pos;
427}

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

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

Here is the caller graph for this function:

◆ pstrcmp()

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

Definition at line 431 of file configuration.c.

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

Referenced by GNUNET_CONFIGURATION_load_from(), and handle_inline().

Here is the caller graph for this function:

◆ handle_inline()

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

Handle an inline directive.

Returns
GNUNET_SYSERR on error, GNUNET_OK otherwise

Definition at line 445 of file configuration.c.

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

References cfg, cleanup(), collect_files_cb(), GNUNET_CONFIGURATION_Handle::current_nest_level, GNUNET_CONFIGURATION_Handle::diagnostics, ConfigSection::entries, CollectFilesContext::files, CollectFilesContext::files_length, find_section(), GNUNET_array_grow, GNUNET_asprintf(), GNUNET_assert, GNUNET_break, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_parse(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_CONTAINER_DLL_insert_tail, GNUNET_DISK_file_test_read(), GNUNET_DISK_glob(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_new, GNUNET_OK, GNUNET_strdup, GNUNET_STRINGS_filename_expand(), GNUNET_SYSERR, ConfigFile::hint_inaccessible, ConfigSection::hint_inlined_from_filename, ConfigSection::hint_inlined_from_line, ConfigFile::hint_restrict_section, ConfigSection::hint_secret_filename, ConfigSection::hint_secret_stat, ConfigSection::inaccessible, ConfigFile::level, GNUNET_CONFIGURATION_Handle::loaded_files_head, GNUNET_CONFIGURATION_Handle::loaded_files_tail, LOG, ConfigSection::name, ConfigSection::next, GNUNET_CONFIGURATION_Handle::pd, pstrcmp(), GNUNET_CONFIGURATION_Handle::restrict_section, GNUNET_CONFIGURATION_Handle::sections, and ConfigFile::source_filename.

Referenced by GNUNET_CONFIGURATION_deserialize().

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

◆ find_entry()

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

Find an entry from a configuration.

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

Definition at line 677 of file configuration.c.

680{
681 struct ConfigSection *sec;
682
683 if (NULL == (sec = find_section (cfg,
684 section)))
685 return NULL;
686 for (struct ConfigEntry *pos = sec->entries;
687 pos != NULL;
688 pos = pos->next)
689 if (0 == strcasecmp (key,
690 pos->key))
691 return pos;
692 if (sec->inaccessible)
693 {
695 "Section '%s' is marked as inaccessible, because the configuration "
696 "file that contains the section can't be read. Attempts to use "
697 "option '%s' will fail.\n",
698 section,
699 key);
700 return NULL;
701 }
702 return NULL;
703}

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

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

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

◆ set_entry_hint()

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

Set a configuration hint.

Parameters
cfgconfiguration handle
sectionsection
optionconfig option
hint_filename
hint_line

Definition at line 716 of file configuration.c.

721{
722 struct ConfigEntry *e = find_entry (cfg, section, option);
723 if (! cfg->diagnostics)
724 return;
725 if (! e)
726 return;
728 e->hint_lineno = hint_line;
729}

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

Referenced by GNUNET_CONFIGURATION_deserialize().

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

◆ do_skip()

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

Should we skip this configuration entry when serializing?

Parameters
secsection name
keykey
Returns
true if we should skip it

Definition at line 1137 of file configuration.c.

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

References key.

Referenced by GNUNET_CONFIGURATION_serialize(), and GNUNET_CONFIGURATION_serialize_diagnostics().

Here is the caller graph for this function:

◆ dump_os_ipk()

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

Dump an os installation path to a buffer.

Parameters
cfgconfiguration
bufbuffer to write to
ipkwhich path to print

Definition at line 1271 of file configuration.c.

1275{
1277 ipk);
1278 const char *ipkname;
1279 switch (ipk)
1280 {
1282 ipkname = "IPK_DATADIR";
1283 break;
1285 ipkname = "IPK_BINDIR";
1286 break;
1288 ipkname = "IPK_LIBDIR";
1289 break;
1291 ipkname = "IPK_PREFIX";
1293 ipkname = "IPK_LOCALEDIR";
1294 break;
1296 ipkname = "IPK_ICONDIR";
1298 ipkname = "IPK_DOCDIR";
1299 break;
1301 ipkname = "IPK_LIBEXECDIR";
1302 break;
1304 ipkname = "IPK_SELF_PREFIX";
1305 break;
1306 default:
1307 ipkname = "??";
1308 break;
1309 }
1311 "# %s = %s\n",
1312 ipkname,
1313 v);
1314 GNUNET_free (v);
1315}

References cfg, GNUNET_buffer_write_fstr(), GNUNET_free, GNUNET_OS_installation_get_path(), GNUNET_OS_IPK_BINDIR, GNUNET_OS_IPK_DATADIR, GNUNET_OS_IPK_DOCDIR, GNUNET_OS_IPK_ICONDIR, GNUNET_OS_IPK_LIBDIR, GNUNET_OS_IPK_LIBEXECDIR, GNUNET_OS_IPK_LOCALEDIR, GNUNET_OS_IPK_PREFIX, GNUNET_OS_IPK_SELF_PREFIX, and GNUNET_CONFIGURATION_Handle::pd.

Referenced by GNUNET_CONFIGURATION_serialize_diagnostics().

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

◆ copy_entry()

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

Copy a configuration value to the given target configuration.

Overwrites existing entries.

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

Definition at line 1637 of file configuration.c.

1641{
1642 struct GNUNET_CONFIGURATION_Handle *dst = cls;
1643
1645 section,
1646 option,
1647 value);
1648}

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

1680{
1681 struct DiffHandle *dh = cls;
1682 struct ConfigEntry *entNew;
1683
1684 entNew = find_entry (dh->cfg_default, section, option);
1685 if ((NULL != entNew) && (NULL != entNew->val) &&
1686 (0 == strcmp (entNew->val, value)))
1687 return;
1689 section,
1690 option,
1691 value);
1692}

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

2059{
2060 char *prefix;
2061 char *result;
2062 char *start;
2063 const char *post;
2064 const char *env;
2065 char *def;
2066 char *end;
2067 unsigned int lopen;
2068 char erased_char;
2069 char *erased_pos;
2070 size_t len;
2071
2072 if (NULL == orig)
2073 return NULL;
2074 if (depth > 128)
2075 {
2077 "Recursive expansion suspected, aborting $-expansion for term `%s'\n",
2078 orig);
2079 return orig;
2080 }
2082 "Asked to $-expand %s\n",
2083 orig);
2084 if ('$' != orig[0])
2085 {
2087 "Doesn't start with $ - not expanding\n");
2088 return orig;
2089 }
2090 erased_char = 0;
2091 erased_pos = NULL;
2092 if ('{' == orig[1])
2093 {
2094 start = &orig[2];
2095 lopen = 1;
2096 end = &orig[1];
2097 while (lopen > 0)
2098 {
2099 end++;
2100 switch (*end)
2101 {
2102 case '}':
2103 lopen--;
2104 break;
2105
2106 case '{':
2107 lopen++;
2108 break;
2109
2110 case '\0':
2112 "Missing closing `}' in option `%s'\n",
2113 orig);
2114 return orig;
2115
2116 default:
2117 break;
2118 }
2119 }
2120 erased_char = *end;
2121 erased_pos = end;
2122 *end = '\0';
2123 post = end + 1;
2124 def = strchr (orig, ':');
2125 if (NULL != def)
2126 {
2127 *def = '\0';
2128 def++;
2129 if (('-' == *def) || ('=' == *def))
2130 def++;
2131 def = GNUNET_strdup (def);
2132 }
2133 }
2134 else
2135 {
2136 int i;
2137
2138 start = &orig[1];
2139 def = NULL;
2140 i = 0;
2141 while ( (orig[i] != '/') &&
2142 (orig[i] != '\\') &&
2143 (orig[i] != '\0') &&
2144 (orig[i] != ' ') )
2145 i++;
2146 if (orig[i] == '\0')
2147 {
2148 post = "";
2149 }
2150 else
2151 {
2152 erased_char = orig[i];
2153 erased_pos = &orig[i];
2154 orig[i] = '\0';
2155 post = &orig[i + 1];
2156 }
2157 }
2159 "Split into `%s' and `%s' with default %s\n",
2160 start,
2161 post,
2162 def);
2163 if (GNUNET_OK !=
2165 "PATHS",
2166 start,
2167 &prefix))
2168 {
2169 if (NULL == (env = getenv (start)))
2170 {
2171 /* try default */
2172 def = expand_dollar (cfg,
2173 def,
2174 depth + 1);
2175 env = def;
2176 }
2177 if (NULL == env)
2178 {
2180 if (erased_pos)
2181 *erased_pos = erased_char;
2183 "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n",
2184 start,
2185 orig);
2187 return orig;
2188 }
2190 }
2192 prefix);
2193 if ((erased_pos) && ('}' != erased_char))
2194 {
2195 len = strlen (prefix) + 1;
2196 prefix = GNUNET_realloc (prefix, len + 1);
2197 prefix[len - 1] = erased_char;
2198 prefix[len] = '\0';
2199 }
2200 result = GNUNET_malloc (strlen (prefix) + strlen (post) + 1);
2201 strcpy (result, prefix);
2202 strcat (result, post);
2203 GNUNET_free (def);
2205 GNUNET_free (orig);
2206 return result;
2207}

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

Referenced by expand_dollar(), and GNUNET_CONFIGURATION_expand_dollar().

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

◆ escape_name()

static char * escape_name ( const char *  value)
static

FIXME.

Parameters
valueFIXME
Returns
FIXME

Definition at line 2374 of file configuration.c.

2375{
2376 char *escaped;
2377 const char *rpos;
2378 char *wpos;
2379
2380 escaped = GNUNET_malloc (strlen (value) * 2 + 1);
2381 memset (escaped, 0, strlen (value) * 2 + 1);
2382 rpos = value;
2383 wpos = escaped;
2384 while (rpos[0] != '\0')
2385 {
2386 switch (rpos[0])
2387 {
2388 case '\\':
2389 case ' ':
2390 wpos[0] = '\\';
2391 wpos[1] = rpos[0];
2392 wpos += 2;
2393 break;
2394
2395 default:
2396 wpos[0] = rpos[0];
2397 wpos++;
2398 }
2399 rpos++;
2400 }
2401 return escaped;
2402}

References GNUNET_malloc, and value.

Referenced by GNUNET_CONFIGURATION_append_value_filename(), and GNUNET_CONFIGURATION_remove_value_filename().

Here is the caller graph for this function:

◆ test_match()

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

FIXME.

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

Definition at line 2413 of file configuration.c.

2415{
2416 const char *of = cls;
2417
2418 return (0 == strcmp (of, fn))
2420 : GNUNET_OK;
2421}

References GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_CONFIGURATION_append_value_filename().

Here is the caller graph for this function:

◆ print_filename_option()

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

Print each option in a given section as a filename.

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

Definition at line 2743 of file configuration.c.

2747{
2748 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
2749
2750 char *value_fn;
2751 char *fn;
2752
2755 section,
2756 option,
2757 &value_fn));
2758 fn = GNUNET_STRINGS_filename_expand (value_fn);
2759 if (NULL == fn)
2760 fn = value_fn;
2761 else
2762 GNUNET_free (value_fn);
2763 fprintf (stdout,
2764 "%s = %s\n",
2765 option,
2766 fn);
2767 GNUNET_free (fn);
2768}

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

Referenced by GNUNET_CONFIGURATION_config_tool_run().

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

◆ print_option()

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

Print each option in a given section.

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

Definition at line 2780 of file configuration.c.

2784{
2785 (void) cls;
2786 (void) section;
2787
2788 fprintf (stdout,
2789 "%s = %s\n",
2790 option,
2791 value);
2792}

References value.

Referenced by GNUNET_CONFIGURATION_config_tool_run().

Here is the caller graph for this function:

◆ print_section_name()

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

Print out given section name.

Parameters
clsunused
sectiona section in the configuration file

Definition at line 2802 of file configuration.c.

2804{
2805 (void) cls;
2806 fprintf (stdout,
2807 "%s\n",
2808 section);
2809}

Referenced by GNUNET_CONFIGURATION_config_tool_run().

Here is the caller graph for this function: