38{
43
48
53
58};
59
60
65{
70
75
80
85};
86
87
92{
97
102
107
115
120
125
130
135};
136
138{
143
148
150
152
158
163
168
173};
174
175
180{
185
190
195
200
205
210
217
222
227
234};
235
236
242{
244
246};
247
248
249void
252{
254}
255
256
259{
262
265
266
270 {
272 "PATHS",
273 "DATADIR",
276 }
280 {
282 "PATHS",
283 "LIBDIR",
286 }
290 {
292 "PATHS",
293 "BINDIR",
296 }
300 {
302 "PATHS",
303 "PREFIX",
306 }
310 {
312 "PATHS",
313 "LOCALEDIR",
316 }
320 {
322 "PATHS",
323 "ICONDIR",
326 }
330 {
332 "PATHS",
333 "DOCDIR",
336 }
340 {
342 "PATHS",
343 "LIBEXECDIR",
346 }
348}
349
350
351void
353{
356
360 {
365 cf);
367 }
370}
371
372
377 void *cb_cls)
378{
381
386 {
390 }
395}
396
397
402{
407
412};
413
414
427{
429
434}
435
436
446 const char *section)
447{
449
451 return NULL;
453 while ( (NULL != pos) &&
454 (0 != strcasecmp (section,
457 return pos;
458}
459
460
461static int
463 const void *b)
464{
465 return strcmp (*((const char **) a),
466 *((const char **) b));
467}
468
469
470static void
472 const char *section,
474
475
483 const char *path_or_glob,
484 bool path_is_glob,
485 const char *restrict_section,
486 const char *source_filename,
487 unsigned int source_lineno)
488{
489 char *inline_path = NULL;
493 .files_length = 0,
494 };
497
498
499 GNUNET_assert (! (path_is_glob && (NULL != restrict_section)));
500
501 if (NULL == source_filename)
502 {
504 "Refusing to parse inline configurations, "
505 "not allowed without source filename!\n");
508 }
509
510 if ('/' == *path_or_glob)
512 else
513 {
514
515
516
517 char *source_realpath;
518 char *endsep;
519
520 source_realpath = realpath (source_filename,
521 NULL);
522 if (NULL == source_realpath)
523 {
524
526
529 }
530 endsep = strrchr (source_realpath, '/');
532 *endsep = '\0';
534 "%s/%s",
535 source_realpath,
536 path_or_glob);
537 free (source_realpath);
538 }
539
540 if (path_is_glob)
541 {
542 int nret;
543
545 "processing config glob '%s'\n",
546 inline_path);
547
550 &igc);
551 if (-1 == nret)
552 {
555 }
559 sizeof (char *),
561 for (int i = 0; i < nret; i++)
562 {
566 {
569 }
570 }
572 }
573 else if (NULL != restrict_section)
574 {
578
580
582
583 if (NULL == cs)
584 {
590 }
592 {
593 const char *pwname;
594 const char *grname;
596 struct stat istat;
597
599 if (0 == stat (sfn, &istat))
600 {
601 struct passwd *pw = getpwuid (istat.st_uid);
602 struct group *gr = getgrgid (istat.st_gid);
603 pwname = (NULL == pw) ? "<unknown>" : pw->pw_name;
604 grname = (NULL == gr) ? "<unknown>" : gr->gr_name;
605
607 "%s:%s %o",
608 pwname,
609 grname,
610 istat.st_mode);
611 }
612 else
613 {
615 }
616 if (source_filename)
617 {
618
622 }
623 }
624
625
626 {
632 cf);
633 }
634
636 {
639
642 }
643
649 inline_path);
651 {
653 fun_ret = inner_ret;
655 }
656
658 restrict_section);
659 if (NULL == cs)
660 {
662 "Configuration file '%s' loaded with @inline-secret@ "
663 "does not contain section '%s'.\n",
664 inline_path,
665 restrict_section);
666
667
668
671 }
673 NULL != ce;
674 ce = ce->next)
676 restrict_section,
677 ce);
679 }
682 inline_path))
683 {
686 }
687 else
688 {
690 }
693 if (NULL != other_cfg)
697 {
701 }
702 return fun_ret;
703}
704
705
716 const char *section,
718{
720
722 section)))
723 return NULL;
725 pos != NULL;
727 if (0 == strcasecmp (
key,
728 pos->key))
729 return pos;
731 {
733 "Section '%s' is marked as inaccessible, because the configuration "
734 "file that contains the section can't be read. Attempts to use "
735 "option '%s' will fail.\n",
736 section,
738 return NULL;
739 }
740 return NULL;
741}
742
743
754static void
756 const char *section,
757 const char *option,
761{
764
766 return;
768 section,
769 option);
770 if (NULL == e)
771 return;
778}
779
780
789static void
791 const char *section,
793{
797
799 section,
804 return;
806 section,
810 NULL != pos;
812 {
814
817 copy->
lineno = pos->lineno;
818 if (NULL == tail)
819 head = copy;
820 else
822 tail = copy;
823 }
826}
827
828
831 const char *mem,
833 const char *source_filename)
834{
835 size_t line_size;
836 unsigned int nr;
837 size_t r_bytes;
838 size_t to_read;
840 char *section;
841 char *eq;
842 char *tag;
844 char *line_orig = NULL;
845
847 section = NULL;
848 nr = 0;
849 r_bytes = 0;
850 while (r_bytes <
size)
851 {
852 const char *pos;
854 bool emptyline;
855
857
858 to_read =
size - r_bytes;
859 pos = memchr (&mem[r_bytes], '\n', to_read);
860 if (NULL == pos)
861 {
863 line_size = to_read);
864 r_bytes += line_size;
865 }
866 else
867 {
869 line_size = (pos - &mem[r_bytes]));
870 r_bytes += line_size + 1;
871 }
873
874 nr++;
875 if (strlen (line_orig) != line_size)
876 {
878 "NUL byte in line %u\n",
879 nr);
881 break;
882 }
883
885 for (size_t i = 0; i < line_size; i++)
886 {
893 }
894
896 continue;
897
898
899 for (size_t i = line_size - 1;
900 (i >= 1) && (isspace ((
unsigned char)
line[i]));
901 i--)
903
904
905 for (;
line[0] !=
'\0' && (isspace ((
unsigned char)
line[0]));
line++)
906 ;
907 line_size = strlen (
line);
908
909
910 if ( (
'#' ==
line[0]) ||
912 continue;
913
914
916 {
917 char *
end = strchr (
line + 1,
'@');
918 char *directive;
920
922 {
924 "Illegal directive in line %u (parsing restricted section %s)\n",
925 nr,
928 break;
929 }
930
932 {
934 "Bad directive in line %u\n",
935 nr);
937 break;
938 }
940 directive =
line + 1;
941
942 if (0 == strcasecmp (directive,
943 "INLINE"))
944 {
945 const char *path =
end + 1;
946
947
948 for (; isspace (*path); path++)
949 ;
950
952 path,
953 false,
954 NULL,
955 source_filename,
956 nr);
957 }
958 else if (0 == strcasecmp (directive,
959 "INLINE-MATCHING"))
960 {
961 const char *path =
end + 1;
962
963
964 for (; isspace (*path); path++)
965 ;
966
968 path,
969 true,
970 NULL,
971 source_filename,
972 nr);
973 }
974 else if (0 == strcasecmp (directive,
975 "INLINE-SECRET"))
976 {
977 char *secname =
end + 1;
978 char *secname_end;
979 const char *path;
980
981
982 for (; isspace (*secname); secname++)
983 ;
984
985 secname_end = strchr (secname, ' ');
986
987 if (NULL == secname_end)
988 {
990 "Bad inline-secret directive in line %u\n",
991 nr);
993 break;
994 }
995 *secname_end = '\0';
996 path = secname_end + 1;
997
998
999 for (; isspace (*path); path++)
1000 ;
1001
1003 path,
1004 false,
1005 secname,
1006 source_filename,
1007 nr);
1008 }
1009 else
1010 {
1012 "Unknown or malformed directive '%s' in line %u\n",
1013 directive,
1014 nr);
1016 break;
1017 }
1019 {
1020 ret = directive_ret;
1021 break;
1022 }
1023 continue;
1024 }
1025 if ( (
'[' ==
line[0]) &&
1026 (
']' ==
line[line_size - 1]) )
1027 {
1028
1029 line[line_size - 1] =
'\0';
1033 continue;
1034 }
1035 if (NULL != (eq = strchr (
line,
'=')))
1036 {
1037
1038 if (NULL == section)
1039 {
1041 "Syntax error while deserializing in line %u (option without section)\n",
1042 nr);
1044 break;
1045 }
1046
1047
1049
1050 for (int i = strlen (tag) - 1;
1051 (i >= 1) && (isspace ((unsigned char) tag[i]));
1052 i--)
1053 tag[i] = '\0';
1054
1055
1057 while (isspace ((
unsigned char)
value[0]))
1059 for (
int i = strlen (
value) - 1;
1060 (i >= 1) && (isspace ((
unsigned char)
value[i]));
1061 i--)
1063
1064
1065 if ( (
'"' ==
value[0]) &&
1067 {
1070 }
1072 section,
1073 tag,
1076 {
1078 section,
1079 tag,
1081 source_filename
1082 ? source_filename
1083 : "<input>",
1084 nr);
1085 }
1087 continue;
1088 }
1089
1091 "Syntax error while deserializing in line %u\n",
1092 nr);
1094 break;
1095 }
1099 (r_bytes ==
size) );
1101}
1102
1103
1107{
1109 uint64_t fs64;
1111 char *fn;
1112 char *mem;
1113 int dirty;
1115 ssize_t sret;
1116
1119 "Asked to parse config file `%s'\n",
1120 fn);
1121 if (NULL == fn)
1123
1124
1125
1126 {
1130
1131
1132 for (; NULL != cf; parent = cf, cf = cf->
prev)
1133 {
1134
1135 if (cf->level >= lvl)
1136 continue;
1138 if ( (NULL == cf->source_filename) ||
1140 continue;
1141 if (0 == strcmp (cf->source_filename,
1143 {
1144 if (NULL == parent)
1145 {
1147 "Forbidden direct cyclic configuration import (%s -> %s)\n",
1148 cf->source_filename,
1150 }
1151 else
1153 "Forbidden indirect cyclic configuration import (%s -> ... -> %s -> %s)\n",
1154 cf->source_filename,
1159 }
1160 }
1161
1162 }
1163
1164
1165 {
1167
1171 : "<input>");
1174 loaded_file);
1175 }
1176
1180 &fs64,
1183 {
1185 "Error while determining the file size of `%s'\n",
1186 fn);
1189 }
1191 {
1195 }
1199 mem,
1201 if ((sret < 0) || (
fs != (
size_t) sret))
1202 {
1204 "Error while reading file `%s'\n",
1205 fn);
1209 }
1211 {
1215 }
1217 "Deserializing contents of file `%s'\n",
1218 fn);
1220 mem,
1222 fn);
1224 {
1226 _ (
"Failed to parse configuration file `%s'\n"),
1227 fn);
1228 }
1230 {
1232 }
1235
1236
1239}
1240
1241
1244{
1246}
1247
1248
1256static bool
1259{
1260 if (0 != strcasecmp ("PATHS",
1261 sec))
1262 return false;
1263 return ( (0 == strcasecmp ("DATADIR",
1265 (0 == strcasecmp ("LIBDIR",
1267 (0 == strcasecmp ("BINDIR",
1269 (0 == strcasecmp ("PREFIX",
1271 (0 == strcasecmp ("LOCALEDIR",
1273 (0 == strcasecmp ("ICONDIR",
1275 (0 == strcasecmp ("DOCDIR",
1277 (0 == strcasecmp ("DEFAULTCONFIG",
1279 (0 == strcasecmp ("LIBEXECDIR",
1281}
1282
1283
1284char *
1287{
1288 char *mem;
1289 char *cbuf;
1290 char *val;
1291 char *pos;
1292 size_t m_size;
1293 size_t c_size;
1294
1295
1296 m_size = 0;
1298 NULL != sec;
1299 sec = sec->next)
1300 {
1301 if (sec->inaccessible && (NULL == sec->entries))
1302 continue;
1303
1304 m_size += strlen (sec->name) + 3;
1306 NULL != ent;
1307 ent = ent->next)
1308 {
1310 ent->key))
1311 continue;
1312 if (NULL != ent->val)
1313 {
1314
1315 pos = ent->val;
1316 while (NULL != (pos = strstr (pos, "\n")))
1317 {
1318 m_size++;
1319 pos++;
1320 }
1321
1322
1323 m_size += strlen (ent->key) + strlen (ent->val) + 4;
1324 }
1325 }
1326
1327 m_size++;
1328 }
1329
1330
1332 c_size = 0;
1335 NULL != sec;
1336 sec = sec->next)
1337 {
1338 int len;
1339
1340
1341 if (sec->inaccessible && (NULL == sec->entries))
1342 continue;
1344 "[%s]\n",
1345 sec->name);
1348 cbuf,
1349 len);
1350 c_size += len;
1353 NULL != ent;
1354 ent = ent->next)
1355 {
1357 ent->key))
1358 continue;
1359 if (NULL != ent->val)
1360 {
1362 strcpy (val, ent->val);
1363 while (NULL != (pos = strstr (val, "\n")))
1364 {
1365 memmove (&pos[2], &pos[1], strlen (&pos[1]));
1366 pos[0] = '\\';
1367 pos[1] = 'n';
1368 }
1372 c_size += len;
1374 }
1375 }
1377 c_size++;
1378 }
1381 return mem;
1382}
1383
1384
1393static void
1398{
1400 ipk);
1401 const char *ipkname;
1402 switch (ipk)
1403 {
1405 ipkname = "IPK_DATADIR";
1406 break;
1408 ipkname = "IPK_BINDIR";
1409 break;
1411 ipkname = "IPK_LIBDIR";
1412 break;
1414 ipkname = "IPK_PREFIX";
1416 ipkname = "IPK_LOCALEDIR";
1417 break;
1419 ipkname = "IPK_ICONDIR";
1421 ipkname = "IPK_DOCDIR";
1422 break;
1424 ipkname = "IPK_LIBEXECDIR";
1425 break;
1427 ipkname = "IPK_SELF_PREFIX";
1428 break;
1429 default:
1430 ipkname = "??";
1431 break;
1432 }
1434 "# %s = %s\n",
1435 ipkname,
1436 v);
1438}
1439
1440
1448static char *
1451{
1453
1455 "#\n# Configuration file diagnostics\n#\n");
1457 "# Entry point: %s\n",
1459 "<none>");
1461 "#\n# Files Loaded:\n");
1462
1464 NULL != cfil;
1465 cfil = cfil->next)
1466 {
1468 "# ");
1469 for (unsigned int i = 0; i < cfil->level; i++)
1471 "+");
1472 if (0 != cfil->level)
1474 " ");
1475
1477 "%s",
1478 cfil->source_filename);
1479
1480 if (NULL != cfil->hint_restrict_section)
1482 " (%s secret section %s)",
1483 cfil->hint_inaccessible
1484 ? "inaccessible"
1485 : "loaded",
1486 cfil->hint_restrict_section);
1487
1489 "\n");
1490 }
1491
1493 "#\n# Installation paths:\n");
1494
1504
1505
1507 "#\n\n");
1508
1510 NULL != sec;
1511 sec = sec->next)
1512 {
1513 if (sec->hint_secret_filename)
1515 "# secret section from %s\n# secret file stat %s\n",
1516 sec->hint_secret_filename,
1517 sec->hint_secret_stat);
1518 if (sec->hint_inlined_from_filename)
1519 {
1521 "# inlined from %s:%u\n",
1522 sec->hint_inlined_from_filename,
1523 sec->hint_inlined_from_line);
1524 }
1526 "[%s]\n\n",
1527 sec->name);
1528 if (sec->inaccessible && (NULL == sec->entries))
1529 {
1531 "# <section contents inaccessible>\n\n\n");
1532 continue;
1533 }
1535 NULL != ent;
1536 ent = ent->next)
1537 {
1539 ent->key))
1540 continue;
1541 if (NULL != ent->val)
1542 {
1543 char *pos;
1545 strcpy (val, ent->val);
1546 while (NULL != (pos = strstr (val, "\n")))
1547 {
1548 memmove (&pos[2], &pos[1], strlen (&pos[1]));
1549 pos[0] = '\\';
1550 pos[1] = 'n';
1551 }
1552 if (NULL != ent->sources)
1553 {
1555 (NULL != ent->sources->next))
1556 {
1558 &buf,
1559 "# duplicate definitions (highest precedence first):\n");
1563 {
1565
1566 if (
source == ent->sources)
1568 else if (0 == strcmp (
source->value,
1569 ent->val))
1571 else
1572 status =
"different value";
1574 &buf,
1575 "# %s:%u (%s)\n",
1579 }
1580 }
1581 else
1582 {
1584 "# %s:%u\n",
1585 ent->sources->filename,
1586 ent->sources->lineno);
1587 }
1588 }
1590 "%s = %s\n",
1591 ent->key,
1592 val);
1594 }
1596 }
1597 if (sec->inaccessible)
1598 {
1600 "# <additional section contents inaccessible>\n\n\n");
1601 continue;
1602 }
1603
1605 }
1607}
1608
1609
1610char *
1613{
1615 false);
1616}
1617
1618
1619char *
1622{
1624 true);
1625}
1626
1627
1630 char **contents,
1632{
1633 uint64_t fs64;
1635
1638 &fs64,
1643 *
size = (size_t) fs64;
1646 *contents,
1649 {
1651 *contents = NULL;
1653 }
1655}
1656
1657
1665static bool
1668{
1670 char *contents;
1672
1674 &contents,
1676 return false;
1679 &actual);
1682 expected);
1683}
1684
1685
1697 const char *contents,
1700{
1701 char *fn;
1702 char *tfn;
1703
1705 if (fn == NULL)
1708 {
1711 }
1712 {
1713
1714
1715 char *rfn = realpath (fn,
1716 NULL);
1717
1718 if (NULL != rfn)
1719 {
1722 free (rfn);
1723 }
1724 }
1725
1726
1727
1728
1729
1730
1732 "%s.%u.tmp",
1733 fn,
1734 (unsigned int) getpid ());
1735 {
1737
1747 {
1751 }
1752 if (((ssize_t)
size) !=
1754 contents,
1756 {
1758 "write",
1759 tfn);
1761 (void) unlink (tfn);
1765 }
1766
1767
1769 {
1771 "fsync",
1772 tfn);
1774 (void) unlink (tfn);
1778 }
1780 {
1782 "close",
1783 tfn);
1784 (void) unlink (tfn);
1788 }
1789 }
1790 {
1791 struct stat sbuf;
1792
1793
1794
1795 if ( (0 == stat (fn,
1796 &sbuf)) &&
1797 (0 != chmod (tfn,
1798 sbuf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO))) )
1800 "chmod",
1801 tfn);
1802 }
1803 if ( (NULL != expected_hash) &&
1805 expected_hash)) )
1806 {
1808 "Configuration file `%s' changed while it was being cleaned\n",
1809 fn);
1810 (void) unlink (tfn);
1814 }
1815 if (0 != rename (tfn,
1816 fn))
1817 {
1819 "rename",
1820 fn);
1821 (void) unlink (tfn);
1825 }
1829}
1830
1831
1836{
1838 char *cfg_buf;
1840
1844 cfg_buf,
1846 NULL);
1850}
1851
1852
1857{
1861 bool remove;
1862};
1863
1864
1870 unsigned int lines_length,
1872{
1873 for (unsigned int i = 0; i < lines_length; i++)
1875 return &lines[i];
1876 return NULL;
1877}
1878
1879
1883static bool
1885 const char *target,
1887 unsigned int lines_length)
1888{
1890
1891 if (0 != strcmp (
source->filename,
1892 target))
1893 return false;
1895 lines_length,
1897 return (NULL !=
line) &&
line->remove;
1898}
1899
1900
1904static int
1906 const void *b)
1907{
1910
1912 return -1;
1914 return 1;
1915 return 0;
1916}
1917
1918
1924 void *cb_cls,
1925 unsigned int *removed)
1926{
1928 unsigned int lines_length = 0;
1930 char *target;
1931 char *contents = NULL;
1932 char *cleaned = NULL;
1934 size_t cleaned_size = 0;
1936
1937 if (NULL != removed)
1938 *removed = 0;
1943 if (NULL == target)
1945
1947 NULL != cf;
1948 cf = cf->next)
1949 {
1951
1952 if (! cf->have_content_hash)
1953 continue;
1957 target)) )
1958 parsed_file = cf;
1960 }
1961 if (NULL == parsed_file)
1962 {
1964 "Configuration file `%s' was not parsed with diagnostics enabled\n",
1965 target);
1967 }
1969 &contents,
1971 {
1973 "Configuration file `%s' changed since it was parsed\n",
1974 target);
1976 }
1977 {
1979
1982 &actual);
1985 {
1987 "Configuration file `%s' changed since it was parsed\n",
1988 target);
1990 }
1991 }
1992
1993
1994
1996 NULL != sec;
1997 sec = sec->next)
1998 for (
const struct ConfigEntry *ent = sec->entries;
1999 NULL != ent;
2000 ent = ent->next)
2004 {
2005 bool duplicate = false;
2007
2008 if (0 != strcmp (
source->filename,
2009 target))
2010 continue;
2012 NULL != other;
2013 other = other->next)
2014 {
2015 if ( (0 == strcmp (
source->value,
2016 other->value)) &&
2017 ( (
source->lineno != other->lineno) ||
2018 (0 != strcmp (
source->filename,
2019 other->filename)) ) )
2020 {
2021 duplicate = true;
2022 break;
2023 }
2024 }
2025 if ( (! duplicate) ||
2027 lines_length,
2029 continue;
2031 line.option = ent->key;
2035 lines_length,
2037 }
2038
2039
2040
2042 NULL != sec;
2043 sec = sec->next)
2044 for (
const struct ConfigEntry *ent = sec->entries;
2045 NULL != ent;
2046 ent = ent->next)
2047 {
2049
2054 target,
2055 lines,
2056 lines_length))
2057 {
2059 break;
2060 }
2061 if ( (NULL != survivor) &&
2062 (0 == strcmp (survivor->
value,
2063 ent->val)) )
2064 continue;
2068 {
2070
2071 if ( (0 != strcmp (
source->filename,
2072 target)) ||
2073 (0 != strcmp (
source->value,
2074 ent->val)) )
2075 continue;
2077 lines_length,
2079 if ( (NULL !=
line) &&
line->remove)
2080 {
2081 line->remove =
false;
2082 break;
2083 }
2084 }
2085 }
2086
2087 if (lines_length > 1)
2088 qsort (lines,
2089 lines_length,
2090 sizeof (*lines),
2092 {
2093 unsigned int remove_count = 0;
2094
2095 for (unsigned int i = 0; i < lines_length; i++)
2096 if (lines[i].remove)
2097 remove_count++;
2098 if (0 == remove_count)
2099 {
2100 if (NULL != removed)
2101 *removed = 0;
2104 }
2105
2107 for (
size_t offset = 0, line_number = 1; offset <
size; line_number++)
2108 {
2109 size_t end = offset;
2111
2112 while ( (
end <
size) && (
'\n' != contents[
end]) )
2117 lines_length,
2118 (unsigned int) line_number);
2119 if ( (NULL ==
line) || (!
line->remove) )
2120 {
2122 &contents[offset],
2124 cleaned_size +=
end - offset;
2125 }
2127 }
2130 cleaned,
2131 cleaned_size,
2134 if (NULL != removed)
2135 *removed = remove_count;
2136 if (NULL != cb)
2137 for (unsigned int i = 0; i < lines_length; i++)
2138 if (lines[i].remove)
2139 cb (cb_cls,
2144 }
2145
2150 lines_length,
2151 0);
2154}
2155
2156
2157void
2161 void *iter_cls)
2162{
2164 NULL != spos;
2165 spos = spos->next)
2167 NULL != epos;
2168 epos = epos->next)
2169 if (NULL != epos->val)
2170 iter (iter_cls,
2171 spos->name,
2172 epos->key,
2173 epos->val);
2174}
2175
2176
2177void
2182 void *iter_cls)
2183{
2185
2187 while ((spos != NULL) && (0 != strcasecmp (spos->
name, section)))
2189 if (NULL == spos)
2190 return;
2192 NULL != epos;
2193 epos = epos->next)
2194 if (NULL != epos->val)
2195 iter (iter_cls,
2197 epos->key,
2198 epos->val);
2200 {
2202 "Section '%s' is marked as inaccessible, because a configuration "
2203 "file that contains the section can't be read.\n",
2204 section);
2205 return;
2206 }
2207}
2208
2209
2210void
2214 void *iter_cls)
2215{
2218
2220 while (NULL !=
next)
2221 {
2225 continue;
2226 iter (iter_cls,
2228 }
2229}
2230
2231
2232void
2234 const char *section)
2235{
2239
2240 prev = NULL;
2242 while (NULL != spos)
2243 {
2244 if (0 == strcasecmp (section,
2246 {
2247 if (NULL == prev)
2249 else
2251 while (NULL != (ent = spos->
entries))
2252 {
2254
2259 {
2264 }
2267 }
2273 return;
2274 }
2275 prev = spos;
2277 }
2278}
2279
2280
2290static void
2292 const char *section,
2293 const char *option,
2295{
2297
2299 section,
2300 option,
2302}
2303
2304
2308{
2310
2316}
2317
2318
2329static void
2331 const char *section,
2332 const char *option,
2334{
2337
2339 if ((NULL != entNew) && (NULL != entNew->
val) &&
2340 (0 == strcmp (entNew->
val,
value)))
2341 return;
2343 section,
2344 option,
2346}
2347
2348
2353{
2355
2361 &diffHandle);
2362 return diffHandle.cfgDiff;
2363}
2364
2365
2371{
2374
2379}
2380
2381
2382void
2385 const char *section,
2386 const char *option,
2388{
2391 char *nv;
2392
2394 if (NULL != e)
2395 {
2397 {
2400 }
2401 else
2402 {
2406 }
2407 return;
2408 }
2410 if (sec == NULL)
2411 {
2416 }
2422}
2423
2424
2425void
2427 const char *section,
2428 const char *option,
2429 unsigned long long number)
2430{
2431 char s[64];
2432
2434 64,
2435 "%llu",
2438 section,
2439 option,
2440 s);
2441}
2442
2443
2447 const char *section,
2448 const char *option,
2449 unsigned long long *
number)
2450{
2453
2455 section,
2456 option)))
2460 if (1 != sscanf (e->
val,
2461 "%llu%1s",
2466}
2467
2468
2469void
2471 const char *section,
2472 const char *option,
2474{
2475 char s[64];
2476
2477
2478 const locale_t cl = newlocale (LC_NUMERIC_MASK,
2479 "C",
2480 (locale_t) 0);
2481 locale_t old_locale;
2482
2484 old_locale = uselocale (cl);
2486 64,
2487 "%f",
2489 uselocale (old_locale);
2490 freelocale (cl);
2492 section,
2493 option,
2494 s);
2495}
2496
2497
2501 const char *section,
2502 const char *option,
2504{
2507
2509 section,
2510 option)))
2514
2515 {
2516 const locale_t cl = newlocale (LC_NUMERIC_MASK,
2517 "C",
2518 (locale_t) 0);
2519 locale_t old_locale;
2520 int n;
2521
2523 old_locale = uselocale (cl);
2525 "%f%1s",
2528 uselocale (old_locale);
2529 freelocale (cl);
2530 if (1 != n)
2532 }
2534}
2535
2536
2540 const char *section,
2541 const char *option,
2543{
2546
2548 section,
2549 option)))
2554 time);
2557 section,
2558 option,
2559 _ (
"Not a valid relative time specification"));
2561}
2562
2563
2567 const char *section,
2568 const char *option,
2569 unsigned long long *
size)
2570{
2572
2574 section,
2575 option)))
2581}
2582
2583
2597 const char *section,
2598 const char *option,
2600{
2602
2604 section,
2605 option))) ||
2607 {
2610 }
2613}
2614
2615
2619 const char *section,
2620 const char *option,
2621 const char *const *choices,
2623{
2625 unsigned int i;
2626
2628 section,
2629 option)))
2631 for (i = 0; NULL !=
choices[i]; i++)
2632 if (0 == strcasecmp (choices[i], e->
val))
2633 break;
2634 if (NULL == choices[i])
2635 {
2637 _ (
"Configuration value '%s' for '%s'"
2638 " in section '%s' is not in set of legal choices\n"),
2640 option,
2641 section);
2643 }
2646}
2647
2648
2651 const char *section,
2652 const char *option,
2653 void *buf,
2654 size_t buf_size)
2655{
2659
2663 section,
2664 option,
2669 {
2672 }
2676 buf,
2677 buf_size))
2678 {
2681 }
2684}
2685
2686
2689 const char *section,
2690 const char *option)
2691{
2693
2695 section,
2696 option))) ||
2700}
2701
2702
2708{
2713
2718};
2719
2720
2721static char *
2723 char *orig,
2725
2726
2747static char *
2749 char *orig,
2750 unsigned int depth,
2752 size_t *skip)
2753{
2757 const char *post;
2759 char *def;
2761 unsigned int lopen;
2762 char erased_char;
2763 char *erased_pos;
2764 size_t len;
2765 size_t def_skip;
2766 bool recursive = false;
2768
2769 *skip = 1;
2770 if (NULL == orig)
2771 return NULL;
2772 if (depth > 128)
2773 {
2775 "Recursive expansion suspected, aborting $-expansion for term `%s'\n",
2776 orig);
2777 return orig;
2778 }
2780 "Asked to $-expand %s\n",
2781 orig);
2782 if ('$' != orig[0])
2783 {
2785 "Doesn't start with $ - not expanding\n");
2786 return orig;
2787 }
2788 erased_char = 0;
2789 erased_pos = NULL;
2790 if ('{' == orig[1])
2791 {
2793 lopen = 1;
2795 while (lopen > 0)
2796 {
2799 {
2800 case '}':
2801 lopen--;
2802 break;
2803
2804 case '{':
2805 lopen++;
2806 break;
2807
2808 case '\0':
2810 "Missing closing `}' in option `%s'\n",
2811 orig);
2812 return orig;
2813
2814 default:
2815 break;
2816 }
2817 }
2822 def = strchr (orig, ':');
2823 if (NULL != def)
2824 {
2825 *def = '\0';
2826 def++;
2827 if (('-' == *def) || ('=' == *def))
2828 def++;
2830 }
2831 }
2832 else
2833 {
2834 int i;
2835
2837 def = NULL;
2838 i = 0;
2839 while ( (orig[i] != '/') &&
2840 (orig[i] != '\\') &&
2841 (orig[i] != '\0') &&
2842 (orig[i] != ' ') )
2843 i++;
2844 if (orig[i] == '\0')
2845 {
2846 post = "";
2847 }
2848 else
2849 {
2850 erased_char = orig[i];
2851 erased_pos = &orig[i];
2852 orig[i] = '\0';
2853 post = &orig[i + 1];
2854 }
2855 }
2857 "Split into `%s' and `%s' with default %s\n",
2859 post,
2860 def);
2862 NULL != pos;
2864 {
2865 if (0 == strcmp (pos->name,
2867 {
2869 "The definition of `%s' refers to itself, not expanding it\n",
2871 recursive = true;
2872 break;
2873 }
2874 }
2875 if (recursive ||
2878 "PATHS",
2881 {
2882 if (recursive ||
2884 {
2885
2887 def,
2888 depth + 1,
2889 frame,
2890 &def_skip);
2892 }
2894 {
2896 if (erased_pos)
2897 *erased_pos = erased_char;
2899 "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n",
2901 orig);
2903 return orig;
2904 }
2906 }
2907 inner.parent = frame;
2911 &inner);
2912 if ((erased_pos) && ('}' != erased_char))
2913 {
2914 len = strlen (
prefix) + 1;
2916 prefix[len - 1] = erased_char;
2918 }
2927}
2928
2929
2938static char *
2940 char *orig,
2942{
2943 char *dup;
2944 size_t i;
2945 size_t len;
2946 size_t skip;
2947
2948 i = 0;
2949 while ('\0' != orig[i])
2950 {
2951 if ('$' != orig[i])
2952 {
2953 i++;
2954 continue;
2955 }
2959 len = strlen (dup) + 1;
2963
2964
2965 i += skip;
2966 }
2967 return orig;
2968}
2969
2970
2971char *
2974 char *orig)
2975{
2977 orig,
2978 NULL);
2979}
2980
2981
2985 const char *section,
2986 const char *option,
2988{
2989 char *tmp;
2991
2993 section,
2994 option,
2995 &tmp);
2997 {
2999 "Failed to retrieve filename\n");
3002 }
3004 tmp);
3010}
3011
3012
3016 const char *section,
3017 const char *option)
3018{
3019 static const char *yesno[] = {
3020 "YES",
3021 "NO",
3022 NULL
3023 };
3024 const char *val;
3026
3029 section,
3030 option,
3031 yesno,
3032 &val);
3035 if (val == yesno[0])
3038}
3039
3040
3041int
3044 const char *section,
3045 const char *option,
3047 void *cb_cls)
3048{
3050 char *pos;
3052 char old;
3054
3057 section,
3058 option,
3060 return 0;
3064 while (1)
3065 {
3066 while (pos[0] == ' ')
3067 pos++;
3068 if (strlen (pos) == 0)
3069 break;
3071 while ((
end[0] !=
' ') && (
end[0] !=
'\0'))
3072 {
3074 {
3076 {
3077 case '\\':
3078 case ' ':
3079 memmove (
end, &
end[1], strlen (&
end[1]) + 1);
3080
3081 case '\0':
3082
3083 break;
3084
3085 default:
3086
3087 break;
3088 }
3089 }
3091 }
3094 if (strlen (pos) > 0)
3095 {
3097 if ( (NULL != cb) &&
3099 pos)))
3100 {
3102 break;
3103 }
3104 }
3105 if (old == '\0')
3106 break;
3108 }
3111}
3112
3113
3120static char *
3122{
3123 char *escaped;
3124 const char *rpos;
3125 char *wpos;
3126
3128 memset (escaped, 0, strlen (
value) * 2 + 1);
3130 wpos = escaped;
3131 while (rpos[0] != '\0')
3132 {
3133 switch (rpos[0])
3134 {
3135 case '\\':
3136 case ' ':
3137 wpos[0] = '\\';
3138 wpos[1] = rpos[0];
3139 wpos += 2;
3140 break;
3141
3142 default:
3143 wpos[0] = rpos[0];
3144 wpos++;
3145 }
3146 rpos++;
3147 }
3148 return escaped;
3149}
3150
3151
3161 const char *fn)
3162{
3163 const char *of = cls;
3164
3165 return (0 == strcmp (of, fn))
3168}
3169
3170
3174 const char *section,
3175 const char *option,
3177{
3178 char *escaped;
3179 char *old;
3180 char *nw;
3181
3184 section,
3185 option,
3194 strcpy (nw, old);
3195 if (strlen (old) > 0)
3196 strcat (nw, " ");
3197 strcat (nw, escaped);
3199 section,
3200 option,
3201 nw);
3206}
3207
3208
3212 const char *section,
3213 const char *option,
3215{
3217 char *pos;
3219 char *match;
3220 char old;
3221
3224 section,
3225 option,
3230 while (1)
3231 {
3232 while (pos[0] == ' ')
3233 pos++;
3234 if (strlen (pos) == 0)
3235 break;
3237 while ((
end[0] !=
' ') && (
end[0] !=
'\0'))
3238 {
3240 {
3242 {
3243 case '\\':
3244 case ' ':
3246 break;
3247
3248 case '\0':
3249
3250 break;
3251
3252 default:
3253
3254 break;
3255 }
3256 }
3258 }
3261 if (0 == strcmp (pos, match))
3262 {
3263 if (old != '\0')
3264 memmove (pos,
3266 strlen (&
end[1]) + 1);
3267 else
3268 {
3270 pos[-1] = '\0';
3271 else
3272 pos[0] = '\0';
3273 }
3275 section,
3276 option,
3281 }
3282 if (old == '\0')
3283 break;
3286 }
3290}
3291
3292
3296 const char *defaults_d)
3297{
3300 .files_length = 0,
3301 };
3303
3307 &files_context))
3309 qsort (files_context.
files,
3311 sizeof (char *),
3313 for (
unsigned int i = 0; i < files_context.
files_length; i++)
3314 {
3315 const char *ext;
3317
3318
3320 if ( (NULL == ext) ||
3321 (0 != strcmp (ext,
3322 ".conf")) )
3323 {
3325 "Skipping file `%s'\n",
3328 continue;
3329 }
3333 break;
3334 }
3336 {
3337 for (
size_t i = 0; i < files_context.
files_length; i++)
3341 0);
3342 }
3343 return fun_ret;
3344}
3345
3346
3347char *
3350{
3351 char *cfg_fn;
3352 const char *xdg =
getenv (
"XDG_CONFIG_HOME");
3353
3354 if (NULL != xdg)
3356 "%s%s%s",
3357 xdg,
3360 else
3362
3364 return cfg_fn;
3366
3367
3368
3369
3371 "/etc/%s",
3375 return cfg_fn;
3377
3379 "/etc/%s/%s",
3384 return cfg_fn;
3385
3387 return NULL;
3388}
3389
3390
3395{
3396 char *baseconfig;
3397 const char *base_config_varname;
3398
3400 {
3401
3404 }
3407 {
3410 }
3411
3413
3414 if ((NULL != base_config_varname)
3415 && (NULL != (baseconfig =
getenv (base_config_varname))))
3416 {
3418 }
3419 else
3420 {
3421 char *ipath;
3422
3425 if (NULL == ipath)
3426 {
3429 }
3431 "%s%s",
3432 ipath,
3433 "config.d");
3435 }
3436
3437 {
3439
3441
3447 dname)))
3448 {
3450 "Failed to load base configuration from '%s'\n",
3454 }
3456 }
3461 {
3462
3464 "Failed to load configuration from file '%s'\n",
3467 }
3470 "PATHS",
3471 "DEFAULTCONFIG"))) &&
3474 "PATHS",
3475 "DEFAULTCONFIG",
3478}
3479
3480
3489static void
3491 const char *section,
3492 const char *option,
3494{
3496
3497 char *value_fn;
3498 char *fn;
3499
3502 section,
3503 option,
3504 &value_fn));
3506 if (NULL == fn)
3507 fn = value_fn;
3508 else
3510 fprintf (stdout,
3511 "%s = %s\n",
3512 option,
3513 fn);
3515}
3516
3517
3526static void
3528 const char *section,
3529 const char *option,
3531{
3532 (void) cls;
3533 (void) section;
3534
3535 fprintf (stdout,
3536 "%s = %s\n",
3537 option,
3539}
3540
3541
3548static void
3550 const char *section)
3551{
3552 (void) cls;
3553 fprintf (stdout,
3554 "%s\n",
3555 section);
3556}
3557
3558
3559void
3561 void *cls,
3562 char *const *args,
3563 const char *cfgfile,
3565{
3569
3570 (void) args;
3573 {
3574
3579 cfgfile))
3580 {
3581 fprintf (stderr,
3582 _ (
"Failed to load config file `%s'"),
3583 cfgfile);
3584 return;
3585 }
3587 }
3588
3592 {
3593 fprintf (stderr,
3594 _ (
"The following sections are available:\n"));
3597 NULL);
3598 return;
3599 }
3602 {
3603 char *serialization;
3604
3606 {
3607 fprintf (stderr,
3608 _ (
"%s, %s or %s argument is required\n"),
3609 "--section",
3610 "--list-sections",
3611 "--diagnostics");
3613 return;
3614 }
3618 fprintf (stdout,
3619 "%s",
3620 serialization);
3622 }
3623 else if ( (NULL != cs->
section) &&
3624 (NULL == cs->
value) )
3625 {
3627 {
3635 }
3636 else
3637 {
3639
3641 {
3647 {
3652 return;
3653 }
3654 }
3655 else
3656 {
3662 {
3667 return;
3668 }
3669 }
3670 fprintf (stdout,
3671 "%s\n",
3674 }
3675 }
3677 {
3679 {
3680 fprintf (stderr,
3681 _ (
"--option argument required to set value\n"));
3683 return;
3684 }
3691 }
3693 {
3694 char *cfg_fn = NULL;
3695
3696 if (NULL == out)
3698
3699 if (NULL == cfgfile)
3700 {
3701 const char *xdg =
getenv (
"XDG_CONFIG_HOME");
3702
3703 if (NULL != xdg)
3705 "%s%s%s",
3706 xdg,
3709 else
3711 cfgfile = cfg_fn;
3712 }
3713
3715 {
3717
3721 NULL))
3722 {
3723 fprintf (stderr,
3724 _ (
"failed to load configuration defaults"));
3729 return;
3730 }
3733 out,
3734 cfgfile))
3737 }
3738 else
3739 {
3742 cfgfile))
3744 }
3746 }
3747 if (NULL != out)
3749 if (NULL != ncfg)
3751}
3752
3753
3754void
3757{
3761}
3762
3763
3767{
3769}
3770
3771
3772char *
3774 pd,
3775 const struct
3777 const char *progname)
3778{
3779 static char *cache;
3780 char *binary = NULL;
3781 char *path = NULL;
3782 size_t path_len;
3783
3787 NULL,
3788 NULL))
3789 {
3791 }
3792 if (NULL != cache)
3793 path = cache;
3794 else
3796 "PATHS",
3797 "SUID_BINARY_PATH",
3798 &path);
3799 if ( (NULL == path) ||
3800 (0 == strlen (path)) )
3801 {
3802 if (NULL != path)
3804 cache = NULL;
3806 progname);
3807 }
3808 path_len = strlen (path);
3810 "%s%s%s",
3811 path,
3814 progname);
3815 cache = path;
3816 return binary;
3817}
3818
3819
3820
struct GNUNET_MQ_Envelope * env
static bool do_skip(const char *sec, const char *key)
Should we skip this configuration entry when serializing?
static void print_filename_option(void *cls, const char *section, const char *option, const char *value)
Print each option in a given section as a filename.
static char * expand_dollar(const struct GNUNET_CONFIGURATION_Handle *cfg, char *orig, unsigned int depth, const struct ExpansionFrame *frame, size_t *skip)
Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" where either in the "PATHS" section or...
static bool source_is_removed(const struct ConfigSource *source, const char *target, struct CleanLine *lines, unsigned int lines_length)
Return whether a source is a target line currently marked for removal.
static struct CleanLine * find_clean_line(struct CleanLine *lines, unsigned int lines_length, unsigned int line)
Find a cleanup record for a physical line.
static int clean_line_cmp(const void *a, const void *b)
Sort cleanup records by source line.
static struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
static enum GNUNET_GenericReturnValue handle_inline(struct GNUNET_CONFIGURATION_Handle *cfg, const char *path_or_glob, bool path_is_glob, const char *restrict_section, const char *source_filename, unsigned int source_lineno)
Handle an inline directive.
static void print_section_name(void *cls, const char *section)
Print out given section name.
static enum GNUNET_GenericReturnValue read_file(const char *filename, char **contents, size_t *size)
static char * escape_name(const char *value)
FIXME.
static void compare_entries(void *cls, const char *section, const char *option, const char *value)
A callback function, compares entries from two configurations (default against a new configuration) a...
static void add_entry_source(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value, const char *filename, unsigned int line)
Record the source of a configuration value.
static char * serialize_diagnostics(const struct GNUNET_CONFIGURATION_Handle *cfg, bool verbose)
Serialize configuration diagnostics.
static enum GNUNET_GenericReturnValue test_match(void *cls, const char *fn)
FIXME.
static char * expand_all(const struct GNUNET_CONFIGURATION_Handle *cfg, char *orig, const struct ExpansionFrame *frame)
$-expand all terms in a string.
static struct ConfigSection * find_section(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Find a section entry from a configuration.
static enum GNUNET_GenericReturnValue write_buffer_atomic(const char *filename, const char *contents, size_t size, const struct GNUNET_HashCode *expected_hash)
Atomically replace a file with the given bytes.
static void copy_entry_with_sources(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const struct ConfigEntry *entry)
Copy an entry parsed through an @inline-secret@ directive, including all diagnostic source informatio...
static int pstrcmp(const void *a, const void *b)
static enum GNUNET_GenericReturnValue collect_files_cb(void *cls, const char *filename)
Function called with a filename.
static bool file_hash_matches(const char *filename, const struct GNUNET_HashCode *expected)
Check that a file still has the expected contents.
static void copy_entry(void *cls, const char *section, const char *option, const char *value)
Copy a configuration value to the given target configuration.
static void print_option(void *cls, const char *section, const char *option, const char *value)
Print each option in a given section.
static void dump_os_ipk(const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_Buffer *buf, enum GNUNET_OS_InstallationPathKind ipk)
Dump an os installation path to a buffer.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static int start
Set if we are to start default services (including ARM).
static int list
Set if we should print a list of currently running services.
static int ret
Final status code.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static int end
Set if we are to shutdown all services (including ARM).
static int prefix
If printing the value of PREFIX has been requested.
static char * line
Desired phone line (string to be converted to a hash).
static unsigned int verbose
Be verbose.
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_FS_Handle * fs
Handle to FS service.
static GstElement * source
Appsrc instance into which we write data for the pipeline.
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 status
The program status; 0 for success.
static int result
Global testing status.
static void cleanup()
Cleanup task.
static struct GNUNET_Process * p
Helper process we started.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_data(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, void *buf, size_t buf_size)
Get Crockford32-encoded fixed-size binary data from a configuration.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(const struct GNUNET_OS_ProjectData *pd)
Create a new configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_is_dirty(const struct GNUNET_CONFIGURATION_Handle *cfg)
Test if there are configuration options that were changed since the last save.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_append_value_filename(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Append a filename to a configuration value that represents a list of filenames.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
void GNUNET_CONFIGURATION_remove_section(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Remove the given section and all options in it.
enum GNUNET_GenericReturnValue(* GNUNET_CONFIGURATION_Callback)(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Signature of a function to be run with a configuration.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
void GNUNET_CONFIGURATION_iterate_sections(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_SectionIterator iter, void *iter_cls)
Iterate over all sections in the configuration.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
char * GNUNET_CONFIGURATION_get_suid_binary_path(const struct GNUNET_OS_ProjectData *pd, const struct GNUNET_CONFIGURATION_Handle *cfg, const char *progname)
Given the name of a helper, service or daemon binary construct the full path to the binary using the ...
void GNUNET_CONFIGURATION_config_settings_free(struct GNUNET_CONFIGURATION_ConfigSettings *cs)
Free resources associated with cs.
void GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over all options in the configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_remove_value_filename(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Remove a filename from a configuration value that represents a list of filenames.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse_and_run(const struct GNUNET_OS_ProjectData *pd, const char *filename, GNUNET_CONFIGURATION_Callback cb, void *cb_cls)
Parse a configuration file filename and run the function cb with the resulting configuration object.
void GNUNET_CONFIGURATION_config_tool_run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main task to run to perform operations typical for gnunet-config as per the configuration settings gi...
void(* GNUNET_CONFIGURATION_SectionIterator)(void *cls, const char *section)
Function to iterate over all configuration sections.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *source_filename)
De-serializes configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_size(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *size)
Get a configuration value that should be a size in bytes.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
char * GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
Serializes the given configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
void GNUNET_CONFIGURATION_set_value_number(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long number)
Set a configuration value that should be a number.
char * GNUNET_CONFIGURATION_default_filename(const struct GNUNET_OS_ProjectData *pd)
Return the filename of the default configuration filename that is used when no explicit configuration...
char * GNUNET_CONFIGURATION_expand_dollar(const struct GNUNET_CONFIGURATION_Handle *cfg, char *orig)
Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" where either in the "PATHS" section or...
void GNUNET_CONFIGURATION_set_value_float(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, float number)
Set a configuration value that should be a float.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_clean_file(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename, GNUNET_CONFIGURATION_CleanCallback cb, void *cb_cls, unsigned int *removed)
Remove redundant option definitions from a parsed configuration file.
const struct GNUNET_OS_ProjectData * GNUNET_CONFIGURATION_get_project_data(const struct GNUNET_CONFIGURATION_Handle *cfg)
Return the project data associated with this configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_get_diff(const struct GNUNET_CONFIGURATION_Handle *cfg_default, const struct GNUNET_CONFIGURATION_Handle *cfg_new)
Compute configuration with only entries that have been changed.
char * GNUNET_CONFIGURATION_serialize_diagnostics_verbose(const struct GNUNET_CONFIGURATION_Handle *cfg)
Serializes the given configuration with verbose diagnostics information, including all source definit...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Parse a configuration file, add all of the options in the file to the configuration environment.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_float(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, float *number)
Get a configuration value that should be a floating point number.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load_from(struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d)
Load default configuration.
int GNUNET_CONFIGURATION_iterate_value_filenames(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, GNUNET_FileNameCallback cb, void *cb_cls)
Iterate over the set of filenames stored in a configuration value.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_choice(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *const *choices, const char **value)
Get a configuration value that should be in a set of predefined strings.
void(* GNUNET_CONFIGURATION_CleanCallback)(void *cls, const char *section, const char *option, unsigned int line)
Function called for each duplicate definition removed by GNUNET_CONFIGURATION_clean_file().
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.
int GNUNET_DISK_glob(const char *glob_pattern, GNUNET_FileNameCallback callback, void *callback_cls)
Find all files matching a glob pattern.
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test_read(const char *fil)
Check that fil corresponds to a filename and the file has read permissions.
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).
enum GNUNET_GenericReturnValue GNUNET_DISK_file_sync(const struct GNUNET_DISK_FileHandle *h)
Write file changes to disk.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
@ 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.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
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.
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.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
void GNUNET_buffer_write_str(struct GNUNET_Buffer *buf, const char *str)
Write a 0-terminated string to a buffer, excluding the 0-terminator.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_OS_installation_get_path(const struct GNUNET_OS_ProjectData *pd, enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
GNUNET_OS_InstallationPathKind
Possible installation paths to request.
char * GNUNET_OS_get_libexec_binary_path(const struct GNUNET_OS_ProjectData *pd, const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
@ GNUNET_OS_IPK_SELF_PREFIX
Return the installation directory of this application, not the one of the overall GNUnet installation...
@ GNUNET_OS_IPK_ICONDIR
Return the prefix of the path with application icons (share/icons/).
@ GNUNET_OS_IPK_DATADIR
Return the directory where data is installed (share/gnunet/)
@ GNUNET_OS_IPK_DOCDIR
Return the prefix of the path with documentation files, including the license (share/doc/gnunet/).
@ GNUNET_OS_IPK_LOCALEDIR
Return the directory where translations are installed (share/locale/)
@ GNUNET_OS_IPK_LIBDIR
Return the directory where libraries are installed.
@ GNUNET_OS_IPK_PREFIX
Return the "PREFIX" directory given to configure.
@ GNUNET_OS_IPK_BINDIR
Return the directory where the program binaries are installed.
@ GNUNET_OS_IPK_LIBEXECDIR
Return the directory where helper binaries are installed (lib/gnunet/libexec/)
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
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.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_path_is_absolute(const char *filename, int can_be_uri, int *r_is_uri, char **r_uri_scheme)
Check whether filename is absolute or not, and if it's an URI.
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.
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.
static unsigned int size
Size of the "table".
One physical assignment line considered for removal.
Closure to collect_files_cb.
char ** files
Collected files from globbing.
unsigned int files_length
Size of the files array.
struct ConfigEntry * next
This is a linked list.
char * key
key for this entry
struct ConfigSource * sources
Source definitions retained for diagnostics.
char * val
current, committed value
char * hint_restrict_section
Was this configuration file parsed via @inline-secret@?
char * source_filename
Source filename.
bool hint_inaccessible
Was this configuration file inaccessible?
bool have_content_hash
Whether content_hash is available.
unsigned int level
Level in the tree of loaded config files.
struct GNUNET_HashCode content_hash
Hash of the file contents seen while parsing.
char * name
name of the section
char * hint_inlined_from_filename
For secret sections: Where was this inlined from?
struct ConfigEntry * entries
entries in the section
bool inaccessible
Is the configuration section marked as inaccessible?
struct ConfigSection * next
This is a linked list.
char * hint_secret_filename
Diagnostics hint for the secret file.
unsigned int hint_inlined_from_line
For secret sections: Where was this inlined from?
char * hint_secret_stat
Extra information regarding permissions of the secret file.
source location of a configuration value
char * value
Value as normalized by the configuration parser.
unsigned int lineno
Line containing the definition.
char * filename
Filename containing the definition.
struct ConfigSource * next
Sources are ordered from highest to lowest precedence.
Used for diffing a configuration object against the default one.
const struct GNUNET_CONFIGURATION_Handle * cfg_default
struct GNUNET_CONFIGURATION_Handle * cfgDiff
A [PATHS] option or environment variable whose value is being $-expanded, used to detect definitions ...
const struct ExpansionFrame * parent
The expansion this one is part of, or NULL.
const char * name
Name of the variable whose value is being expanded.
Dynamically growing buffer.
Closure for GNUNET_CONFIGURATION_config_tool_run() with settings for what should be done with the con...
char * value
Value to set.
int full
Should the generated configuration file contain the whole configuration?
int global_ret
Return value from the operation, to be returned from 'main'.
int list_sections
Whether to show the sections.
int rewrite
Should we write out the configuration file, even if no value was changed?
char * option
Name of the option.
char * section
Name of the section.
int is_filename
Treat option as a filename.
unsigned int diagnostics
Diagnostics verbosity.
struct ConfigFile * loaded_files_tail
Linked list of loaded files.
bool load_called
Was the configuration ever loaded via GNUNET_CONFIGURATION_load?
unsigned int current_nest_level
Current nesting level of file loading.
const struct GNUNET_OS_ProjectData * pd
Project data for this configuration object.
struct ConfigSection * sections
Configuration sections.
struct ConfigFile * loaded_files_head
Linked list of loaded files.
char * main_filename
Name of the entry point configuration file.
enum GNUNET_GenericReturnValue dirty
Modification indication since last save GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on err...
bool diagnostics
Enable diagnostics.
const char * restrict_section
When parsing into this configuration, and this value is non-NULL, only parse sections of the same nam...
Handle used to access files (and pipes).
Project-specific data used to help the OS subsystem find installation paths.
const char * base_config_varname
Name of an environment variable that can be used to override the location from which default configur...
const char * project_dirname
Name of the project that is used in the "libexec" prefix, For example, "gnunet".
const char * user_config_file
Configuration file name to use (if $XDG_CONFIG_HOME is not set).
const char * config_file
Configuration file name (in $XDG_CONFIG_HOME) to use.
Time for relative time used by GNUnet, in microseconds.