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 if (NULL == cfg)
404 return NULL;
405
406 pos = cfg->sections;
407 while ((pos != NULL) && (0 != strcasecmp (section, pos->name)))
408 pos = pos->next;
409 return pos;
410}
411
412
413static int
414pstrcmp (const void *a, const void *b)
415{
416 return strcmp (*((const char **) a), *((const char **) b));
417}
418
419
427 const char *path_or_glob,
428 bool path_is_glob,
429 const char *restrict_section,
430 const char *source_filename,
431 unsigned int source_lineno)
432{
433 char *inline_path = NULL;
434 struct GNUNET_CONFIGURATION_Handle *other_cfg = NULL;
435 struct CollectFilesContext igc = {
436 .files = NULL,
437 .files_length = 0,
438 };
439 enum GNUNET_GenericReturnValue fun_ret;
440 unsigned int old_nest_level = cfg->current_nest_level++;
441
442 /* We support the section restriction only for non-globs */
443 GNUNET_assert (! (path_is_glob && (NULL != restrict_section)));
444
445 if (NULL == source_filename)
446 {
448 "Refusing to parse inline configurations, "
449 "not allowed without source filename!\n");
450 fun_ret = GNUNET_SYSERR;
451 goto cleanup;
452 }
453
454 if ('/' == *path_or_glob)
455 inline_path = GNUNET_strdup (path_or_glob);
456 else
457 {
458 /* We compute the canonical, absolute path first,
459 so that relative imports resolve properly with symlinked
460 config files. */
461 char *source_realpath;
462 char *endsep;
463
464 source_realpath = realpath (source_filename,
465 NULL);
466 if (NULL == source_realpath)
467 {
468 /* Couldn't even resolve path of base dir. */
469 GNUNET_break (0);
470 /* failed to parse included config */
471 fun_ret = GNUNET_SYSERR;
472 goto cleanup;
473 }
474 endsep = strrchr (source_realpath, '/');
475 GNUNET_assert (NULL != endsep);
476 *endsep = '\0';
477 GNUNET_asprintf (&inline_path,
478 "%s/%s",
479 source_realpath,
480 path_or_glob);
481 free (source_realpath);
482 }
483
484 if (path_is_glob)
485 {
486 int nret;
487
489 "processing config glob '%s'\n",
490 inline_path);
491
492 nret = GNUNET_DISK_glob (inline_path, collect_files_cb, &igc);
493 if (-1 == nret)
494 {
495 fun_ret = GNUNET_SYSERR;
496 goto cleanup;
497 }
498 GNUNET_assert (nret == igc.files_length);
499 qsort (igc.files, igc.files_length, sizeof (char *), pstrcmp);
500 for (int i = 0; i < nret; i++)
501 {
502 if (GNUNET_OK !=
504 igc.files[i]))
505 {
506 fun_ret = GNUNET_SYSERR;
507 goto cleanup;
508 }
509 }
510 fun_ret = GNUNET_OK;
511 }
512 else if (NULL != restrict_section)
513 {
514 enum GNUNET_GenericReturnValue inner_ret;
515 struct ConfigSection *cs;
516 struct ConfigFile *cf = GNUNET_new (struct ConfigFile);
517
518 inner_ret = GNUNET_DISK_file_test_read (inline_path);
519
520 cs = find_section (cfg, restrict_section);
521
522 if (NULL == cs)
523 {
524 cs = GNUNET_new (struct ConfigSection);
525 cs->name = GNUNET_strdup (restrict_section);
526 cs->next = cfg->sections;
527 cfg->sections = cs;
528 cs->entries = NULL;
529 }
530 if (cfg->diagnostics)
531 {
532 char *sfn = GNUNET_STRINGS_filename_expand (inline_path);
533 struct stat istat;
534
535 cs->hint_secret_filename = sfn;
536 if (0 == stat (sfn, &istat))
537 {
538 struct passwd *pw = getpwuid (istat.st_uid);
539 struct group *gr = getgrgid (istat.st_gid);
540 char *pwname = (NULL == pw) ? "<unknown>" : pw->pw_name;
541 char *grname = (NULL == gr) ? "<unknown>" : gr->gr_name;
542
544 "%s:%s %o",
545 pwname,
546 grname,
547 istat.st_mode);
548 }
549 else
550 {
551 cs->hint_secret_stat = GNUNET_strdup ("<can't stat file>");
552 }
553 if (source_filename)
554 {
555 /* Possible that this secret section has been inlined before */
557 cs->hint_inlined_from_filename = GNUNET_strdup (source_filename);
558 cs->hint_inlined_from_line = source_lineno;
559 }
560 }
561
562 /* Put file in the load list for diagnostics, even if we can't access it. */
563 {
565 cf->source_filename = GNUNET_strdup (inline_path);
566 cf->hint_restrict_section = GNUNET_strdup (restrict_section);
569 cf);
570 }
571
572 if (GNUNET_OK != inner_ret)
573 {
574 cs->inaccessible = true;
575 cf->hint_inaccessible = true;
576 /* File can't be accessed, but that's okay. */
577 fun_ret = GNUNET_OK;
578 goto cleanup;
579 }
580
581 other_cfg = GNUNET_CONFIGURATION_create ();
582 other_cfg->restrict_section = restrict_section;
583 inner_ret = GNUNET_CONFIGURATION_parse (other_cfg,
584 inline_path);
585 if (GNUNET_OK != inner_ret)
586 {
587 cf->hint_inaccessible = true;
588 fun_ret = inner_ret;
589 goto cleanup;
590 }
591
592 cs = find_section (other_cfg, restrict_section);
593 if (NULL == cs)
594 {
596 "Configuration file '%s' loaded with @inline-secret@ "
597 "does not contain section '%s'.\n",
598 inline_path,
599 restrict_section);
600 /* Inlined onfiguration is accessible but doesn't contain any values.
601 We treat this as if the inlined section was empty, and do not
602 consider it an error. */
603 fun_ret = GNUNET_OK;
604 goto cleanup;
605 }
606 for (struct ConfigEntry *ce = cs->entries;
607 NULL != ce;
608 ce = ce->next)
610 restrict_section,
611 ce->key,
612 ce->val);
613 fun_ret = GNUNET_OK;
614 }
615 else if (GNUNET_OK !=
617 inline_path))
618 {
619 fun_ret = GNUNET_SYSERR;
620 goto cleanup;
621 }
622 else
623 {
624 fun_ret = GNUNET_OK;
625 }
626cleanup:
627 cfg->current_nest_level = old_nest_level;
628 if (NULL != other_cfg)
630 GNUNET_free (inline_path);
631 if (igc.files_length > 0)
632 {
633 for (size_t i = 0; i < igc.files_length; i++)
634 GNUNET_free (igc.files[i]);
636 }
637 return fun_ret;
638}
639
640
649static struct ConfigEntry *
651 const char *section,
652 const char *key)
653{
654 struct ConfigSection *sec;
655 struct ConfigEntry *pos;
656
657 if (NULL == (sec = find_section (cfg, section)))
658 return NULL;
659 if (sec->inaccessible)
660 {
662 "Section '%s' is marked as inaccessible, because the configuration "
663 " file that contains the section can't be read. Attempts to use "
664 "option '%s' will fail.\n",
665 section,
666 key);
667 return NULL;
668 }
669 pos = sec->entries;
670 while ((pos != NULL) && (0 != strcasecmp (key, pos->key)))
671 pos = pos->next;
672 return pos;
673}
674
675
685static void
687 const char *section,
688 const char *option,
689 const char *hint_filename,
690 unsigned int hint_line)
691{
692 struct ConfigEntry *e = find_entry (cfg, section, option);
693 if (! cfg->diagnostics)
694 return;
695 if (! e)
696 return;
698 e->hint_lineno = hint_line;
699}
700
701
704 const char *mem,
705 size_t size,
706 const char *source_filename)
707{
708 size_t line_size;
709 unsigned int nr;
710 size_t r_bytes;
711 size_t to_read;
713 char *section;
714 char *eq;
715 char *tag;
716 char *value;
717 char *line_orig = NULL;
718
719 ret = GNUNET_OK;
720 section = NULL;
721 nr = 0;
722 r_bytes = 0;
723 while (r_bytes < size)
724 {
725 char *pos;
726 char *line;
727 bool emptyline;
728
729 GNUNET_free (line_orig);
730 /* fgets-like behaviour on buffer */
731 to_read = size - r_bytes;
732 pos = memchr (&mem[r_bytes], '\n', to_read);
733 if (NULL == pos)
734 {
735 line_orig = GNUNET_strndup (&mem[r_bytes],
736 line_size = to_read);
737 r_bytes += line_size;
738 }
739 else
740 {
741 line_orig = GNUNET_strndup (&mem[r_bytes],
742 line_size = (pos - &mem[r_bytes]));
743 r_bytes += line_size + 1;
744 }
745 line = line_orig;
746 /* increment line number */
747 nr++;
748 /* tabs and '\r' are whitespace */
749 emptyline = GNUNET_YES;
750 for (size_t i = 0; i < line_size; i++)
751 {
752 if (line[i] == '\t')
753 line[i] = ' ';
754 if (line[i] == '\r')
755 line[i] = ' ';
756 if (' ' != line[i])
757 emptyline = GNUNET_NO;
758 }
759 /* ignore empty lines */
760 if (GNUNET_YES == emptyline)
761 continue;
762
763 /* remove tailing whitespace */
764 for (size_t i = line_size - 1;
765 (i >= 1) && (isspace ((unsigned char) line[i]));
766 i--)
767 line[i] = '\0';
768
769 /* remove leading whitespace */
770 for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++)
771 ;
772
773 /* ignore comments */
774 if ( ('#' == line[0]) ||
775 ('%' == line[0]) )
776 continue;
777
778 /* Handle special directives. */
779 if ('@' == line[0])
780 {
781 char *end = strchr (line + 1, '@');
782 char *directive;
783 enum GNUNET_GenericReturnValue directive_ret;
784
785 if (NULL != cfg->restrict_section)
786 {
788 "Illegal directive in line %u (parsing restricted section %s)\n",
789 nr,
792 break;
793 }
794
795 if (NULL == end)
796 {
798 "Bad directive in line %u\n",
799 nr);
801 break;
802 }
803 *end = '\0';
804 directive = line + 1;
805
806 if (0 == strcasecmp (directive,
807 "INLINE"))
808 {
809 const char *path = end + 1;
810
811 /* Skip space before path */
812 for (; isspace (*path); path++)
813 ;
814
815 directive_ret = handle_inline (cfg,
816 path,
817 false,
818 NULL,
819 source_filename,
820 nr);
821 }
822 else if (0 == strcasecmp (directive,
823 "INLINE-MATCHING"))
824 {
825 const char *path = end + 1;
826
827 /* Skip space before path */
828 for (; isspace (*path); path++)
829 ;
830
831 directive_ret = handle_inline (cfg,
832 path,
833 true,
834 NULL,
835 source_filename,
836 nr);
837 }
838 else if (0 == strcasecmp (directive,
839 "INLINE-SECRET"))
840 {
841 char *secname = end + 1;
842 char *secname_end;
843 const char *path;
844
845 /* Skip space before secname */
846 for (; isspace (*secname); secname++)
847 ;
848
849 secname_end = strchr (secname, ' ');
850
851 if (NULL == secname_end)
852 {
854 "Bad inline-secret directive in line %u\n",
855 nr);
857 break;
858 }
859 *secname_end = '\0';
860 path = secname_end + 1;
861
862 /* Skip space before path */
863 for (; isspace (*path); path++)
864 ;
865
866 directive_ret = handle_inline (cfg,
867 path,
868 false,
869 secname,
870 source_filename,
871 nr);
872 }
873 else
874 {
876 "Unknown or malformed directive '%s' in line %u\n",
877 directive,
878 nr);
880 break;
881 }
882 if (GNUNET_OK != directive_ret)
883 {
884 ret = directive_ret;
885 break;
886 }
887 continue;
888 }
889 if ( ('[' == line[0]) &&
890 (']' == line[line_size - 1]) )
891 {
892 /* [value] */
893 line[line_size - 1] = '\0';
894 value = &line[1];
895 GNUNET_free (section);
896 section = GNUNET_strdup (value);
897 continue;
898 }
899 if (NULL != (eq = strchr (line, '=')))
900 {
901 size_t i;
902
903 if (NULL == section)
904 {
906 "Syntax error while deserializing in line %u (option without section)\n",
907 nr);
909 break;
910 }
911
912 /* tag = value */
913 tag = GNUNET_strndup (line, eq - line);
914 /* remove tailing whitespace */
915 for (i = strlen (tag) - 1;
916 (i >= 1) && (isspace ((unsigned char) tag[i]));
917 i--)
918 tag[i] = '\0';
919
920 /* Strip whitespace */
921 value = eq + 1;
922 while (isspace ((unsigned char) value[0]))
923 value++;
924 for (i = strlen (value) - 1;
925 (i >= 1) && (isspace ((unsigned char) value[i]));
926 i--)
927 value[i] = '\0';
928
929 /* remove quotes */
930 i = 0;
931 if ( ('"' == value[0]) &&
932 ('"' == value[strlen (value) - 1]) )
933 {
934 value[strlen (value) - 1] = '\0';
935 value++;
936 }
938 section,
939 tag,
940 &value[i]);
941 if (cfg->diagnostics)
942 {
944 section,
945 tag,
946 source_filename
947 ? source_filename
948 : "<input>",
949 nr);
950 }
951 GNUNET_free (tag);
952 continue;
953 }
954 /* parse error */
956 "Syntax error while deserializing in line %u\n",
957 nr);
959 break;
960 }
961 GNUNET_free (line_orig);
962 GNUNET_free (section);
963 GNUNET_assert ( (GNUNET_OK != ret) ||
964 (r_bytes == size) );
965 return ret;
966}
967
968
971 const char *filename)
972{
973 uint64_t fs64;
974 size_t fs;
975 char *fn;
976 char *mem;
977 int dirty;
979 ssize_t sret;
980
982 LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to parse config file `%s'\n", fn);
983 if (NULL == fn)
984 return GNUNET_SYSERR;
985
986
987 /* Check for cycles */
988 {
989 unsigned int lvl = cfg->current_nest_level;
990 struct ConfigFile *cf = cfg->loaded_files_tail;
991 struct ConfigFile *parent = NULL;
992
993
994 for (; NULL != cf; parent = cf, cf = cf->prev)
995 {
996 /* Check parents based on level, skipping children of siblings. */
997 if (cf->level >= lvl)
998 continue;
999 lvl = cf->level;
1000 if ( (NULL == cf->source_filename) || (NULL == filename))
1001 continue;
1002 if (0 == strcmp (cf->source_filename, filename))
1003 {
1004 if (NULL == parent)
1005 {
1007 "Forbidden direct cyclic configuration import (%s -> %s)\n",
1008 cf->source_filename,
1009 filename);
1010 }
1011 else
1013 "Forbidden indirect cyclic configuration import (%s -> ... -> %s -> %s)\n",
1014 cf->source_filename,
1015 parent->source_filename,
1016 filename);
1017 GNUNET_free (fn);
1018 return GNUNET_SYSERR;
1019 }
1020 }
1021
1022 }
1023
1024 /* Keep track of loaded files.*/
1025 {
1026 struct ConfigFile *cf = GNUNET_new (struct ConfigFile);
1027
1029 cf->source_filename = GNUNET_strdup (filename ? filename : "<input>");
1032 cf);
1033 }
1034
1035 dirty = cfg->dirty; /* back up value! */
1036 if (GNUNET_SYSERR ==
1038 &fs64,
1039 GNUNET_YES,
1040 GNUNET_YES))
1041 {
1043 "Error while determining the file size of `%s'\n",
1044 fn);
1045 GNUNET_free (fn);
1046 return GNUNET_SYSERR;
1047 }
1048 if (fs64 > SIZE_MAX)
1049 {
1050 GNUNET_break (0); /* File size is more than the heap size */
1051 GNUNET_free (fn);
1052 return GNUNET_SYSERR;
1053 }
1054 fs = fs64;
1055 mem = GNUNET_malloc (fs);
1056 sret = GNUNET_DISK_fn_read (fn, mem, fs);
1057 if ((sret < 0) || (fs != (size_t) sret))
1058 {
1060 "Error while reading file `%s'\n",
1061 fn);
1062 GNUNET_free (fn);
1063 GNUNET_free (mem);
1064 return GNUNET_SYSERR;
1065 }
1067 "Deserializing contents of file `%s'\n",
1068 fn);
1070 mem,
1071 fs,
1072 fn);
1073 if (GNUNET_SYSERR == ret)
1074 {
1076 _ ("Failed to parse configuration file `%s'\n"),
1077 fn);
1078 }
1079 GNUNET_free (fn);
1080 GNUNET_free (mem);
1081 /* restore dirty flag - anything we set in the meantime
1082 * came from disk */
1083 cfg->dirty = dirty;
1084 return ret;
1085}
1086
1087
1090{
1091 return cfg->dirty;
1092}
1093
1094
1102static bool
1103do_skip (const char *sec,
1104 const char *key)
1105{
1106 if (0 != strcasecmp ("PATHS",
1107 sec))
1108 return false;
1109 return ( (0 == strcasecmp ("DATADIR",
1110 key)) ||
1111 (0 == strcasecmp ("LIBDIR",
1112 key)) ||
1113 (0 == strcasecmp ("BINDIR",
1114 key)) ||
1115 (0 == strcasecmp ("PREFIX",
1116 key)) ||
1117 (0 == strcasecmp ("LOCALEDIR",
1118 key)) ||
1119 (0 == strcasecmp ("ICONDIR",
1120 key)) ||
1121 (0 == strcasecmp ("DOCDIR",
1122 key)) ||
1123 (0 == strcasecmp ("DEFAULTCONFIG",
1124 key)) ||
1125 (0 == strcasecmp ("LIBEXECDIR",
1126 key)) );
1127}
1128
1129
1130char *
1132 size_t *size)
1133{
1134 char *mem;
1135 char *cbuf;
1136 char *val;
1137 char *pos;
1138 size_t m_size;
1139 size_t c_size;
1140
1141 /* Pass1 : calculate the buffer size required */
1142 m_size = 0;
1143 for (struct ConfigSection *sec = cfg->sections;
1144 NULL != sec;
1145 sec = sec->next)
1146 {
1147 if (sec->inaccessible)
1148 continue;
1149 /* For each section we need to add 3 characters: {'[',']','\n'} */
1150 m_size += strlen (sec->name) + 3;
1151 for (struct ConfigEntry *ent = sec->entries;
1152 NULL != ent;
1153 ent = ent->next)
1154 {
1155 if (do_skip (sec->name,
1156 ent->key))
1157 continue;
1158 if (NULL != ent->val)
1159 {
1160 /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */
1161 pos = ent->val;
1162 while (NULL != (pos = strstr (pos, "\n")))
1163 {
1164 m_size++;
1165 pos++;
1166 }
1167 /* For each key = value pair we need to add 4 characters (2
1168 spaces and 1 equal-to character and 1 new line) */
1169 m_size += strlen (ent->key) + strlen (ent->val) + 4;
1170 }
1171 }
1172 /* A new line after section end */
1173 m_size++;
1174 }
1175
1176 /* Pass2: Allocate memory and write the configuration to it */
1177 mem = GNUNET_malloc (m_size);
1178 c_size = 0;
1179 *size = c_size;
1180 for (struct ConfigSection *sec = cfg->sections;
1181 NULL != sec;
1182 sec = sec->next)
1183 {
1184 int len;
1185
1186 len = GNUNET_asprintf (&cbuf,
1187 "[%s]\n",
1188 sec->name);
1189 GNUNET_assert (0 < len);
1190 GNUNET_memcpy (mem + c_size,
1191 cbuf,
1192 len);
1193 c_size += len;
1194 GNUNET_free (cbuf);
1195 for (struct ConfigEntry *ent = sec->entries;
1196 NULL != ent;
1197 ent = ent->next)
1198 {
1199 if (do_skip (sec->name,
1200 ent->key))
1201 continue;
1202 if (NULL != ent->val)
1203 {
1204 val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1205 strcpy (val, ent->val);
1206 while (NULL != (pos = strstr (val, "\n")))
1207 {
1208 memmove (&pos[2], &pos[1], strlen (&pos[1]));
1209 pos[0] = '\\';
1210 pos[1] = 'n';
1211 }
1212 len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
1213 GNUNET_free (val);
1214 GNUNET_memcpy (mem + c_size, cbuf, len);
1215 c_size += len;
1216 GNUNET_free (cbuf);
1217 }
1218 }
1219 GNUNET_memcpy (mem + c_size, "\n", 1);
1220 c_size++;
1221 }
1222 GNUNET_assert (c_size == m_size);
1223 *size = c_size;
1224 return mem;
1225}
1226
1227
1228char *
1231{
1232 struct GNUNET_Buffer buf = { 0 };
1233
1235 "#\n# Configuration file diagnostics\n#\n");
1237 "# Entry point: %s\n",
1239 "<none>");
1241 "#\n# Files Loaded:\n");
1242
1243 for (struct ConfigFile *cfil = cfg->loaded_files_head;
1244 NULL != cfil;
1245 cfil = cfil->next)
1246 {
1248 "# ");
1249 for (unsigned int i = 0; i < cfil->level; i++)
1251 "+");
1252 if (0 != cfil->level)
1254 " ");
1255
1257 "%s",
1258 cfil->source_filename);
1259
1260 if (NULL != cfil->hint_restrict_section)
1262 " (%s secret section %s)",
1263 cfil->hint_inaccessible
1264 ? "inaccessible"
1265 : "loaded",
1266 cfil->hint_restrict_section);
1267
1269 "\n");
1270 }
1271
1273 "#\n\n");
1274
1275 for (struct ConfigSection *sec = cfg->sections;
1276 NULL != sec;
1277 sec = sec->next)
1278 {
1279 if (sec->hint_secret_filename)
1281 "# secret section from %s\n# secret file stat %s\n",
1282 sec->hint_secret_filename,
1283 sec->hint_secret_stat);
1284 if (sec->hint_inlined_from_filename)
1285 {
1287 "# inlined from %s:%u\n",
1288 sec->hint_inlined_from_filename,
1289 sec->hint_inlined_from_line);
1290 }
1292 "[%s]\n\n",
1293 sec->name);
1294 if (sec->inaccessible)
1295 {
1297 "# <section contents inaccessible>\n\n\n");
1298 continue;
1299 }
1300 for (struct ConfigEntry *ent = sec->entries;
1301 NULL != ent;
1302 ent = ent->next)
1303 {
1304 if (do_skip (sec->name,
1305 ent->key))
1306 continue;
1307 if (NULL != ent->val)
1308 {
1309 char *pos;
1310 char *val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1311 strcpy (val, ent->val);
1312 while (NULL != (pos = strstr (val, "\n")))
1313 {
1314 memmove (&pos[2], &pos[1], strlen (&pos[1]));
1315 pos[0] = '\\';
1316 pos[1] = 'n';
1317 }
1318 if (NULL != ent->hint_filename)
1319 {
1321 "# %s:%u\n",
1322 ent->hint_filename,
1323 ent->hint_lineno);
1324 }
1326 "%s = %s\n",
1327 ent->key,
1328 val);
1329 GNUNET_free (val);
1330 }
1331 GNUNET_buffer_write_str (&buf, "\n");
1332 }
1333 GNUNET_buffer_write_str (&buf, "\n");
1334 }
1335 return GNUNET_buffer_reap_str (&buf);
1336}
1337
1338
1341 const char *filename)
1342{
1343 char *fn;
1344 char *cfg_buf;
1345 size_t size;
1346
1348 if (fn == NULL)
1349 return GNUNET_SYSERR;
1351 {
1352 GNUNET_free (fn);
1353 return GNUNET_SYSERR;
1354 }
1356 &size);
1357 {
1358 struct GNUNET_DISK_FileHandle *h;
1359
1368 if (NULL == h)
1369 {
1370 GNUNET_free (fn);
1371 GNUNET_free (cfg_buf);
1372 return GNUNET_SYSERR;
1373 }
1374 if (((ssize_t) size) !=
1376 cfg_buf,
1377 size))
1378 {
1380 "write",
1381 fn);
1383 (void) GNUNET_DISK_directory_remove (fn);
1384 GNUNET_free (fn);
1385 GNUNET_free (cfg_buf);
1386 cfg->dirty = GNUNET_SYSERR; /* last write failed */
1387 return GNUNET_SYSERR;
1388 }
1391 }
1392 GNUNET_free (fn);
1393 GNUNET_free (cfg_buf);
1394 cfg->dirty = GNUNET_NO; /* last write succeeded */
1395 return GNUNET_OK;
1396}
1397
1398
1399void
1402 void *iter_cls)
1403{
1404 for (struct ConfigSection *spos = cfg->sections;
1405 NULL != spos;
1406 spos = spos->next)
1407 for (struct ConfigEntry *epos = spos->entries;
1408 NULL != epos;
1409 epos = epos->next)
1410 if (NULL != epos->val)
1411 iter (iter_cls,
1412 spos->name,
1413 epos->key,
1414 epos->val);
1415}
1416
1417
1418void
1420 const struct GNUNET_CONFIGURATION_Handle *cfg,
1421 const char *section,
1423 void *iter_cls)
1424{
1425 struct ConfigSection *spos;
1426 struct ConfigEntry *epos;
1427
1428 spos = cfg->sections;
1429 while ((spos != NULL) && (0 != strcasecmp (spos->name, section)))
1430 spos = spos->next;
1431 if (NULL == spos)
1432 return;
1433 if (spos->inaccessible)
1434 {
1436 "Section '%s' is marked as inaccessible, because the configuration "
1437 " file that contains the section can't be read.\n",
1438 section);
1439 return;
1440 }
1441 for (epos = spos->entries; NULL != epos; epos = epos->next)
1442 if (NULL != epos->val)
1443 iter (iter_cls, spos->name, epos->key, epos->val);
1444}
1445
1446
1447void
1449 const struct GNUNET_CONFIGURATION_Handle *cfg,
1451 void *iter_cls)
1452{
1453 struct ConfigSection *spos;
1454 struct ConfigSection *next;
1455
1456 next = cfg->sections;
1457 while (next != NULL)
1458 {
1459 spos = next;
1460 next = spos->next;
1461 iter (iter_cls, spos->name);
1462 }
1463}
1464
1465
1466void
1468 const char *section)
1469{
1470 struct ConfigSection *spos;
1471 struct ConfigSection *prev;
1472 struct ConfigEntry *ent;
1473
1474 prev = NULL;
1475 spos = cfg->sections;
1476 while (NULL != spos)
1477 {
1478 if (0 == strcasecmp (section, spos->name))
1479 {
1480 if (NULL == prev)
1481 cfg->sections = spos->next;
1482 else
1483 prev->next = spos->next;
1484 while (NULL != (ent = spos->entries))
1485 {
1486 spos->entries = ent->next;
1487 GNUNET_free (ent->key);
1488 GNUNET_free (ent->val);
1490 GNUNET_free (ent);
1491 cfg->dirty = GNUNET_YES;
1492 }
1493 GNUNET_free (spos->name);
1497 GNUNET_free (spos);
1498 return;
1499 }
1500 prev = spos;
1501 spos = spos->next;
1502 }
1503}
1504
1505
1515static void
1516copy_entry (void *cls,
1517 const char *section,
1518 const char *option,
1519 const char *value)
1520{
1521 struct GNUNET_CONFIGURATION_Handle *dst = cls;
1522
1524 section,
1525 option,
1526 value);
1527}
1528
1529
1532{
1534
1537 return ret;
1538}
1539
1540
1551static void
1553 const char *section,
1554 const char *option,
1555 const char *value)
1556{
1557 struct DiffHandle *dh = cls;
1558 struct ConfigEntry *entNew;
1559
1560 entNew = find_entry (dh->cfg_default, section, option);
1561 if ((NULL != entNew) && (NULL != entNew->val) &&
1562 (0 == strcmp (entNew->val, value)))
1563 return;
1565 section,
1566 option,
1567 value);
1568}
1569
1570
1573 const struct GNUNET_CONFIGURATION_Handle *cfg_default,
1574 const struct GNUNET_CONFIGURATION_Handle *cfg_new)
1575{
1576 struct DiffHandle diffHandle;
1577
1578 diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
1579 diffHandle.cfg_default = cfg_default;
1580 GNUNET_CONFIGURATION_iterate (cfg_new, &compare_entries, &diffHandle);
1581 return diffHandle.cfgDiff;
1582}
1583
1584
1588 const struct GNUNET_CONFIGURATION_Handle *cfg_new,
1589 const char *filename)
1590{
1591 int ret;
1592 struct GNUNET_CONFIGURATION_Handle *diff;
1593
1594 diff = GNUNET_CONFIGURATION_get_diff (cfg_default, cfg_new);
1597 return ret;
1598}
1599
1600
1601void
1603 const char *section,
1604 const char *option,
1605 const char *value)
1606{
1607 struct ConfigSection *sec;
1608 struct ConfigEntry *e;
1609 char *nv;
1610
1611 e = find_entry (cfg, section, option);
1612 if (NULL != e)
1613 {
1614 if (NULL == value)
1615 {
1616 GNUNET_free (e->val);
1617 e->val = NULL;
1618 }
1619 else
1620 {
1621 nv = GNUNET_strdup (value);
1622 GNUNET_free (e->val);
1623 e->val = nv;
1624 }
1625 return;
1626 }
1627 sec = find_section (cfg, section);
1628 if (sec == NULL)
1629 {
1630 sec = GNUNET_new (struct ConfigSection);
1631 sec->name = GNUNET_strdup (section);
1632 sec->next = cfg->sections;
1633 cfg->sections = sec;
1634 }
1635 e = GNUNET_new (struct ConfigEntry);
1636 e->key = GNUNET_strdup (option);
1637 e->val = GNUNET_strdup (value);
1638 e->next = sec->entries;
1639 sec->entries = e;
1640}
1641
1642
1643void
1645 const char *section,
1646 const char *option,
1647 unsigned long long number)
1648{
1649 char s[64];
1650
1651 GNUNET_snprintf (s,
1652 64,
1653 "%llu",
1654 number);
1656 section,
1657 option,
1658 s);
1659}
1660
1661
1664 const struct GNUNET_CONFIGURATION_Handle *cfg,
1665 const char *section,
1666 const char *option,
1667 unsigned long long *number)
1668{
1669 struct ConfigEntry *e;
1670 char dummy[2];
1671
1672 if (NULL == (e = find_entry (cfg, section, option)))
1673 return GNUNET_SYSERR;
1674 if (NULL == e->val)
1675 return GNUNET_SYSERR;
1676 if (1 != sscanf (e->val, "%llu%1s", number, dummy))
1677 return GNUNET_SYSERR;
1678 return GNUNET_OK;
1679}
1680
1681
1684 const struct GNUNET_CONFIGURATION_Handle *cfg,
1685 const char *section,
1686 const char *option,
1687 float *number)
1688{
1689 struct ConfigEntry *e;
1690 char dummy[2];
1691
1692 if (NULL == (e = find_entry (cfg, section, option)))
1693 return GNUNET_SYSERR;
1694 if (NULL == e->val)
1695 return GNUNET_SYSERR;
1696 if (1 != sscanf (e->val, "%f%1s", number, dummy))
1697 return GNUNET_SYSERR;
1698 return GNUNET_OK;
1699}
1700
1701
1704 const struct GNUNET_CONFIGURATION_Handle *cfg,
1705 const char *section,
1706 const char *option,
1707 struct GNUNET_TIME_Relative *time)
1708{
1709 struct ConfigEntry *e;
1710 int ret;
1711
1712 if (NULL == (e = find_entry (cfg, section, option)))
1713 return GNUNET_SYSERR;
1714 if (NULL == e->val)
1715 return GNUNET_SYSERR;
1717 if (GNUNET_OK != ret)
1719 section,
1720 option,
1721 _ ("Not a valid relative time specification"));
1722 return ret;
1723}
1724
1725
1728 const struct GNUNET_CONFIGURATION_Handle *cfg,
1729 const char *section,
1730 const char *option,
1731 unsigned long long *size)
1732{
1733 struct ConfigEntry *e;
1734
1735 if (NULL == (e = find_entry (cfg, section, option)))
1736 return GNUNET_SYSERR;
1737 if (NULL == e->val)
1738 return GNUNET_SYSERR;
1740}
1741
1742
1755 const struct GNUNET_CONFIGURATION_Handle *cfg,
1756 const char *section,
1757 const char *option,
1758 char **value)
1759{
1760 struct ConfigEntry *e;
1761
1762 if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1763 {
1764 *value = NULL;
1765 return GNUNET_SYSERR;
1766 }
1767 *value = GNUNET_strdup (e->val);
1768 return GNUNET_OK;
1769}
1770
1771
1774 const struct GNUNET_CONFIGURATION_Handle *cfg,
1775 const char *section,
1776 const char *option,
1777 const char *const *choices,
1778 const char **value)
1779{
1780 struct ConfigEntry *e;
1781 unsigned int i;
1782
1783 if (NULL == (e = find_entry (cfg, section, option)))
1784 return GNUNET_SYSERR;
1785 for (i = 0; NULL != choices[i]; i++)
1786 if (0 == strcasecmp (choices[i], e->val))
1787 break;
1788 if (NULL == choices[i])
1789 {
1791 _ ("Configuration value '%s' for '%s'"
1792 " in section '%s' is not in set of legal choices\n"),
1793 e->val,
1794 option,
1795 section);
1796 return GNUNET_SYSERR;
1797 }
1798 *value = choices[i];
1799 return GNUNET_OK;
1800}
1801
1802
1805 const char *section,
1806 const char *option,
1807 void *buf,
1808 size_t buf_size)
1809{
1810 char *enc;
1811 int res;
1812 size_t data_size;
1813
1814 if (GNUNET_OK !=
1815 (res =
1816 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &enc)))
1817 return res;
1818 data_size = (strlen (enc) * 5) / 8;
1819 if (data_size != buf_size)
1820 {
1821 GNUNET_free (enc);
1822 return GNUNET_SYSERR;
1823 }
1824 if (GNUNET_OK !=
1825 GNUNET_STRINGS_string_to_data (enc, strlen (enc), buf, buf_size))
1826 {
1827 GNUNET_free (enc);
1828 return GNUNET_SYSERR;
1829 }
1830 GNUNET_free (enc);
1831 return GNUNET_OK;
1832}
1833
1834
1837 const char *section,
1838 const char *option)
1839{
1840 struct ConfigEntry *e;
1841
1842 if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1843 return GNUNET_NO;
1844 return GNUNET_YES;
1845}
1846
1847
1863static char *
1865 char *orig,
1866 unsigned int depth)
1867{
1868 char *prefix;
1869 char *result;
1870 char *start;
1871 const char *post;
1872 const char *env;
1873 char *def;
1874 char *end;
1875 unsigned int lopen;
1876 char erased_char;
1877 char *erased_pos;
1878 size_t len;
1879
1880 if (NULL == orig)
1881 return NULL;
1882 if (depth > 128)
1883 {
1885 "Recursive expansion suspected, aborting $-expansion for term `%s'\n",
1886 orig);
1887 return orig;
1888 }
1890 "Asked to $-expand %s\n",
1891 orig);
1892 if ('$' != orig[0])
1893 {
1895 "Doesn't start with $ - not expanding\n");
1896 return orig;
1897 }
1898 erased_char = 0;
1899 erased_pos = NULL;
1900 if ('{' == orig[1])
1901 {
1902 start = &orig[2];
1903 lopen = 1;
1904 end = &orig[1];
1905 while (lopen > 0)
1906 {
1907 end++;
1908 switch (*end)
1909 {
1910 case '}':
1911 lopen--;
1912 break;
1913
1914 case '{':
1915 lopen++;
1916 break;
1917
1918 case '\0':
1920 "Missing closing `}' in option `%s'\n",
1921 orig);
1922 return orig;
1923
1924 default:
1925 break;
1926 }
1927 }
1928 erased_char = *end;
1929 erased_pos = end;
1930 *end = '\0';
1931 post = end + 1;
1932 def = strchr (orig, ':');
1933 if (NULL != def)
1934 {
1935 *def = '\0';
1936 def++;
1937 if (('-' == *def) || ('=' == *def))
1938 def++;
1939 def = GNUNET_strdup (def);
1940 }
1941 }
1942 else
1943 {
1944 int i;
1945
1946 start = &orig[1];
1947 def = NULL;
1948 i = 0;
1949 while ( (orig[i] != '/') &&
1950 (orig[i] != '\\') &&
1951 (orig[i] != '\0') &&
1952 (orig[i] != ' ') )
1953 i++;
1954 if (orig[i] == '\0')
1955 {
1956 post = "";
1957 }
1958 else
1959 {
1960 erased_char = orig[i];
1961 erased_pos = &orig[i];
1962 orig[i] = '\0';
1963 post = &orig[i + 1];
1964 }
1965 }
1967 "Split into `%s' and `%s' with default %s\n",
1968 start,
1969 post,
1970 def);
1971 if (GNUNET_OK !=
1973 "PATHS",
1974 start,
1975 &prefix))
1976 {
1977 if (NULL == (env = getenv (start)))
1978 {
1979 /* try default */
1980 def = expand_dollar (cfg,
1981 def,
1982 depth + 1);
1983 env = def;
1984 }
1985 if (NULL == env)
1986 {
1988 if (erased_pos)
1989 *erased_pos = erased_char;
1991 "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n",
1992 start,
1993 orig);
1995 return orig;
1996 }
1998 }
2000 prefix);
2001 if ((erased_pos) && ('}' != erased_char))
2002 {
2003 len = strlen (prefix) + 1;
2004 prefix = GNUNET_realloc (prefix, len + 1);
2005 prefix[len - 1] = erased_char;
2006 prefix[len] = '\0';
2007 }
2008 result = GNUNET_malloc (strlen (prefix) + strlen (post) + 1);
2009 strcpy (result, prefix);
2010 strcat (result, post);
2011 GNUNET_free (def);
2013 GNUNET_free (orig);
2014 return result;
2015}
2016
2017
2018char *
2020 const struct GNUNET_CONFIGURATION_Handle *cfg,
2021 char *orig)
2022{
2023 char *dup;
2024 size_t i;
2025 size_t len;
2026
2027 for (i = 0; '\0' != orig[i]; i++)
2028 {
2029 if ('$' != orig[i])
2030 continue;
2031 dup = GNUNET_strdup (orig + i);
2032 dup = expand_dollar (cfg, dup, 0);
2033 GNUNET_assert (NULL != dup); /* make compiler happy */
2034 len = strlen (dup) + 1;
2035 orig = GNUNET_realloc (orig, i + len);
2036 GNUNET_memcpy (orig + i, dup, len);
2037 GNUNET_free (dup);
2038 }
2039 return orig;
2040}
2041
2042
2045 const struct GNUNET_CONFIGURATION_Handle *cfg,
2046 const char *section,
2047 const char *option,
2048 char **value)
2049{
2050 char *tmp;
2051
2052 if (GNUNET_OK !=
2053 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp))
2054 {
2055 LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to retrieve filename\n");
2056 *value = NULL;
2057 return GNUNET_SYSERR;
2058 }
2061 GNUNET_free (tmp);
2062 if (*value == NULL)
2063 return GNUNET_SYSERR;
2064 return GNUNET_OK;
2065}
2066
2067
2070 const struct GNUNET_CONFIGURATION_Handle *cfg,
2071 const char *section,
2072 const char *option)
2073{
2074 static const char *yesno[] = { "YES", "NO", NULL };
2075 const char *val;
2076 int ret;
2077
2078 ret =
2079 GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
2080 if (ret == GNUNET_SYSERR)
2081 return ret;
2082 if (val == yesno[0])
2083 return GNUNET_YES;
2084 return GNUNET_NO;
2085}
2086
2087
2088int
2090 const struct GNUNET_CONFIGURATION_Handle *cfg,
2091 const char *section,
2092 const char *option,
2094 void *cb_cls)
2095{
2096 char *list;
2097 char *pos;
2098 char *end;
2099 char old;
2100 int ret;
2101
2102 if (GNUNET_OK !=
2103 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list))
2104 return 0;
2105 GNUNET_assert (list != NULL);
2106 ret = 0;
2107 pos = list;
2108 while (1)
2109 {
2110 while (pos[0] == ' ')
2111 pos++;
2112 if (strlen (pos) == 0)
2113 break;
2114 end = pos + 1;
2115 while ((end[0] != ' ') && (end[0] != '\0'))
2116 {
2117 if (end[0] == '\\')
2118 {
2119 switch (end[1])
2120 {
2121 case '\\':
2122 case ' ':
2123 memmove (end, &end[1], strlen (&end[1]) + 1);
2124
2125 case '\0':
2126 /* illegal, but just keep it */
2127 break;
2128
2129 default:
2130 /* illegal, but just ignore that there was a '/' */
2131 break;
2132 }
2133 }
2134 end++;
2135 }
2136 old = end[0];
2137 end[0] = '\0';
2138 if (strlen (pos) > 0)
2139 {
2140 ret++;
2141 if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos)))
2142 {
2144 break;
2145 }
2146 }
2147 if (old == '\0')
2148 break;
2149 pos = end + 1;
2150 }
2151 GNUNET_free (list);
2152 return ret;
2153}
2154
2155
2162static char *
2163escape_name (const char *value)
2164{
2165 char *escaped;
2166 const char *rpos;
2167 char *wpos;
2168
2169 escaped = GNUNET_malloc (strlen (value) * 2 + 1);
2170 memset (escaped, 0, strlen (value) * 2 + 1);
2171 rpos = value;
2172 wpos = escaped;
2173 while (rpos[0] != '\0')
2174 {
2175 switch (rpos[0])
2176 {
2177 case '\\':
2178 case ' ':
2179 wpos[0] = '\\';
2180 wpos[1] = rpos[0];
2181 wpos += 2;
2182 break;
2183
2184 default:
2185 wpos[0] = rpos[0];
2186 wpos++;
2187 }
2188 rpos++;
2189 }
2190 return escaped;
2191}
2192
2193
2201static enum GNUNET_GenericReturnValue
2202test_match (void *cls, const char *fn)
2203{
2204 const char *of = cls;
2205
2206 return (0 == strcmp (of, fn)) ? GNUNET_SYSERR : GNUNET_OK;
2207}
2208
2209
2213 const char *section,
2214 const char *option,
2215 const char *value)
2216{
2217 char *escaped;
2218 char *old;
2219 char *nw;
2220
2221 if (GNUNET_SYSERR ==
2223 section,
2224 option,
2225 &test_match,
2226 (void *) value))
2227 return GNUNET_NO; /* already exists */
2228 if (GNUNET_OK !=
2229 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
2230 old = GNUNET_strdup ("");
2231 escaped = escape_name (value);
2232 nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2);
2233 strcpy (nw, old);
2234 if (strlen (old) > 0)
2235 strcat (nw, " ");
2236 strcat (nw, escaped);
2238 section,
2239 option,
2240 nw);
2241 GNUNET_free (old);
2242 GNUNET_free (nw);
2243 GNUNET_free (escaped);
2244 return GNUNET_OK;
2245}
2246
2247
2251 const char *section,
2252 const char *option,
2253 const char *value)
2254{
2255 char *list;
2256 char *pos;
2257 char *end;
2258 char *match;
2259 char old;
2260
2261 if (GNUNET_OK !=
2263 section,
2264 option,
2265 &list))
2266 return GNUNET_NO;
2267 match = escape_name (value);
2268 pos = list;
2269 while (1)
2270 {
2271 while (pos[0] == ' ')
2272 pos++;
2273 if (strlen (pos) == 0)
2274 break;
2275 end = pos + 1;
2276 while ((end[0] != ' ') && (end[0] != '\0'))
2277 {
2278 if (end[0] == '\\')
2279 {
2280 switch (end[1])
2281 {
2282 case '\\':
2283 case ' ':
2284 end++;
2285 break;
2286
2287 case '\0':
2288 /* illegal, but just keep it */
2289 break;
2290
2291 default:
2292 /* illegal, but just ignore that there was a '/' */
2293 break;
2294 }
2295 }
2296 end++;
2297 }
2298 old = end[0];
2299 end[0] = '\0';
2300 if (0 == strcmp (pos, match))
2301 {
2302 if (old != '\0')
2303 memmove (pos,
2304 &end[1],
2305 strlen (&end[1]) + 1);
2306 else
2307 {
2308 if (pos != list)
2309 pos[-1] = '\0';
2310 else
2311 pos[0] = '\0';
2312 }
2314 section,
2315 option,
2316 list);
2317 GNUNET_free (list);
2318 GNUNET_free (match);
2319 return GNUNET_OK;
2320 }
2321 if (old == '\0')
2322 break;
2323 end[0] = old;
2324 pos = end + 1;
2325 }
2326 GNUNET_free (list);
2327 GNUNET_free (match);
2328 return GNUNET_NO;
2329}
2330
2331
2334 const char *defaults_d)
2335{
2336 struct CollectFilesContext files_context = {
2337 .files = NULL,
2338 .files_length = 0,
2339 };
2340 enum GNUNET_GenericReturnValue fun_ret;
2341
2342 if (GNUNET_SYSERR ==
2344 &files_context))
2345 return GNUNET_SYSERR; /* no configuration at all found */
2346 qsort (files_context.files,
2347 files_context.files_length,
2348 sizeof (char *),
2349 pstrcmp);
2350 for (unsigned int i = 0; i < files_context.files_length; i++)
2351 {
2352 char *ext;
2353 const char *filename = files_context.files[i];
2354
2355 /* Examine file extension */
2356 ext = strrchr (filename, '.');
2357 if ((NULL == ext) || (0 != strcmp (ext, ".conf")))
2358 {
2359 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Skipping file `%s'\n", filename);
2360 fun_ret = GNUNET_OK;
2361 goto cleanup;
2362 }
2364 if (fun_ret != GNUNET_OK)
2365 break;
2366 }
2367cleanup:
2368 if (files_context.files_length > 0)
2369 {
2370 for (size_t i = 0; i < files_context.files_length; i++)
2371 GNUNET_free (files_context.files[i]);
2372 GNUNET_array_grow (files_context.files,
2373 files_context.files_length,
2374 0);
2375 }
2376 return fun_ret;
2377}
2378
2379
2380char *
2382{
2383 char *cfg_fn;
2385 const char *xdg = getenv ("XDG_CONFIG_HOME");
2386
2387 if (NULL != xdg)
2388 GNUNET_asprintf (&cfg_fn,
2389 "%s%s%s",
2390 xdg,
2392 pd->config_file);
2393 else
2394 cfg_fn = GNUNET_strdup (pd->user_config_file);
2395
2396 if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2397 return cfg_fn;
2398 GNUNET_free (cfg_fn);
2399
2400 /* Fall back to /etc/ for the default configuration.
2401 Should be okay to use forward slashes here. */
2402
2403 GNUNET_asprintf (&cfg_fn,
2404 "/etc/%s",
2405 pd->config_file);
2406 if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2407 return cfg_fn;
2408 GNUNET_free (cfg_fn);
2409
2410 GNUNET_asprintf (&cfg_fn,
2411 "/etc/%s/%s",
2412 pd->project_dirname,
2413 pd->config_file);
2414 if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
2415 return cfg_fn;
2416
2417 GNUNET_free (cfg_fn);
2418 return NULL;
2419}
2420
2421
2424{
2427 const char *xdg = getenv ("XDG_CONFIG_HOME");
2428 char *cfgname = NULL;
2430
2431 /* Makes sure function implicitly looking at the installation directory (for
2432 example GNUNET_CONFIGURATION_load further down) use GNUnet's environment
2433 instead of the caller's. It's done at the start to make sure as many
2434 functions as possible are directed to the proper paths. */
2435 GNUNET_OS_init (dpd);
2436
2438
2439 /* First, try user configuration. */
2440 if (NULL != xdg)
2441 GNUNET_asprintf (&cfgname, "%s/%s", xdg, dpd->config_file);
2442 else
2443 cfgname = GNUNET_strdup (dpd->user_config_file);
2444
2445 /* If user config doesn't exist, try in
2446 /etc/<projdir>/<cfgfile> and /etc/<cfgfile> */
2447 if (GNUNET_OK != GNUNET_DISK_file_test (cfgname))
2448 {
2449 GNUNET_free (cfgname);
2450 GNUNET_asprintf (&cfgname, "/etc/%s", dpd->config_file);
2451 }
2452 if (GNUNET_OK != GNUNET_DISK_file_test (cfgname))
2453 {
2454 GNUNET_free (cfgname);
2455 GNUNET_asprintf (&cfgname,
2456 "/etc/%s/%s",
2457 dpd->project_dirname,
2458 dpd->config_file);
2459 }
2460 if (GNUNET_OK != GNUNET_DISK_file_test (cfgname))
2461 {
2463 "Unable to top-level configuration file.\n");
2464 GNUNET_OS_init (pd);
2466 GNUNET_free (cfgname);
2467 return NULL;
2468 }
2469
2470 /* We found a configuration file that looks good, try to load it. */
2471
2473 "Loading top-level configuration from '%s'\n",
2474 cfgname);
2475 if (GNUNET_OK !=
2476 GNUNET_CONFIGURATION_load (cfg, cfgname))
2477 {
2478 GNUNET_OS_init (pd);
2480 GNUNET_free (cfgname);
2481 return NULL;
2482 }
2483 GNUNET_free (cfgname);
2484 GNUNET_OS_init (pd);
2485 return cfg;
2486}
2487
2488
2499 const char *filename)
2500{
2501 char *baseconfig;
2502 const char *base_config_varname;
2503
2504 if (cfg->load_called)
2505 {
2506 /* FIXME: Make this a GNUNET_assert later */
2507 GNUNET_break (0);
2509 }
2510 cfg->load_called = true;
2511 if (NULL != filename)
2512 {
2515 }
2516
2517 base_config_varname = GNUNET_OS_project_data_get ()->base_config_varname;
2518
2519 if ((NULL != base_config_varname)
2520 && (NULL != (baseconfig = getenv (base_config_varname))))
2521 {
2522 baseconfig = GNUNET_strdup (baseconfig);
2523 }
2524 else
2525 {
2526 char *ipath;
2527
2529 if (NULL == ipath)
2530 {
2531 GNUNET_break (0);
2532 return GNUNET_SYSERR;
2533 }
2534 GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d");
2535 GNUNET_free (ipath);
2536 }
2537
2538 char *dname = GNUNET_STRINGS_filename_expand (baseconfig);
2539 GNUNET_free (baseconfig);
2540
2541 if ((GNUNET_YES ==
2543 GNUNET_YES)) &&
2544 (GNUNET_SYSERR ==
2546 dname)))
2547 {
2549 "Failed to load base configuration from '%s'\n",
2550 filename);
2551 GNUNET_free (dname);
2552 return GNUNET_SYSERR; /* no configuration at all found */
2553 }
2554 GNUNET_free (dname);
2555 if ((NULL != filename) &&
2556 (GNUNET_OK !=
2558 filename)))
2559 {
2560 /* specified configuration not found */
2562 "Failed to load configuration from file '%s'\n",
2563 filename);
2564 return GNUNET_SYSERR;
2565 }
2566 if (((GNUNET_YES !=
2568 "PATHS",
2569 "DEFAULTCONFIG"))) &&
2570 (filename != NULL))
2572 "PATHS",
2573 "DEFAULTCONFIG",
2574 filename);
2575 return GNUNET_OK;
2576}
2577
2578
2579/* 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.