GNUnet 0.21.2
configuration.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2006, 2007, 2008, 2009, 2013, 2020, 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
29
30#define LOG(kind, ...) GNUNET_log_from (kind, "util", __VA_ARGS__)
31
32#define LOG_STRERROR_FILE(kind, syscall, filename) \
33 GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
34
39{
44
48 char *key;
49
53 char *val;
54
59
63 unsigned int hint_lineno;
64};
65
66
71{
76
81
85 char *name;
86
94
99
104
109
114};
115
117{
122
126 unsigned int level;
127
129
131
137
142};
143
144
149{
154
159
164
168 unsigned int current_nest_level;
169
174
181
186
191
197 const char *restrict_section;
198};
199
200
206{
208
210};
211
212
213void
216{
217 cfg->diagnostics = true;
218}
219
220
223{
225 char *p;
226
228 /* make certain values from the project data available
229 as PATHS */
231 if (NULL != p)
232 {
234 "PATHS",
235 "DATADIR",
236 p);
237 GNUNET_free (p);
238 }
240 if (NULL != p)
241 {
243 "PATHS",
244 "LIBDIR",
245 p);
246 GNUNET_free (p);
247 }
249 if (NULL != p)
250 {
252 "PATHS",
253 "BINDIR",
254 p);
255 GNUNET_free (p);
256 }
258 if (NULL != p)
259 {
261 "PATHS",
262 "PREFIX",
263 p);
264 GNUNET_free (p);
265 }
267 if (NULL != p)
268 {
270 "PATHS",
271 "LOCALEDIR",
272 p);
273 GNUNET_free (p);
274 }
276 if (NULL != p)
277 {
279 "PATHS",
280 "ICONDIR",
281 p);
282 GNUNET_free (p);
283 }
285 if (NULL != p)
286 {
288 "PATHS",
289 "DOCDIR",
290 p);
291 GNUNET_free (p);
292 }
294 if (NULL != p)
295 {
297 "PATHS",
298 "LIBEXECDIR",
299 p);
300 GNUNET_free (p);
301 }
302 return cfg;
303}
304
305
306void
308{
309 struct ConfigSection *sec;
310 struct ConfigFile *cf;
311
312 while (NULL != (sec = cfg->sections))
314 while (NULL != (cf = cfg->loaded_files_head))
315 {
320 cf);
321 GNUNET_free (cf);
322 }
325}
326
327
331 void *cb_cls)
332{
335
337 if (GNUNET_OK !=
339 filename))
340 {
341 GNUNET_break (0);
343 return GNUNET_SYSERR;
344 }
345 ret = cb (cb_cls, cfg);
347 return ret;
348}
349
350
355{
359 char **files;
360
364 unsigned int files_length;
365};
366
367
379 const char *filename)
380{
381 struct CollectFilesContext *igc = cls;
382
384 igc->files_length,
386 return GNUNET_OK;
387}
388
389
397static struct ConfigSection *
399 const char *section)
400{
401 struct ConfigSection *pos;
402
403 pos = cfg->sections;
404 while ((pos != NULL) && (0 != strcasecmp (section, pos->name)))
405 pos = pos->next;
406 return pos;
407}
408
409
410static int
411pstrcmp (const void *a, const void *b)
412{
413 return strcmp (*((const char **) a), *((const char **) b));
414}
415
416
424 const char *path_or_glob,
425 bool path_is_glob,
426 const char *restrict_section,
427 const char *source_filename,
428 unsigned int source_lineno)
429{
430 char *inline_path = NULL;
431 struct GNUNET_CONFIGURATION_Handle *other_cfg = NULL;
432 struct CollectFilesContext igc = {
433 .files = NULL,
434 .files_length = 0,
435 };
436 enum GNUNET_GenericReturnValue fun_ret;
437 unsigned int old_nest_level = cfg->current_nest_level++;
438
439 /* We support the section restriction only for non-globs */
440 GNUNET_assert (! (path_is_glob && (NULL != restrict_section)));
441
442 if (NULL == source_filename)
443 {
445 "Refusing to parse inline configurations, "
446 "not allowed without source filename!\n");
447 fun_ret = GNUNET_SYSERR;
448 goto cleanup;
449 }
450
451 if ('/' == *path_or_glob)
452 inline_path = GNUNET_strdup (path_or_glob);
453 else
454 {
455 /* We compute the canonical, absolute path first,
456 so that relative imports resolve properly with symlinked
457 config files. */
458 char *source_realpath;
459 char *endsep;
460
461 source_realpath = realpath (source_filename,
462 NULL);
463 if (NULL == source_realpath)
464 {
465 /* Couldn't even resolve path of base dir. */
466 GNUNET_break (0);
467 /* failed to parse included config */
468 fun_ret = GNUNET_SYSERR;
469 goto cleanup;
470 }
471 endsep = strrchr (source_realpath, '/');
472 GNUNET_assert (NULL != endsep);
473 *endsep = '\0';
474 GNUNET_asprintf (&inline_path,
475 "%s/%s",
476 source_realpath,
477 path_or_glob);
478 free (source_realpath);
479 }
480
481 if (path_is_glob)
482 {
483 int nret;
484
486 "processing config glob '%s'\n",
487 inline_path);
488
489 nret = GNUNET_DISK_glob (inline_path, collect_files_cb, &igc);
490 if (-1 == nret)
491 {
492 fun_ret = GNUNET_SYSERR;
493 goto cleanup;
494 }
495 GNUNET_assert (nret == igc.files_length);
496 qsort (igc.files, igc.files_length, sizeof (char *), pstrcmp);
497 for (int i = 0; i < nret; i++)
498 {
499 if (GNUNET_OK !=
501 igc.files[i]))
502 {
503 fun_ret = GNUNET_SYSERR;
504 goto cleanup;
505 }
506 }
507 fun_ret = GNUNET_OK;
508 }
509 else if (NULL != restrict_section)
510 {
511 enum GNUNET_GenericReturnValue inner_ret;
512 struct ConfigSection *cs;
513 struct ConfigFile *cf = GNUNET_new (struct ConfigFile);
514
515 inner_ret = GNUNET_DISK_file_test_read (inline_path);
516
517 cs = find_section (cfg, restrict_section);
518
519 if (NULL == cs)
520 {
521 cs = GNUNET_new (struct ConfigSection);
522 cs->name = GNUNET_strdup (restrict_section);
523 cs->next = cfg->sections;
524 cfg->sections = cs;
525 cs->entries = NULL;
526 }
527 if (cfg->diagnostics)
528 {
529 char *sfn = GNUNET_STRINGS_filename_expand (inline_path);
530 struct stat istat;
531
532 cs->hint_secret_filename = sfn;
533 if (0 == stat (sfn, &istat))
534 {
535 struct passwd *pw = getpwuid (istat.st_uid);
536 struct group *gr = getgrgid (istat.st_gid);
537 char *pwname = (NULL == pw) ? "<unknown>" : pw->pw_name;
538 char *grname = (NULL == gr) ? "<unknown>" : gr->gr_name;
539
541 "%s:%s %o",
542 pwname,
543 grname,
544 istat.st_mode);
545 }
546 else
547 {
548 cs->hint_secret_stat = GNUNET_strdup ("<can't stat file>");
549 }
550 if (source_filename)
551 {
552 /* Possible that this secret section has been inlined before */
554 cs->hint_inlined_from_filename = GNUNET_strdup (source_filename);
555 cs->hint_inlined_from_line = source_lineno;
556 }
557 }
558
559 /* Put file in the load list for diagnostics, even if we can't access it. */
560 {
562 cf->source_filename = GNUNET_strdup (inline_path);
563 cf->hint_restrict_section = GNUNET_strdup (restrict_section);
566 cf);
567 }
568
569 if (GNUNET_OK != inner_ret)
570 {
571 cs->inaccessible = true;
572 cf->hint_inaccessible = true;
573 /* File can't be accessed, but that's okay. */
574 fun_ret = GNUNET_OK;
575 goto cleanup;
576 }
577
578 other_cfg = GNUNET_CONFIGURATION_create ();
579 other_cfg->restrict_section = restrict_section;
580 inner_ret = GNUNET_CONFIGURATION_parse (other_cfg,
581 inline_path);
582 if (GNUNET_OK != inner_ret)
583 {
584 cf->hint_inaccessible = true;
585 fun_ret = inner_ret;
586 goto cleanup;
587 }
588
589 cs = find_section (other_cfg, restrict_section);
590 if (NULL == cs)
591 {
593 "Configuration file '%s' loaded with @inline-secret@ "
594 "does not contain section '%s'.\n",
595 inline_path,
596 restrict_section);
597 /* Inlined onfiguration is accessible but doesn't contain any values.
598 We treat this as if the inlined section was empty, and do not
599 consider it an error. */
600 fun_ret = GNUNET_OK;
601 goto cleanup;
602 }
603 for (struct ConfigEntry *ce = cs->entries;
604 NULL != ce;
605 ce = ce->next)
607 restrict_section,
608 ce->key,
609 ce->val);
610 fun_ret = GNUNET_OK;
611 }
612 else if (GNUNET_OK !=
614 inline_path))
615 {
616 fun_ret = GNUNET_SYSERR;
617 goto cleanup;
618 }
619 else
620 {
621 fun_ret = GNUNET_OK;
622 }
623cleanup:
624 cfg->current_nest_level = old_nest_level;
625 if (NULL != other_cfg)
627 GNUNET_free (inline_path);
628 if (igc.files_length > 0)
629 {
630 for (size_t i = 0; i < igc.files_length; i++)
631 GNUNET_free (igc.files[i]);
633 }
634 return fun_ret;
635}
636
637
646static struct ConfigEntry *
648 const char *section,
649 const char *key)
650{
651 struct ConfigSection *sec;
652 struct ConfigEntry *pos;
653
654 if (NULL == (sec = find_section (cfg, section)))
655 return NULL;
656 if (sec->inaccessible)
657 {
659 "Section '%s' is marked as inaccessible, because the configuration "
660 " file that contains the section can't be read. Attempts to use "
661 "option '%s' will fail.\n",
662 section,
663 key);
664 return NULL;
665 }
666 pos = sec->entries;
667 while ((pos != NULL) && (0 != strcasecmp (key, pos->key)))
668 pos = pos->next;
669 return pos;
670}
671
672
682static void
684 const char *section,
685 const char *option,
686 const char *hint_filename,
687 unsigned int hint_line)
688{
689 struct ConfigEntry *e = find_entry (cfg, section, option);
690 if (! cfg->diagnostics)
691 return;
692 if (! e)
693 return;
695 e->hint_lineno = hint_line;
696}
697
698
701 const char *mem,
702 size_t size,
703 const char *source_filename)
704{
705 size_t line_size;
706 unsigned int nr;
707 size_t r_bytes;
708 size_t to_read;
710 char *section;
711 char *eq;
712 char *tag;
713 char *value;
714 char *line_orig = NULL;
715
716 ret = GNUNET_OK;
717 section = NULL;
718 nr = 0;
719 r_bytes = 0;
720 while (r_bytes < size)
721 {
722 char *pos;
723 char *line;
724 bool emptyline;
725
726 GNUNET_free (line_orig);
727 /* fgets-like behaviour on buffer */
728 to_read = size - r_bytes;
729 pos = memchr (&mem[r_bytes], '\n', to_read);
730 if (NULL == pos)
731 {
732 line_orig = GNUNET_strndup (&mem[r_bytes],
733 line_size = to_read);
734 r_bytes += line_size;
735 }
736 else
737 {
738 line_orig = GNUNET_strndup (&mem[r_bytes],
739 line_size = (pos - &mem[r_bytes]));
740 r_bytes += line_size + 1;
741 }
742 line = line_orig;
743 /* increment line number */
744 nr++;
745 /* tabs and '\r' are whitespace */
746 emptyline = GNUNET_YES;
747 for (size_t i = 0; i < line_size; i++)
748 {
749 if (line[i] == '\t')
750 line[i] = ' ';
751 if (line[i] == '\r')
752 line[i] = ' ';
753 if (' ' != line[i])
754 emptyline = GNUNET_NO;
755 }
756 /* ignore empty lines */
757 if (GNUNET_YES == emptyline)
758 continue;
759
760 /* remove tailing whitespace */
761 for (size_t i = line_size - 1;
762 (i >= 1) && (isspace ((unsigned char) line[i]));
763 i--)
764 line[i] = '\0';
765
766 /* remove leading whitespace */
767 for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++)
768 ;
769
770 /* ignore comments */
771 if ( ('#' == line[0]) ||
772 ('%' == line[0]) )
773 continue;
774
775 /* Handle special directives. */
776 if ('@' == line[0])
777 {
778 char *end = strchr (line + 1, '@');
779 char *directive;
780 enum GNUNET_GenericReturnValue directive_ret;
781
782 if (NULL != cfg->restrict_section)
783 {
785 "Illegal directive in line %u (parsing restricted section %s)\n",
786 nr,
789 break;
790 }
791
792 if (NULL == end)
793 {
795 "Bad directive in line %u\n",
796 nr);
798 break;
799 }
800 *end = '\0';
801 directive = line + 1;
802
803 if (0 == strcasecmp (directive,
804 "INLINE"))
805 {
806 const char *path = end + 1;
807
808 /* Skip space before path */
809 for (; isspace (*path); path++)
810 ;
811
812 directive_ret = handle_inline (cfg,
813 path,
814 false,
815 NULL,
816 source_filename,
817 nr);
818 }
819 else if (0 == strcasecmp (directive,
820 "INLINE-MATCHING"))
821 {
822 const char *path = end + 1;
823
824 /* Skip space before path */
825 for (; isspace (*path); path++)
826 ;
827
828 directive_ret = handle_inline (cfg,
829 path,
830 true,
831 NULL,
832 source_filename,
833 nr);
834 }
835 else if (0 == strcasecmp (directive,
836 "INLINE-SECRET"))
837 {
838 char *secname = end + 1;
839 char *secname_end;
840 const char *path;
841
842 /* Skip space before secname */
843 for (; isspace (*secname); secname++)
844 ;
845
846 secname_end = strchr (secname, ' ');
847
848 if (NULL == secname_end)
849 {
851 "Bad inline-secret directive in line %u\n",
852 nr);
854 break;
855 }
856 *secname_end = '\0';
857 path = secname_end + 1;
858
859 /* Skip space before path */
860 for (; isspace (*path); path++)
861 ;
862
863 directive_ret = handle_inline (cfg,
864 path,
865 false,
866 secname,
867 source_filename,
868 nr);
869 }
870 else
871 {
873 "Unknown or malformed directive '%s' in line %u\n",
874 directive,
875 nr);
877 break;
878 }
879 if (GNUNET_OK != directive_ret)
880 {
881 ret = directive_ret;
882 break;
883 }
884 continue;
885 }
886 if ( ('[' == line[0]) &&
887 (']' == line[line_size - 1]) )
888 {
889 /* [value] */
890 line[line_size - 1] = '\0';
891 value = &line[1];
892 GNUNET_free (section);
893 section = GNUNET_strdup (value);
894 continue;
895 }
896 if (NULL != (eq = strchr (line, '=')))
897 {
898 size_t i;
899
900 if (NULL == section)
901 {
903 "Syntax error while deserializing in line %u (option without section)\n",
904 nr);
906 break;
907 }
908
909 /* tag = value */
910 tag = GNUNET_strndup (line, eq - line);
911 /* remove tailing whitespace */
912 for (i = strlen (tag) - 1;
913 (i >= 1) && (isspace ((unsigned char) tag[i]));
914 i--)
915 tag[i] = '\0';
916
917 /* Strip whitespace */
918 value = eq + 1;
919 while (isspace ((unsigned char) value[0]))
920 value++;
921 for (i = strlen (value) - 1;
922 (i >= 1) && (isspace ((unsigned char) value[i]));
923 i--)
924 value[i] = '\0';
925
926 /* remove quotes */
927 i = 0;
928 if ( ('"' == value[0]) &&
929 ('"' == value[strlen (value) - 1]) )
930 {
931 value[strlen (value) - 1] = '\0';
932 value++;
933 }
935 section,
936 tag,
937 &value[i]);
938 if (cfg->diagnostics)
939 {
941 section,
942 tag,
943 source_filename
944 ? source_filename
945 : "<input>",
946 nr);
947 }
948 GNUNET_free (tag);
949 continue;
950 }
951 /* parse error */
953 "Syntax error while deserializing in line %u\n",
954 nr);
956 break;
957 }
958 GNUNET_free (line_orig);
959 GNUNET_free (section);
960 GNUNET_assert ( (GNUNET_OK != ret) ||
961 (r_bytes == size) );
962 return ret;
963}
964
965
968 const char *filename)
969{
970 uint64_t fs64;
971 size_t fs;
972 char *fn;
973 char *mem;
974 int dirty;
976 ssize_t sret;
977
979 LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to parse config file `%s'\n", fn);
980 if (NULL == fn)
981 return GNUNET_SYSERR;
982
983
984 /* Check for cycles */
985 {
986 unsigned int lvl = cfg->current_nest_level;
987 struct ConfigFile *cf = cfg->loaded_files_tail;
988 struct ConfigFile *parent = NULL;
989
990
991 for (; NULL != cf; parent = cf, cf = cf->prev)
992 {
993 /* Check parents based on level, skipping children of siblings. */
994 if (cf->level >= lvl)
995 continue;
996 lvl = cf->level;
997 if ( (NULL == cf->source_filename) || (NULL == filename))
998 continue;
999 if (0 == strcmp (cf->source_filename, filename))
1000 {
1001 if (NULL == parent)
1002 {
1004 "Forbidden direct cyclic configuration import (%s -> %s)\n",
1005 cf->source_filename,
1006 filename);
1007 }
1008 else
1010 "Forbidden indirect cyclic configuration import (%s -> ... -> %s -> %s)\n",
1011 cf->source_filename,
1012 parent->source_filename,
1013 filename);
1014 GNUNET_free (fn);
1015 return GNUNET_SYSERR;
1016 }
1017 }
1018
1019 }
1020
1021 /* Keep track of loaded files.*/
1022 {
1023 struct ConfigFile *cf = GNUNET_new (struct ConfigFile);
1024
1026 cf->source_filename = GNUNET_strdup (filename ? filename : "<input>");
1029 cf);
1030 }
1031
1032 dirty = cfg->dirty; /* back up value! */
1033 if (GNUNET_SYSERR ==
1035 &fs64,
1036 GNUNET_YES,
1037 GNUNET_YES))
1038 {
1040 "Error while determining the file size of `%s'\n",
1041 fn);
1042 GNUNET_free (fn);
1043 return GNUNET_SYSERR;
1044 }
1045 if (fs64 > SIZE_MAX)
1046 {
1047 GNUNET_break (0); /* File size is more than the heap size */
1048 GNUNET_free (fn);
1049 return GNUNET_SYSERR;
1050 }
1051 fs = fs64;
1052 mem = GNUNET_malloc (fs);
1053 sret = GNUNET_DISK_fn_read (fn, mem, fs);
1054 if ((sret < 0) || (fs != (size_t) sret))
1055 {
1057 "Error while reading file `%s'\n",
1058 fn);
1059 GNUNET_free (fn);
1060 GNUNET_free (mem);
1061 return GNUNET_SYSERR;
1062 }
1064 "Deserializing contents of file `%s'\n",
1065 fn);
1067 mem,
1068 fs,
1069 fn);
1070 if (GNUNET_SYSERR == ret)
1071 {
1073 _ ("Failed to parse configuration file `%s'\n"),
1074 fn);
1075 }
1076 GNUNET_free (fn);
1077 GNUNET_free (mem);
1078 /* restore dirty flag - anything we set in the meantime
1079 * came from disk */
1080 cfg->dirty = dirty;
1081 return ret;
1082}
1083
1084
1087{
1088 return cfg->dirty;
1089}
1090
1091
1099static bool
1100do_skip (const char *sec,
1101 const char *key)
1102{
1103 if (0 != strcasecmp ("PATHS",
1104 sec))
1105 return false;
1106 return ( (0 == strcasecmp ("DATADIR",
1107 key)) ||
1108 (0 == strcasecmp ("LIBDIR",
1109 key)) ||
1110 (0 == strcasecmp ("BINDIR",
1111 key)) ||
1112 (0 == strcasecmp ("PREFIX",
1113 key)) ||
1114 (0 == strcasecmp ("LOCALEDIR",
1115 key)) ||
1116 (0 == strcasecmp ("ICONDIR",
1117 key)) ||
1118 (0 == strcasecmp ("DOCDIR",
1119 key)) ||
1120 (0 == strcasecmp ("DEFAULTCONFIG",
1121 key)) ||
1122 (0 == strcasecmp ("LIBEXECDIR",
1123 key)) );
1124}
1125
1126
1127char *
1129 size_t *size)
1130{
1131 char *mem;
1132 char *cbuf;
1133 char *val;
1134 char *pos;
1135 size_t m_size;
1136 size_t c_size;
1137
1138 /* Pass1 : calculate the buffer size required */
1139 m_size = 0;
1140 for (struct ConfigSection *sec = cfg->sections;
1141 NULL != sec;
1142 sec = sec->next)
1143 {
1144 if (sec->inaccessible)
1145 continue;
1146 /* For each section we need to add 3 characters: {'[',']','\n'} */
1147 m_size += strlen (sec->name) + 3;
1148 for (struct ConfigEntry *ent = sec->entries;
1149 NULL != ent;
1150 ent = ent->next)
1151 {
1152 if (do_skip (sec->name,
1153 ent->key))
1154 continue;
1155 if (NULL != ent->val)
1156 {
1157 /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */
1158 pos = ent->val;
1159 while (NULL != (pos = strstr (pos, "\n")))
1160 {
1161 m_size++;
1162 pos++;
1163 }
1164 /* For each key = value pair we need to add 4 characters (2
1165 spaces and 1 equal-to character and 1 new line) */
1166 m_size += strlen (ent->key) + strlen (ent->val) + 4;
1167 }
1168 }
1169 /* A new line after section end */
1170 m_size++;
1171 }
1172
1173 /* Pass2: Allocate memory and write the configuration to it */
1174 mem = GNUNET_malloc (m_size);
1175 c_size = 0;
1176 *size = c_size;
1177 for (struct ConfigSection *sec = cfg->sections;
1178 NULL != sec;
1179 sec = sec->next)
1180 {
1181 int len;
1182
1183 len = GNUNET_asprintf (&cbuf,
1184 "[%s]\n",
1185 sec->name);
1186 GNUNET_assert (0 < len);
1187 GNUNET_memcpy (mem + c_size,
1188 cbuf,
1189 len);
1190 c_size += len;
1191 GNUNET_free (cbuf);
1192 for (struct ConfigEntry *ent = sec->entries;
1193 NULL != ent;
1194 ent = ent->next)
1195 {
1196 if (do_skip (sec->name,
1197 ent->key))
1198 continue;
1199 if (NULL != ent->val)
1200 {
1201 val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1202 strcpy (val, ent->val);
1203 while (NULL != (pos = strstr (val, "\n")))
1204 {
1205 memmove (&pos[2], &pos[1], strlen (&pos[1]));
1206 pos[0] = '\\';
1207 pos[1] = 'n';
1208 }
1209 len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
1210 GNUNET_free (val);
1211 GNUNET_memcpy (mem + c_size, cbuf, len);
1212 c_size += len;
1213 GNUNET_free (cbuf);
1214 }
1215 }
1216 GNUNET_memcpy (mem + c_size, "\n", 1);
1217 c_size++;
1218 }
1219 GNUNET_assert (c_size == m_size);
1220 *size = c_size;
1221 return mem;
1222}
1223
1224
1225char *
1228{
1229 struct GNUNET_Buffer buf = { 0 };
1230
1232 "#\n# Configuration file diagnostics\n#\n");
1234 "# Entry point: %s\n",
1236 "<none>");
1238 "#\n# Files Loaded:\n");
1239
1240 for (struct ConfigFile *cfil = cfg->loaded_files_head;
1241 NULL != cfil;
1242 cfil = cfil->next)
1243 {
1245 "# ");
1246 for (unsigned int i = 0; i < cfil->level; i++)
1248 "+");
1249 if (0 != cfil->level)
1251 " ");
1252
1254 "%s",
1255 cfil->source_filename);
1256
1257 if (NULL != cfil->hint_restrict_section)
1259 " (%s secret section %s)",
1260 cfil->hint_inaccessible
1261 ? "inaccessible"
1262 : "loaded",
1263 cfil->hint_restrict_section);
1264
1266 "\n");
1267 }
1268
1270 "#\n\n");
1271
1272 for (struct ConfigSection *sec = cfg->sections;
1273 NULL != sec;
1274 sec = sec->next)
1275 {
1276 if (sec->hint_secret_filename)
1278 "# secret section from %s\n# secret file stat %s\n",
1279 sec->hint_secret_filename,
1280 sec->hint_secret_stat);
1281 if (sec->hint_inlined_from_filename)
1282 {
1284 "# inlined from %s:%u\n",
1285 sec->hint_inlined_from_filename,
1286 sec->hint_inlined_from_line);
1287 }
1289 "[%s]\n\n",
1290 sec->name);
1291 if (sec->inaccessible)
1292 {
1294 "# <section contents inaccessible>\n\n\n");
1295 continue;
1296 }
1297 for (struct ConfigEntry *ent = sec->entries;
1298 NULL != ent;
1299 ent = ent->next)
1300 {
1301 if (do_skip (sec->name,
1302 ent->key))
1303 continue;
1304 if (NULL != ent->val)
1305 {
1306 char *pos;
1307 char *val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1308 strcpy (val, ent->val);
1309 while (NULL != (pos = strstr (val, "\n")))
1310 {
1311 memmove (&pos[2], &pos[1], strlen (&pos[1]));
1312 pos[0] = '\\';
1313 pos[1] = 'n';
1314 }
1315 if (NULL != ent->hint_filename)
1316 {
1318 "# %s:%u\n",
1319 ent->hint_filename,
1320 ent->hint_lineno);
1321 }
1323 "%s = %s\n",
1324 ent->key,
1325 val);
1326 GNUNET_free (val);
1327 }
1328 GNUNET_buffer_write_str (&buf, "\n");
1329 }
1330 GNUNET_buffer_write_str (&buf, "\n");
1331 }
1332 return GNUNET_buffer_reap_str (&buf);
1333}
1334
1335
1338 const char *filename)
1339{
1340 char *fn;
1341 char *cfg_buf;
1342 size_t size;
1343
1345 if (fn == NULL)
1346 return GNUNET_SYSERR;
1348 {
1349 GNUNET_free (fn);
1350 return GNUNET_SYSERR;
1351 }
1353 &size);
1354 {
1355 struct GNUNET_DISK_FileHandle *h;
1356
1365 if (NULL == h)
1366 {
1367 GNUNET_free (fn);
1368 GNUNET_free (cfg_buf);
1369 return GNUNET_SYSERR;
1370 }
1371 if (((ssize_t) size) !=
1373 cfg_buf,
1374 size))
1375 {
1377 "write",
1378 fn);
1380 (void) GNUNET_DISK_directory_remove (fn);
1381 GNUNET_free (fn);
1382 GNUNET_free (cfg_buf);
1383 cfg->dirty = GNUNET_SYSERR; /* last write failed */
1384 return GNUNET_SYSERR;
1385 }
1388 }
1389 GNUNET_free (fn);
1390 GNUNET_free (cfg_buf);
1391 cfg->dirty = GNUNET_NO; /* last write succeeded */
1392 return GNUNET_OK;
1393}
1394
1395
1396void
1399 void *iter_cls)
1400{
1401 for (struct ConfigSection *spos = cfg->sections;
1402 NULL != spos;
1403 spos = spos->next)
1404 for (struct ConfigEntry *epos = spos->entries;
1405 NULL != epos;
1406 epos = epos->next)
1407 if (NULL != epos->val)
1408 iter (iter_cls,
1409 spos->name,
1410 epos->key,
1411 epos->val);
1412}
1413
1414
1415void
1417 const struct GNUNET_CONFIGURATION_Handle *cfg,
1418 const char *section,
1420 void *iter_cls)
1421{
1422 struct ConfigSection *spos;
1423 struct ConfigEntry *epos;
1424
1425 spos = cfg->sections;
1426 while ((spos != NULL) && (0 != strcasecmp (spos->name, section)))
1427 spos = spos->next;
1428 if (NULL == spos)
1429 return;
1430 if (spos->inaccessible)
1431 {
1433 "Section '%s' is marked as inaccessible, because the configuration "
1434 " file that contains the section can't be read.\n",
1435 section);
1436 return;
1437 }
1438 for (epos = spos->entries; NULL != epos; epos = epos->next)
1439 if (NULL != epos->val)
1440 iter (iter_cls, spos->name, epos->key, epos->val);
1441}
1442
1443
1444void
1446 const struct GNUNET_CONFIGURATION_Handle *cfg,
1448 void *iter_cls)
1449{
1450 struct ConfigSection *spos;
1451 struct ConfigSection *next;
1452
1453 next = cfg->sections;
1454 while (next != NULL)
1455 {
1456 spos = next;
1457 next = spos->next;
1458 iter (iter_cls, spos->name);
1459 }
1460}
1461
1462
1463void
1465 const char *section)
1466{
1467 struct ConfigSection *spos;
1468 struct ConfigSection *prev;
1469 struct ConfigEntry *ent;
1470
1471 prev = NULL;
1472 spos = cfg->sections;
1473 while (NULL != spos)
1474 {
1475 if (0 == strcasecmp (section, spos->name))
1476 {
1477 if (NULL == prev)
1478 cfg->sections = spos->next;
1479 else
1480 prev->next = spos->next;
1481 while (NULL != (ent = spos->entries))
1482 {
1483 spos->entries = ent->next;
1484 GNUNET_free (ent->key);
1485 GNUNET_free (ent->val);
1487 GNUNET_free (ent);
1488 cfg->dirty = GNUNET_YES;
1489 }
1490 GNUNET_free (spos->name);
1494 GNUNET_free (spos);
1495 return;
1496 }
1497 prev = spos;
1498 spos = spos->next;
1499 }
1500}
1501
1502
1512static void
1513copy_entry (void *cls,
1514 const char *section,
1515 const char *option,
1516 const char *value)
1517{
1518 struct GNUNET_CONFIGURATION_Handle *dst = cls;
1519
1521 section,
1522 option,
1523 value);
1524}
1525
1526
1529{
1531
1534 return ret;
1535}
1536
1537
1548static void
1550 const char *section,
1551 const char *option,
1552 const char *value)
1553{
1554 struct DiffHandle *dh = cls;
1555 struct ConfigEntry *entNew;
1556
1557 entNew = find_entry (dh->cfg_default, section, option);
1558 if ((NULL != entNew) && (NULL != entNew->val) &&
1559 (0 == strcmp (entNew->val, value)))
1560 return;
1562 section,
1563 option,
1564 value);
1565}
1566
1567
1570 const struct GNUNET_CONFIGURATION_Handle *cfg_default,
1571 const struct GNUNET_CONFIGURATION_Handle *cfg_new)
1572{
1573 struct DiffHandle diffHandle;
1574
1575 diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
1576 diffHandle.cfg_default = cfg_default;
1577 GNUNET_CONFIGURATION_iterate (cfg_new, &compare_entries, &diffHandle);
1578 return diffHandle.cfgDiff;
1579}
1580
1581
1585 const struct GNUNET_CONFIGURATION_Handle *cfg_new,
1586 const char *filename)
1587{
1588 int ret;
1589 struct GNUNET_CONFIGURATION_Handle *diff;
1590
1591 diff = GNUNET_CONFIGURATION_get_diff (cfg_default, cfg_new);
1594 return ret;
1595}
1596
1597
1598void
1600 const char *section,
1601 const char *option,
1602 const char *value)
1603{
1604 struct ConfigSection *sec;
1605 struct ConfigEntry *e;
1606 char *nv;
1607
1608 e = find_entry (cfg, section, option);
1609 if (NULL != e)
1610 {
1611 if (NULL == value)
1612 {
1613 GNUNET_free (e->val);
1614 e->val = NULL;
1615 }
1616 else
1617 {
1618 nv = GNUNET_strdup (value);
1619 GNUNET_free (e->val);
1620 e->val = nv;
1621 }
1622 return;
1623 }
1624 sec = find_section (cfg, section);
1625 if (sec == NULL)
1626 {
1627 sec = GNUNET_new (struct ConfigSection);
1628 sec->name = GNUNET_strdup (section);
1629 sec->next = cfg->sections;
1630 cfg->sections = sec;
1631 }
1632 e = GNUNET_new (struct ConfigEntry);
1633 e->key = GNUNET_strdup (option);
1634 e->val = GNUNET_strdup (value);
1635 e->next = sec->entries;
1636 sec->entries = e;
1637}
1638
1639
1640void
1642 const char *section,
1643 const char *option,
1644 unsigned long long number)
1645{
1646 char s[64];
1647
1648 GNUNET_snprintf (s,
1649 64,
1650 "%llu",
1651 number);
1653 section,
1654 option,
1655 s);
1656}
1657
1658
1661 const struct GNUNET_CONFIGURATION_Handle *cfg,
1662 const char *section,
1663 const char *option,
1664 unsigned long long *number)
1665{
1666 struct ConfigEntry *e;
1667 char dummy[2];
1668
1669 if (NULL == (e = find_entry (cfg, section, option)))
1670 return GNUNET_SYSERR;
1671 if (NULL == e->val)
1672 return GNUNET_SYSERR;
1673 if (1 != sscanf (e->val, "%llu%1s", number, dummy))
1674 return GNUNET_SYSERR;
1675 return GNUNET_OK;
1676}
1677
1678
1681 const struct GNUNET_CONFIGURATION_Handle *cfg,
1682 const char *section,
1683 const char *option,
1684 float *number)
1685{
1686 struct ConfigEntry *e;
1687 char dummy[2];
1688
1689 if (NULL == (e = find_entry (cfg, section, option)))
1690 return GNUNET_SYSERR;
1691 if (NULL == e->val)
1692 return GNUNET_SYSERR;
1693 if (1 != sscanf (e->val, "%f%1s", number, dummy))
1694 return GNUNET_SYSERR;
1695 return GNUNET_OK;
1696}
1697
1698
1701 const struct GNUNET_CONFIGURATION_Handle *cfg,
1702 const char *section,
1703 const char *option,
1704 struct GNUNET_TIME_Relative *time)
1705{
1706 struct ConfigEntry *e;
1707 int ret;
1708
1709 if (NULL == (e = find_entry (cfg, section, option)))
1710 return GNUNET_SYSERR;
1711 if (NULL == e->val)
1712 return GNUNET_SYSERR;
1714 if (GNUNET_OK != ret)
1716 section,
1717 option,
1718 _ ("Not a valid relative time specification"));
1719 return ret;
1720}
1721
1722
1725 const struct GNUNET_CONFIGURATION_Handle *cfg,
1726 const char *section,
1727 const char *option,
1728 unsigned long long *size)
1729{
1730 struct ConfigEntry *e;
1731
1732 if (NULL == (e = find_entry (cfg, section, option)))
1733 return GNUNET_SYSERR;
1734 if (NULL == e->val)
1735 return GNUNET_SYSERR;
1737}
1738
1739
1752 const struct GNUNET_CONFIGURATION_Handle *cfg,
1753 const char *section,
1754 const char *option,
1755 char **value)
1756{
1757 struct ConfigEntry *e;
1758
1759 if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1760 {
1761 *value = NULL;
1762 return GNUNET_SYSERR;
1763 }
1764 *value = GNUNET_strdup (e->val);
1765 return GNUNET_OK;
1766}
1767
1768
1771 const struct GNUNET_CONFIGURATION_Handle *cfg,
1772 const char *section,
1773 const char *option,
1774 const char *const *choices,
1775 const char **value)
1776{
1777 struct ConfigEntry *e;
1778 unsigned int i;
1779
1780 if (NULL == (e = find_entry (cfg, section, option)))
1781 return GNUNET_SYSERR;
1782 for (i = 0; NULL != choices[i]; i++)
1783 if (0 == strcasecmp (choices[i], e->val))
1784 break;
1785 if (NULL == choices[i])
1786 {
1788 _ ("Configuration value '%s' for '%s'"
1789 " in section '%s' is not in set of legal choices\n"),
1790 e->val,
1791 option,
1792 section);
1793 return GNUNET_SYSERR;
1794 }
1795 *value = choices[i];
1796 return GNUNET_OK;
1797}
1798
1799
1802 const char *section,
1803 const char *option,
1804 void *buf,
1805 size_t buf_size)
1806{
1807 char *enc;
1808 int res;
1809 size_t data_size;
1810
1811 if (GNUNET_OK !=
1812 (res =
1813 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &enc)))
1814 return res;
1815 data_size = (strlen (enc) * 5) / 8;
1816 if (data_size != buf_size)
1817 {
1818 GNUNET_free (enc);
1819 return GNUNET_SYSERR;
1820 }
1821 if (GNUNET_OK !=
1822 GNUNET_STRINGS_string_to_data (enc, strlen (enc), buf, buf_size))
1823 {
1824 GNUNET_free (enc);
1825 return GNUNET_SYSERR;
1826 }
1827 GNUNET_free (enc);
1828 return GNUNET_OK;
1829}
1830
1831
1834 const char *section,
1835 const char *option)
1836{
1837 struct ConfigEntry *e;
1838
1839 if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1840 return GNUNET_NO;
1841 return GNUNET_YES;
1842}
1843
1844
1860static char *
1862 char *orig,
1863 unsigned int depth)
1864{
1865 char *prefix;
1866 char *result;
1867 char *start;
1868 const char *post;
1869 const char *env;
1870 char *def;
1871 char *end;
1872 unsigned int lopen;
1873 char erased_char;
1874 char *erased_pos;
1875 size_t len;
1876
1877 if (NULL == orig)
1878 return NULL;
1879 if (depth > 128)
1880 {
1882 "Recursive expansion suspected, aborting $-expansion for term `%s'\n",
1883 orig);
1884 return orig;
1885 }
1887 "Asked to $-expand %s\n",
1888 orig);
1889 if ('$' != orig[0])
1890 {
1892 "Doesn't start with $ - not expanding\n");
1893 return orig;
1894 }
1895 erased_char = 0;
1896 erased_pos = NULL;
1897 if ('{' == orig[1])
1898 {
1899 start = &orig[2];
1900 lopen = 1;
1901 end = &orig[1];
1902 while (lopen > 0)
1903 {
1904 end++;
1905 switch (*end)
1906 {
1907 case '}':
1908 lopen--;
1909 break;
1910
1911 case '{':
1912 lopen++;
1913 break;
1914
1915 case '\0':
1917 "Missing closing `}' in option `%s'\n",
1918 orig);
1919 return orig;
1920
1921 default:
1922 break;
1923 }
1924 }
1925 erased_char = *end;
1926 erased_pos = end;
1927 *end = '\0';
1928 post = end + 1;
1929 def = strchr (orig, ':');
1930 if (NULL != def)
1931 {
1932 *def = '\0';
1933 def++;
1934 if (('-' == *def) || ('=' == *def))
1935 def++;
1936 def = GNUNET_strdup (def);
1937 }
1938 }
1939 else
1940 {
1941 int i;
1942
1943 start = &orig[1];
1944 def = NULL;
1945 i = 0;
1946 while ( (orig[i] != '/') &&
1947 (orig[i] != '\\') &&
1948 (orig[i] != '\0') &&
1949 (orig[i] != ' ') )
1950 i++;
1951 if (orig[i] == '\0')
1952 {
1953 post = "";
1954 }
1955 else
1956 {
1957 erased_char = orig[i];
1958 erased_pos = &orig[i];
1959 orig[i] = '\0';
1960 post = &orig[i + 1];
1961 }
1962 }
1964 "Split into `%s' and `%s' with default %s\n",
1965 start,
1966 post,
1967 def);
1968 if (GNUNET_OK !=
1970 "PATHS",
1971 start,
1972 &prefix))
1973 {
1974 if (NULL == (env = getenv (start)))
1975 {
1976 /* try default */
1977 def = expand_dollar (cfg,
1978 def,
1979 depth + 1);
1980 env = def;
1981 }
1982 if (NULL == env)
1983 {
1985 if (erased_pos)
1986 *erased_pos = erased_char;
1988 "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n",
1989 start,
1990 orig);
1992 return orig;
1993 }
1995 }
1997 prefix);
1998 if ((erased_pos) && ('}' != erased_char))
1999 {
2000 len = strlen (prefix) + 1;
2001 prefix = GNUNET_realloc (prefix, len + 1);
2002 prefix[len - 1] = erased_char;
2003 prefix[len] = '\0';
2004 }
2005 result = GNUNET_malloc (strlen (prefix) + strlen (post) + 1);
2006 strcpy (result, prefix);
2007 strcat (result, post);
2008 GNUNET_free (def);
2010 GNUNET_free (orig);
2011 return result;
2012}
2013
2014
2015char *
2017 const struct GNUNET_CONFIGURATION_Handle *cfg,
2018 char *orig)
2019{
2020 char *dup;
2021 size_t i;
2022 size_t len;
2023
2024 for (i = 0; '\0' != orig[i]; i++)
2025 {
2026 if ('$' != orig[i])
2027 continue;
2028 dup = GNUNET_strdup (orig + i);
2029 dup = expand_dollar (cfg, dup, 0);
2030 GNUNET_assert (NULL != dup); /* make compiler happy */
2031 len = strlen (dup) + 1;
2032 orig = GNUNET_realloc (orig, i + len);
2033 GNUNET_memcpy (orig + i, dup, len);
2034 GNUNET_free (dup);
2035 }
2036 return orig;
2037}
2038
2039
2042 const struct GNUNET_CONFIGURATION_Handle *cfg,
2043 const char *section,
2044 const char *option,
2045 char **value)
2046{
2047 char *tmp;
2048
2049 if (GNUNET_OK !=
2050 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp))
2051 {
2052 LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to retrieve filename\n");
2053 *value = NULL;
2054 return GNUNET_SYSERR;
2055 }
2058 GNUNET_free (tmp);
2059 if (*value == NULL)
2060 return GNUNET_SYSERR;
2061 return GNUNET_OK;
2062}
2063
2064
2067 const struct GNUNET_CONFIGURATION_Handle *cfg,
2068 const char *section,
2069 const char *option)
2070{
2071 static const char *yesno[] = { "YES", "NO", NULL };
2072 const char *val;
2073 int ret;
2074
2075 ret =
2076 GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
2077 if (ret == GNUNET_SYSERR)
2078 return ret;
2079 if (val == yesno[0])
2080 return GNUNET_YES;
2081 return GNUNET_NO;
2082}
2083
2084
2085int
2087 const struct GNUNET_CONFIGURATION_Handle *cfg,
2088 const char *section,
2089 const char *option,
2091 void *cb_cls)
2092{
2093 char *list;
2094 char *pos;
2095 char *end;
2096 char old;
2097 int ret;
2098
2099 if (GNUNET_OK !=
2100 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list))
2101 return 0;
2102 GNUNET_assert (list != NULL);
2103 ret = 0;
2104 pos = list;
2105 while (1)
2106 {
2107 while (pos[0] == ' ')
2108 pos++;
2109 if (strlen (pos) == 0)
2110 break;
2111 end = pos + 1;
2112 while ((end[0] != ' ') && (end[0] != '\0'))
2113 {
2114 if (end[0] == '\\')
2115 {
2116 switch (end[1])
2117 {
2118 case '\\':
2119 case ' ':
2120 memmove (end, &end[1], strlen (&end[1]) + 1);
2121
2122 case '\0':
2123 /* illegal, but just keep it */
2124 break;
2125
2126 default:
2127 /* illegal, but just ignore that there was a '/' */
2128 break;
2129 }
2130 }
2131 end++;
2132 }
2133 old = end[0];
2134 end[0] = '\0';
2135 if (strlen (pos) > 0)
2136 {
2137 ret++;
2138 if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos)))
2139 {
2141 break;
2142 }
2143 }
2144 if (old == '\0')
2145 break;
2146 pos = end + 1;
2147 }
2148 GNUNET_free (list);
2149 return ret;
2150}
2151
2152
2159static char *
2160escape_name (const char *value)
2161{
2162 char *escaped;
2163 const char *rpos;
2164 char *wpos;
2165
2166 escaped = GNUNET_malloc (strlen (value) * 2 + 1);
2167 memset (escaped, 0, strlen (value) * 2 + 1);
2168 rpos = value;
2169 wpos = escaped;
2170 while (rpos[0] != '\0')
2171 {
2172 switch (rpos[0])
2173 {
2174 case '\\':
2175 case ' ':
2176 wpos[0] = '\\';
2177 wpos[1] = rpos[0];
2178 wpos += 2;
2179 break;
2180
2181 default:
2182 wpos[0] = rpos[0];
2183 wpos++;
2184 }
2185 rpos++;
2186 }
2187 return escaped;
2188}
2189
2190
2198static enum GNUNET_GenericReturnValue
2199test_match (void *cls, const char *fn)
2200{
2201 const char *of = cls;
2202
2203 return (0 == strcmp (of, fn)) ? GNUNET_SYSERR : GNUNET_OK;
2204}
2205
2206
2210 const char *section,
2211 const char *option,
2212 const char *value)
2213{
2214 char *escaped;
2215 char *old;
2216 char *nw;
2217
2218 if (GNUNET_SYSERR ==
2220 section,
2221 option,
2222 &test_match,
2223 (void *) value))
2224 return GNUNET_NO; /* already exists */
2225 if (GNUNET_OK !=
2226 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
2227 old = GNUNET_strdup ("");
2228 escaped = escape_name (value);
2229 nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2);
2230 strcpy (nw, old);
2231 if (strlen (old) > 0)
2232 strcat (nw, " ");
2233 strcat (nw, escaped);
2235 section,
2236 option,
2237 nw);
2238 GNUNET_free (old);
2239 GNUNET_free (nw);
2240 GNUNET_free (escaped);
2241 return GNUNET_OK;
2242}
2243
2244
2248 const char *section,
2249 const char *option,
2250 const char *value)
2251{
2252 char *list;
2253 char *pos;
2254 char *end;
2255 char *match;
2256 char old;
2257
2258 if (GNUNET_OK !=
2260 section,
2261 option,
2262 &list))
2263 return GNUNET_NO;
2264 match = escape_name (value);
2265 pos = list;
2266 while (1)
2267 {
2268 while (pos[0] == ' ')
2269 pos++;
2270 if (strlen (pos) == 0)
2271 break;
2272 end = pos + 1;
2273 while ((end[0] != ' ') && (end[0] != '\0'))
2274 {
2275 if (end[0] == '\\')
2276 {
2277 switch (end[1])
2278 {
2279 case '\\':
2280 case ' ':
2281 end++;
2282 break;
2283
2284 case '\0':
2285 /* illegal, but just keep it */
2286 break;
2287
2288 default:
2289 /* illegal, but just ignore that there was a '/' */
2290 break;
2291 }
2292 }
2293 end++;
2294 }
2295 old = end[0];
2296 end[0] = '\0';
2297 if (0 == strcmp (pos, match))
2298 {
2299 if (old != '\0')
2300 memmove (pos,
2301 &end[1],
2302 strlen (&end[1]) + 1);
2303 else
2304 {
2305 if (pos != list)
2306 pos[-1] = '\0';
2307 else
2308 pos[0] = '\0';
2309 }
2311 section,
2312 option,
2313 list);
2314 GNUNET_free (list);
2315 GNUNET_free (match);
2316 return GNUNET_OK;
2317 }
2318 if (old == '\0')
2319 break;
2320 end[0] = old;
2321 pos = end + 1;
2322 }
2323 GNUNET_free (list);
2324 GNUNET_free (match);
2325 return GNUNET_NO;
2326}
2327
2328
2331 const char *defaults_d)
2332{
2333 struct CollectFilesContext files_context = {
2334 .files = NULL,
2335 .files_length = 0,
2336 };
2337 enum GNUNET_GenericReturnValue fun_ret;
2338
2339 if (GNUNET_SYSERR ==
2341 &files_context))
2342 return GNUNET_SYSERR; /* no configuration at all found */
2343 qsort (files_context.files,
2344 files_context.files_length,
2345 sizeof (char *),
2346 pstrcmp);
2347 for (unsigned int i = 0; i < files_context.files_length; i++)
2348 {
2349 char *ext;
2350 const char *filename = files_context.files[i];
2351
2352 /* Examine file extension */
2353 ext = strrchr (filename, '.');
2354 if ((NULL == ext) || (0 != strcmp (ext, ".conf")))
2355 {
2356 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Skipping file `%s'\n", filename);
2357 fun_ret = GNUNET_OK;
2358 goto cleanup;
2359 }
2361 if (fun_ret != GNUNET_OK)
2362 break;
2363 }
2364cleanup:
2365 if (files_context.files_length > 0)
2366 {
2367 for (size_t i = 0; i < files_context.files_length; i++)
2368 GNUNET_free (files_context.files[i]);
2369 GNUNET_array_grow (files_context.files,
2370 files_context.files_length,
2371 0);
2372 }
2373 return fun_ret;
2374}
2375
2376
2377char *
2379{
2380 char *cfg_fn;
2382 const char *xdg = getenv ("XDG_CONFIG_HOME");
2383
2384 if (NULL != xdg)
2385 GNUNET_asprintf (&cfg_fn,
2386 "%s%s%s",
2387 xdg,
2389 pd->config_file);
2390 else
2391 cfg_fn = GNUNET_strdup (pd->user_config_file);
2392
2393 if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2394 return cfg_fn;
2395 GNUNET_free (cfg_fn);
2396
2397 /* Fall back to /etc/ for the default configuration.
2398 Should be okay to use forward slashes here. */
2399
2400 GNUNET_asprintf (&cfg_fn,
2401 "/etc/%s",
2402 pd->config_file);
2403 if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2404 return cfg_fn;
2405 GNUNET_free (cfg_fn);
2406
2407 GNUNET_asprintf (&cfg_fn,
2408 "/etc/%s/%s",
2409 pd->project_dirname,
2410 pd->config_file);
2411 if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2412 return cfg_fn;
2413
2414 GNUNET_free (cfg_fn);
2415 return NULL;
2416}
2417
2418
2421{
2424 const char *xdg = getenv ("XDG_CONFIG_HOME");
2425 char *cfgname = NULL;
2427
2428 /* Makes sure function implicitly looking at the installation directory (for
2429 example GNUNET_CONFIGURATION_load further down) use GNUnet's environment
2430 instead of the caller's. It's done at the start to make sure as many
2431 functions as possible are directed to the proper paths. */
2432 GNUNET_OS_init (dpd);
2433
2435
2436 /* First, try user configuration. */
2437 if (NULL != xdg)
2438 GNUNET_asprintf (&cfgname, "%s/%s", xdg, dpd->config_file);
2439 else
2440 cfgname = GNUNET_strdup (dpd->user_config_file);
2441
2442 /* If user config doesn't exist, try in
2443 /etc/<projdir>/<cfgfile> and /etc/<cfgfile> */
2444 if (GNUNET_OK != GNUNET_DISK_file_test (cfgname))
2445 {
2446 GNUNET_free (cfgname);
2447 GNUNET_asprintf (&cfgname, "/etc/%s", dpd->config_file);
2448 }
2449 if (GNUNET_OK != GNUNET_DISK_file_test (cfgname))
2450 {
2451 GNUNET_free (cfgname);
2452 GNUNET_asprintf (&cfgname,
2453 "/etc/%s/%s",
2454 dpd->project_dirname,
2455 dpd->config_file);
2456 }
2457 if (GNUNET_OK != GNUNET_DISK_file_test (cfgname))
2458 {
2460 "Unable to top-level configuration file.\n");
2461 GNUNET_OS_init (pd);
2463 GNUNET_free (cfgname);
2464 return NULL;
2465 }
2466
2467 /* We found a configuration file that looks good, try to load it. */
2468
2470 "Loading top-level configuration from '%s'\n",
2471 cfgname);
2472 if (GNUNET_OK !=
2473 GNUNET_CONFIGURATION_load (cfg, cfgname))
2474 {
2475 GNUNET_OS_init (pd);
2477 GNUNET_free (cfgname);
2478 return NULL;
2479 }
2480 GNUNET_free (cfgname);
2481 GNUNET_OS_init (pd);
2482 return cfg;
2483}
2484
2485
2496 const char *filename)
2497{
2498 char *baseconfig;
2499 const char *base_config_varname;
2500
2501 if (cfg->load_called)
2502 {
2503 /* FIXME: Make this a GNUNET_assert later */
2504 GNUNET_break (0);
2506 }
2507 cfg->load_called = true;
2508 if (NULL != filename)
2509 {
2512 }
2513
2514 base_config_varname = GNUNET_OS_project_data_get ()->base_config_varname;
2515
2516 if ((NULL != base_config_varname)
2517 && (NULL != (baseconfig = getenv (base_config_varname))))
2518 {
2519 baseconfig = GNUNET_strdup (baseconfig);
2520 }
2521 else
2522 {
2523 char *ipath;
2524
2526 if (NULL == ipath)
2527 {
2528 GNUNET_break (0);
2529 return GNUNET_SYSERR;
2530 }
2531 GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d");
2532 GNUNET_free (ipath);
2533 }
2534
2535 char *dname = GNUNET_STRINGS_filename_expand (baseconfig);
2536 GNUNET_free (baseconfig);
2537
2538 if ((GNUNET_YES ==
2540 GNUNET_YES)) &&
2541 (GNUNET_SYSERR ==
2543 dname)))
2544 {
2546 "Failed to load base configuration from '%s'\n",
2547 filename);
2548 GNUNET_free (dname);
2549 return GNUNET_SYSERR; /* no configuration at all found */
2550 }
2551 GNUNET_free (dname);
2552 if ((NULL != filename) &&
2553 (GNUNET_OK !=
2555 filename)))
2556 {
2557 /* specified configuration not found */
2559 "Failed to load configuration from file '%s'\n",
2560 filename);
2561 return GNUNET_SYSERR;
2562 }
2563 if (((GNUNET_YES !=
2565 "PATHS",
2566 "DEFAULTCONFIG"))) &&
2567 (filename != NULL))
2569 "PATHS",
2570 "DEFAULTCONFIG",
2571 filename);
2572 return GNUNET_OK;
2573}
2574
2575
2576/* 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 struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
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...
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 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,...)
Definition: configuration.c:30
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 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:99
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
static int list
Set if we should print a list of currently running services.
Definition: gnunet-arm.c:69
static int ret
Final status code.
Definition: gnunet-arm.c:94
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
static int prefix
If printing the value of PREFIX has been requested.
Definition: gnunet-config.c:66
static char * line
Desired phone line (string to be converted to a hash).
struct GNUNET_HashCode key
The key used in the DHT.
static void cleanup(void *cls)
Disconnect and shutdown.
Definition: gnunet-did.c:131
static char * filename
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:37
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 struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
Configuration API.
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_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_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.
void(* GNUNET_CONFIGURATION_SectionIterator)(void *cls, const char *section)
Function to iterate over section.
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.
char * GNUNET_CONFIGURATION_default_filename(void)
Return the filename of the default configuration filename that is used when no explicit configuration...
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_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...
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create()
Create a new configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration (starts with defaults, then loads system-specific configuration).
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_default(void)
Return GNUnet's default 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_parse_and_run(const char *filename, GNUNET_CONFIGURATION_Callback cb, void *cb_cls)
Parse a configuration file filename and run the function cb with the resulting configuration object.
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:1237
int GNUNET_DISK_glob(const char *glob_pattern, GNUNET_FileNameCallback callback, void *callback_cls)
Find all files matching a glob pattern.
Definition: disk.c:1009
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:482
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:686
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test_read(const char *fil)
Check that fil corresponds to a filename and the file has read permissions.
Definition: disk.c:489
enum GNUNET_GenericReturnValue GNUNET_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:221
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1087
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:403
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:582
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:664
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:814
@ 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:123
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:103
#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.
#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(enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_default(void)
Return default project data used by 'libgnunetutil' for GNUnet.
void GNUNET_OS_init(const struct GNUNET_OS_ProjectData *pd)
Setup OS subsystem with project data.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
@ 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:495
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:789
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:260
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:236
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define DIR_SEPARATOR_STR
Definition: platform.h:166
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
#define SIZE_MAX
Definition: platform.h:208
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
Definition: configuration.c:39
char * hint_filename
Diagnostics information for the filename.
Definition: configuration.c:58
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:43
char * key
key for this entry
Definition: configuration.c:48
unsigned int hint_lineno
Diagnostics information for the line number.
Definition: configuration.c:63
char * val
current, committed value
Definition: configuration.c:53
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
Definition: configuration.c:71
char * name
name of the section
Definition: configuration.c:85
char * hint_inlined_from_filename
For secret sections: Where was this inlined from?
struct ConfigEntry * entries
entries in the section
Definition: configuration.c:80
bool inaccessible
Is the configuration section marked as inaccessible?
Definition: configuration.c:93
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:75
char * hint_secret_filename
Diagnostics hint for the secret file.
Definition: configuration.c:98
unsigned int hint_inlined_from_line
For secret sections: Where was this inlined from?
char * hint_secret_stat
Extra information regarding permissions of the secret file.
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.
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.
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.