GNUnet  0.11.x
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 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  */
25 #include "platform.h"
26 #include "gnunet_crypto_lib.h"
27 #include "gnunet_strings_lib.h"
28 #include "gnunet_os_lib.h"
30 #include "gnunet_disk_lib.h"
31 
32 #define LOG(kind, ...) GNUNET_log_from (kind, "util", __VA_ARGS__)
33 
34 #define LOG_STRERROR_FILE(kind, syscall, filename) \
35  GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
36 
41 {
45  struct ConfigEntry *next;
46 
50  char *key;
51 
55  char *val;
56 };
57 
58 
63 {
68 
73 
77  char *name;
78 };
79 
80 
85 {
90 
96  int dirty;
97 };
98 
99 
105 {
107 
109 };
110 
111 
119 {
121  char *p;
122 
124  /* make certain values from the project data available
125  as PATHS */
127  if (NULL != p)
128  {
130  "PATHS",
131  "DATADIR",
132  p);
133  GNUNET_free (p);
134  }
136  if (NULL != p)
137  {
139  "PATHS",
140  "LIBDIR",
141  p);
142  GNUNET_free (p);
143  }
145  if (NULL != p)
146  {
148  "PATHS",
149  "BINDIR",
150  p);
151  GNUNET_free (p);
152  }
154  if (NULL != p)
155  {
157  "PATHS",
158  "PREFIX",
159  p);
160  GNUNET_free (p);
161  }
163  if (NULL != p)
164  {
166  "PATHS",
167  "LOCALEDIR",
168  p);
169  GNUNET_free (p);
170  }
172  if (NULL != p)
173  {
175  "PATHS",
176  "ICONDIR",
177  p);
178  GNUNET_free (p);
179  }
181  if (NULL != p)
182  {
184  "PATHS",
185  "DOCDIR",
186  p);
187  GNUNET_free (p);
188  }
190  if (NULL != p)
191  {
193  "PATHS",
194  "LIBEXECDIR",
195  p);
196  GNUNET_free (p);
197  }
198  return cfg;
199 }
200 
201 
207 void
209 {
210  struct ConfigSection *sec;
211 
212  while (NULL != (sec = cfg->sections))
214  GNUNET_free (cfg);
215 }
216 
217 
229 int
232  void *cb_cls)
233 {
235  int ret;
236 
238  if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, filename))
239  {
240  GNUNET_break (0);
242  return GNUNET_SYSERR;
243  }
244  ret = cb (cb_cls, cfg);
246  return ret;
247 }
248 
249 
261 int
263  const char *mem,
264  size_t size,
265  const char *basedir)
266 {
267  char *line;
268  char *line_orig;
269  size_t line_size;
270  char *pos;
271  unsigned int nr;
272  size_t r_bytes;
273  size_t to_read;
274  size_t i;
275  int emptyline;
276  int ret;
277  char *section;
278  char *eq;
279  char *tag;
280  char *value;
281 
282  ret = GNUNET_OK;
283  section = GNUNET_strdup ("");
284  nr = 0;
285  r_bytes = 0;
286  line_orig = NULL;
287  while (r_bytes < size)
288  {
289  GNUNET_free (line_orig);
290  /* fgets-like behaviour on buffer */
291  to_read = size - r_bytes;
292  pos = memchr (&mem[r_bytes], '\n', to_read);
293  if (NULL == pos)
294  {
295  line_orig = GNUNET_strndup (&mem[r_bytes], line_size = to_read);
296  r_bytes += line_size;
297  }
298  else
299  {
300  line_orig =
301  GNUNET_strndup (&mem[r_bytes], line_size = (pos - &mem[r_bytes]));
302  r_bytes += line_size + 1;
303  }
304  line = line_orig;
305  /* increment line number */
306  nr++;
307  /* tabs and '\r' are whitespace */
308  emptyline = GNUNET_YES;
309  for (i = 0; i < line_size; i++)
310  {
311  if (line[i] == '\t')
312  line[i] = ' ';
313  if (line[i] == '\r')
314  line[i] = ' ';
315  if (' ' != line[i])
316  emptyline = GNUNET_NO;
317  }
318  /* ignore empty lines */
319  if (GNUNET_YES == emptyline)
320  continue;
321 
322  /* remove tailing whitespace */
323  for (i = line_size - 1; (i >= 1) && (isspace ((unsigned char) line[i]));
324  i--)
325  line[i] = '\0';
326 
327  /* remove leading whitespace */
328  for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++)
329  ;
330 
331  /* ignore comments */
332  if (('#' == line[0]) || ('%' == line[0]))
333  continue;
334 
335  /* handle special "@INLINE@" directive */
336  if (0 == strncasecmp (line, "@INLINE@ ", strlen ("@INLINE@ ")))
337  {
338  /* @INLINE@ value */
339  value = &line[strlen ("@INLINE@ ")];
340  if (NULL != basedir)
341  {
342  char *fn;
343 
344  GNUNET_asprintf (&fn, "%s/%s", basedir, value);
345  if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, fn))
346  {
347  GNUNET_free (fn);
348  ret = GNUNET_SYSERR; /* failed to parse included config */
349  break;
350  }
351  GNUNET_free (fn);
352  }
353  else
354  {
356  "Ignoring parsing @INLINE@ configurations, not allowed!\n");
357  ret = GNUNET_SYSERR;
358  break;
359  }
360  continue;
361  }
362  if (('[' == line[0]) && (']' == line[line_size - 1]))
363  {
364  /* [value] */
365  line[line_size - 1] = '\0';
366  value = &line[1];
367  GNUNET_free (section);
368  section = GNUNET_strdup (value);
369  continue;
370  }
371  if (NULL != (eq = strchr (line, '=')))
372  {
373  /* tag = value */
374  tag = GNUNET_strndup (line, eq - line);
375  /* remove tailing whitespace */
376  for (i = strlen (tag) - 1; (i >= 1) && (isspace ((unsigned char) tag[i]));
377  i--)
378  tag[i] = '\0';
379 
380  /* Strip whitespace */
381  value = eq + 1;
382  while (isspace ((unsigned char) value[0]))
383  value++;
384  for (i = strlen (value) - 1;
385  (i >= 1) && (isspace ((unsigned char) value[i]));
386  i--)
387  value[i] = '\0';
388 
389  /* remove quotes */
390  i = 0;
391  if (('"' == value[0]) && ('"' == value[strlen (value) - 1]))
392  {
393  value[strlen (value) - 1] = '\0';
394  value++;
395  }
396  GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, &value[i]);
397  GNUNET_free (tag);
398  continue;
399  }
400  /* parse error */
402  _ ("Syntax error while deserializing in line %u\n"),
403  nr);
404  ret = GNUNET_SYSERR;
405  break;
406  }
407  GNUNET_free (line_orig);
408  GNUNET_free (section);
409  GNUNET_assert ((GNUNET_OK != ret) || (r_bytes == size));
410  return ret;
411 }
412 
413 
422 int
424  const char *filename)
425 {
426  uint64_t fs64;
427  size_t fs;
428  char *fn;
429  char *mem;
430  char *endsep;
431  int dirty;
432  int ret;
433  ssize_t sret;
434 
435  fn = GNUNET_STRINGS_filename_expand (filename);
436  LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to parse config file `%s'\n", fn);
437  if (NULL == fn)
438  return GNUNET_SYSERR;
439  dirty = cfg->dirty; /* back up value! */
440  if (GNUNET_SYSERR ==
442  {
444  "Error while determining the file size of `%s'\n",
445  fn);
446  GNUNET_free (fn);
447  return GNUNET_SYSERR;
448  }
449  if (fs64 > SIZE_MAX)
450  {
451  GNUNET_break (0); /* File size is more than the heap size */
452  GNUNET_free (fn);
453  return GNUNET_SYSERR;
454  }
455  fs = fs64;
456  mem = GNUNET_malloc (fs);
457  sret = GNUNET_DISK_fn_read (fn, mem, fs);
458  if ((sret < 0) || (fs != (size_t) sret))
459  {
460  LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Error while reading file `%s'\n"), fn);
461  GNUNET_free (fn);
462  GNUNET_free (mem);
463  return GNUNET_SYSERR;
464  }
465  LOG (GNUNET_ERROR_TYPE_DEBUG, "Deserializing contents of file `%s'\n", fn);
466  endsep = strrchr (fn, (int) '/');
467  if (NULL != endsep)
468  *endsep = '\0';
469  ret = GNUNET_CONFIGURATION_deserialize (cfg, mem, fs, fn);
470  GNUNET_free (fn);
471  GNUNET_free (mem);
472  /* restore dirty flag - anything we set in the meantime
473  * came from disk */
474  cfg->dirty = dirty;
475  return ret;
476 }
477 
478 
486 int
488 {
489  return cfg->dirty;
490 }
491 
492 
501 char *
503  size_t *size)
504 {
505  struct ConfigSection *sec;
506  struct ConfigEntry *ent;
507  char *mem;
508  char *cbuf;
509  char *val;
510  char *pos;
511  size_t m_size;
512  size_t c_size;
513 
514  /* Pass1 : calculate the buffer size required */
515  m_size = 0;
516  for (sec = cfg->sections; NULL != sec; sec = sec->next)
517  {
518  /* For each section we need to add 3 charaters: {'[',']','\n'} */
519  m_size += strlen (sec->name) + 3;
520  for (ent = sec->entries; NULL != ent; ent = ent->next)
521  {
522  if (NULL != ent->val)
523  {
524  /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */
525  pos = ent->val;
526  while (NULL != (pos = strstr (pos, "\n")))
527  {
528  m_size++;
529  pos++;
530  }
531  /* For each key = value pair we need to add 4 characters (2
532  spaces and 1 equal-to character and 1 new line) */
533  m_size += strlen (ent->key) + strlen (ent->val) + 4;
534  }
535  }
536  /* A new line after section end */
537  m_size++;
538  }
539 
540  /* Pass2: Allocate memory and write the configuration to it */
541  mem = GNUNET_malloc (m_size);
542  sec = cfg->sections;
543  c_size = 0;
544  *size = c_size;
545  while (NULL != sec)
546  {
547  int len;
548 
549  len = GNUNET_asprintf (&cbuf, "[%s]\n", sec->name);
550  GNUNET_assert (0 < len);
551  GNUNET_memcpy (mem + c_size, cbuf, len);
552  c_size += len;
553  GNUNET_free (cbuf);
554  for (ent = sec->entries; NULL != ent; ent = ent->next)
555  {
556  if (NULL != ent->val)
557  {
558  val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
559  strcpy (val, ent->val);
560  while (NULL != (pos = strstr (val, "\n")))
561  {
562  memmove (&pos[2], &pos[1], strlen (&pos[1]));
563  pos[0] = '\\';
564  pos[1] = 'n';
565  }
566  len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
567  GNUNET_free (val);
568  GNUNET_memcpy (mem + c_size, cbuf, len);
569  c_size += len;
570  GNUNET_free (cbuf);
571  }
572  }
573  GNUNET_memcpy (mem + c_size, "\n", 1);
574  c_size++;
575  sec = sec->next;
576  }
577  GNUNET_assert (c_size == m_size);
578  *size = c_size;
579  return mem;
580 }
581 
582 
590 int
592  const char *filename)
593 {
594  char *fn;
595  char *cfg_buf;
596  size_t size;
597  ssize_t sret;
598 
599  fn = GNUNET_STRINGS_filename_expand (filename);
600  if (fn == NULL)
601  return GNUNET_SYSERR;
603  {
604  GNUNET_free (fn);
605  return GNUNET_SYSERR;
606  }
607  cfg_buf = GNUNET_CONFIGURATION_serialize (cfg, &size);
608  sret = GNUNET_DISK_fn_write (fn,
609  cfg_buf,
610  size,
615  if ((sret < 0) || (size != (size_t) sret))
616  {
617  GNUNET_free (fn);
618  GNUNET_free (cfg_buf);
620  "Writing configuration to file `%s' failed\n",
621  filename);
622  cfg->dirty = GNUNET_SYSERR; /* last write failed */
623  return GNUNET_SYSERR;
624  }
625  GNUNET_free (fn);
626  GNUNET_free (cfg_buf);
627  cfg->dirty = GNUNET_NO; /* last write succeeded */
628  return GNUNET_OK;
629 }
630 
631 
639 void
642  void *iter_cls)
643 {
644  struct ConfigSection *spos;
645  struct ConfigEntry *epos;
646 
647  for (spos = cfg->sections; NULL != spos; spos = spos->next)
648  for (epos = spos->entries; NULL != epos; epos = epos->next)
649  if (NULL != epos->val)
650  iter (iter_cls, spos->name, epos->key, epos->val);
651 }
652 
653 
662 void
664  const struct GNUNET_CONFIGURATION_Handle *cfg,
665  const char *section,
667  void *iter_cls)
668 {
669  struct ConfigSection *spos;
670  struct ConfigEntry *epos;
671 
672  spos = cfg->sections;
673  while ((spos != NULL) && (0 != strcasecmp (spos->name, section)))
674  spos = spos->next;
675  if (NULL == spos)
676  return;
677  for (epos = spos->entries; NULL != epos; epos = epos->next)
678  if (NULL != epos->val)
679  iter (iter_cls, spos->name, epos->key, epos->val);
680 }
681 
682 
690 void
692  const struct GNUNET_CONFIGURATION_Handle *cfg,
694  void *iter_cls)
695 {
696  struct ConfigSection *spos;
697  struct ConfigSection *next;
698 
699  next = cfg->sections;
700  while (next != NULL)
701  {
702  spos = next;
703  next = spos->next;
704  iter (iter_cls, spos->name);
705  }
706 }
707 
708 
715 void
717  const char *section)
718 {
719  struct ConfigSection *spos;
720  struct ConfigSection *prev;
721  struct ConfigEntry *ent;
722 
723  prev = NULL;
724  spos = cfg->sections;
725  while (NULL != spos)
726  {
727  if (0 == strcasecmp (section, spos->name))
728  {
729  if (NULL == prev)
730  cfg->sections = spos->next;
731  else
732  prev->next = spos->next;
733  while (NULL != (ent = spos->entries))
734  {
735  spos->entries = ent->next;
736  GNUNET_free (ent->key);
737  GNUNET_free (ent->val);
738  GNUNET_free (ent);
739  cfg->dirty = GNUNET_YES;
740  }
741  GNUNET_free (spos->name);
742  GNUNET_free (spos);
743  return;
744  }
745  prev = spos;
746  spos = spos->next;
747  }
748 }
749 
750 
760 static void
761 copy_entry (void *cls,
762  const char *section,
763  const char *option,
764  const char *value)
765 {
766  struct GNUNET_CONFIGURATION_Handle *dst = cls;
767 
768  GNUNET_CONFIGURATION_set_value_string (dst, section, option, value);
769 }
770 
771 
780 {
782 
785  return ret;
786 }
787 
788 
796 static struct ConfigSection *
798  const char *section)
799 {
800  struct ConfigSection *pos;
801 
802  pos = cfg->sections;
803  while ((pos != NULL) && (0 != strcasecmp (section, pos->name)))
804  pos = pos->next;
805  return pos;
806 }
807 
808 
817 static struct ConfigEntry *
819  const char *section,
820  const char *key)
821 {
822  struct ConfigSection *sec;
823  struct ConfigEntry *pos;
824 
825  if (NULL == (sec = find_section (cfg, section)))
826  return NULL;
827  pos = sec->entries;
828  while ((pos != NULL) && (0 != strcasecmp (key, pos->key)))
829  pos = pos->next;
830  return pos;
831 }
832 
833 
844 static void
845 compare_entries (void *cls,
846  const char *section,
847  const char *option,
848  const char *value)
849 {
850  struct DiffHandle *dh = cls;
851  struct ConfigEntry *entNew;
852 
853  entNew = find_entry (dh->cfg_default, section, option);
854  if ((NULL != entNew) && (NULL != entNew->val) &&
855  (0 == strcmp (entNew->val, value)))
856  return;
857  GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff, section, option, value);
858 }
859 
860 
870  const struct GNUNET_CONFIGURATION_Handle *cfg_default,
871  const struct GNUNET_CONFIGURATION_Handle *cfg_new)
872 {
873  struct DiffHandle diffHandle;
874 
875  diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
876  diffHandle.cfg_default = cfg_default;
877  GNUNET_CONFIGURATION_iterate (cfg_new, &compare_entries, &diffHandle);
878  return diffHandle.cfgDiff;
879 }
880 
881 
890 int
893  const struct GNUNET_CONFIGURATION_Handle *cfg_new,
894  const char *filename)
895 {
896  int ret;
897  struct GNUNET_CONFIGURATION_Handle *diff;
898 
899  diff = GNUNET_CONFIGURATION_get_diff (cfg_default, cfg_new);
900  ret = GNUNET_CONFIGURATION_write (diff, filename);
902  return ret;
903 }
904 
905 
914 void
916  const char *section,
917  const char *option,
918  const char *value)
919 {
920  struct ConfigSection *sec;
921  struct ConfigEntry *e;
922  char *nv;
923 
924  e = find_entry (cfg, section, option);
925  if (NULL != e)
926  {
927  if (NULL == value)
928  {
929  GNUNET_free (e->val);
930  e->val = NULL;
931  }
932  else
933  {
934  nv = GNUNET_strdup (value);
935  GNUNET_free (e->val);
936  e->val = nv;
937  }
938  return;
939  }
940  sec = find_section (cfg, section);
941  if (sec == NULL)
942  {
943  sec = GNUNET_new (struct ConfigSection);
944  sec->name = GNUNET_strdup (section);
945  sec->next = cfg->sections;
946  cfg->sections = sec;
947  }
948  e = GNUNET_new (struct ConfigEntry);
949  e->key = GNUNET_strdup (option);
950  e->val = GNUNET_strdup (value);
951  e->next = sec->entries;
952  sec->entries = e;
953 }
954 
955 
964 void
966  const char *section,
967  const char *option,
968  unsigned long long number)
969 {
970  char s[64];
971 
972  GNUNET_snprintf (s, 64, "%llu", number);
973  GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s);
974 }
975 
976 
986 int
988  const struct GNUNET_CONFIGURATION_Handle *cfg,
989  const char *section,
990  const char *option,
991  unsigned long long *number)
992 {
993  struct ConfigEntry *e;
994  char dummy[2];
995 
996  if (NULL == (e = find_entry (cfg, section, option)))
997  return GNUNET_SYSERR;
998  if (NULL == e->val)
999  return GNUNET_SYSERR;
1000  if (1 != sscanf (e->val, "%llu%1s", number, dummy))
1001  return GNUNET_SYSERR;
1002  return GNUNET_OK;
1003 }
1004 
1005 
1015 int
1017  const struct GNUNET_CONFIGURATION_Handle *cfg,
1018  const char *section,
1019  const char *option,
1020  float *number)
1021 {
1022  struct ConfigEntry *e;
1023  char dummy[2];
1024 
1025  if (NULL == (e = find_entry (cfg, section, option)))
1026  return GNUNET_SYSERR;
1027  if (NULL == e->val)
1028  return GNUNET_SYSERR;
1029  if (1 != sscanf (e->val, "%f%1s", number, dummy))
1030  return GNUNET_SYSERR;
1031  return GNUNET_OK;
1032 }
1033 
1034 
1044 int
1046  const struct GNUNET_CONFIGURATION_Handle *cfg,
1047  const char *section,
1048  const char *option,
1049  struct GNUNET_TIME_Relative *time)
1050 {
1051  struct ConfigEntry *e;
1052  int ret;
1053 
1054  if (NULL == (e = find_entry (cfg, section, option)))
1055  return GNUNET_SYSERR;
1056  if (NULL == e->val)
1057  return GNUNET_SYSERR;
1058  ret = GNUNET_STRINGS_fancy_time_to_relative (e->val, time);
1059  if (GNUNET_OK != ret)
1061  section,
1062  option,
1063  _ ("Not a valid relative time specification"));
1064  return ret;
1065 }
1066 
1067 
1077 int
1079  const struct GNUNET_CONFIGURATION_Handle *cfg,
1080  const char *section,
1081  const char *option,
1082  unsigned long long *size)
1083 {
1084  struct ConfigEntry *e;
1085 
1086  if (NULL == (e = find_entry (cfg, section, option)))
1087  return GNUNET_SYSERR;
1088  if (NULL == e->val)
1089  return GNUNET_SYSERR;
1090  return GNUNET_STRINGS_fancy_size_to_bytes (e->val, size);
1091 }
1092 
1093 
1104 int
1106  const struct GNUNET_CONFIGURATION_Handle *cfg,
1107  const char *section,
1108  const char *option,
1109  char **value)
1110 {
1111  struct ConfigEntry *e;
1112 
1113  if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1114  {
1115  *value = NULL;
1116  return GNUNET_SYSERR;
1117  }
1118  *value = GNUNET_strdup (e->val);
1119  return GNUNET_OK;
1120 }
1121 
1122 
1135 int
1137  const struct GNUNET_CONFIGURATION_Handle *cfg,
1138  const char *section,
1139  const char *option,
1140  const char *const *choices,
1141  const char **value)
1142 {
1143  struct ConfigEntry *e;
1144  unsigned int i;
1145 
1146  if (NULL == (e = find_entry (cfg, section, option)))
1147  return GNUNET_SYSERR;
1148  for (i = 0; NULL != choices[i]; i++)
1149  if (0 == strcasecmp (choices[i], e->val))
1150  break;
1151  if (NULL == choices[i])
1152  {
1154  _ ("Configuration value '%s' for '%s'"
1155  " in section '%s' is not in set of legal choices\n"),
1156  e->val,
1157  option,
1158  section);
1159  return GNUNET_SYSERR;
1160  }
1161  *value = choices[i];
1162  return GNUNET_OK;
1163 }
1164 
1165 
1178 int
1180  const char *section,
1181  const char *option,
1182  void *buf,
1183  size_t buf_size)
1184 {
1185  char *enc;
1186  int res;
1187  size_t data_size;
1188 
1189  if (GNUNET_OK !=
1190  (res =
1191  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &enc)))
1192  return res;
1193  data_size = (strlen (enc) * 5) / 8;
1194  if (data_size != buf_size)
1195  {
1196  GNUNET_free (enc);
1197  return GNUNET_SYSERR;
1198  }
1199  if (GNUNET_OK !=
1200  GNUNET_STRINGS_string_to_data (enc, strlen (enc), buf, buf_size))
1201  {
1202  GNUNET_free (enc);
1203  return GNUNET_SYSERR;
1204  }
1205  GNUNET_free (enc);
1206  return GNUNET_OK;
1207 }
1208 
1209 
1218 int
1220  const char *section,
1221  const char *option)
1222 {
1223  struct ConfigEntry *e;
1224 
1225  if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1226  return GNUNET_NO;
1227  return GNUNET_YES;
1228 }
1229 
1230 
1246 static char *
1248  char *orig,
1249  unsigned int depth)
1250 {
1251  char *prefix;
1252  char *result;
1253  char *start;
1254  const char *post;
1255  const char *env;
1256  char *def;
1257  char *end;
1258  unsigned int lopen;
1259  char erased_char;
1260  char *erased_pos;
1261  size_t len;
1262 
1263  if (NULL == orig)
1264  return NULL;
1265  if (depth > 128)
1266  {
1268  _ (
1269  "Recursive expansion suspected, aborting $-expansion for term `%s'\n"),
1270  orig);
1271  return orig;
1272  }
1273  LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to $-expand %s\n", orig);
1274  if ('$' != orig[0])
1275  {
1276  LOG (GNUNET_ERROR_TYPE_DEBUG, "Doesn't start with $ - not expanding\n");
1277  return orig;
1278  }
1279  erased_char = 0;
1280  erased_pos = NULL;
1281  if ('{' == orig[1])
1282  {
1283  start = &orig[2];
1284  lopen = 1;
1285  end = &orig[1];
1286  while (lopen > 0)
1287  {
1288  end++;
1289  switch (*end)
1290  {
1291  case '}':
1292  lopen--;
1293  break;
1294 
1295  case '{':
1296  lopen++;
1297  break;
1298 
1299  case '\0':
1301  _ ("Missing closing `%s' in option `%s'\n"),
1302  "}",
1303  orig);
1304  return orig;
1305 
1306  default:
1307  break;
1308  }
1309  }
1310  erased_char = *end;
1311  erased_pos = end;
1312  *end = '\0';
1313  post = end + 1;
1314  def = strchr (orig, ':');
1315  if (NULL != def)
1316  {
1317  *def = '\0';
1318  def++;
1319  if (('-' == *def) || ('=' == *def))
1320  def++;
1321  def = GNUNET_strdup (def);
1322  }
1323  }
1324  else
1325  {
1326  int i;
1327 
1328  start = &orig[1];
1329  def = NULL;
1330  i = 0;
1331  while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0') &&
1332  (orig[i] != ' '))
1333  i++;
1334  if (orig[i] == '\0')
1335  {
1336  post = "";
1337  }
1338  else
1339  {
1340  erased_char = orig[i];
1341  erased_pos = &orig[i];
1342  orig[i] = '\0';
1343  post = &orig[i + 1];
1344  }
1345  }
1347  "Split into `%s' and `%s' with default %s\n",
1348  start,
1349  post,
1350  def);
1351  if (GNUNET_OK !=
1352  GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", start, &prefix))
1353  {
1354  if (NULL == (env = getenv (start)))
1355  {
1356  /* try default */
1357  def = expand_dollar (cfg, def, depth + 1);
1358  env = def;
1359  }
1360  if (NULL == env)
1361  {
1362  start = GNUNET_strdup (start);
1363  if (erased_pos)
1364  *erased_pos = erased_char;
1366  _ (
1367  "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n"),
1368  start,
1369  orig);
1370  GNUNET_free (start);
1371  return orig;
1372  }
1373  prefix = GNUNET_strdup (env);
1374  }
1375  prefix = GNUNET_CONFIGURATION_expand_dollar (cfg, prefix);
1376  if ((erased_pos) && ('}' != erased_char))
1377  {
1378  len = strlen (prefix) + 1;
1379  prefix = GNUNET_realloc (prefix, len + 1);
1380  prefix[len - 1] = erased_char;
1381  prefix[len] = '\0';
1382  }
1383  result = GNUNET_malloc (strlen (prefix) + strlen (post) + 1);
1384  strcpy (result, prefix);
1385  strcat (result, post);
1386  GNUNET_free (def);
1387  GNUNET_free (prefix);
1388  GNUNET_free (orig);
1389  return result;
1390 }
1391 
1392 
1409 char *
1411  const struct GNUNET_CONFIGURATION_Handle *cfg,
1412  char *orig)
1413 {
1414  char *dup;
1415  size_t i;
1416  size_t len;
1417 
1418  for (i = 0; '\0' != orig[i]; i++)
1419  {
1420  if ('$' != orig[i])
1421  continue;
1422  dup = GNUNET_strdup (orig + i);
1423  dup = expand_dollar (cfg, dup, 0);
1424  GNUNET_assert (NULL != dup); /* make compiler happy */
1425  len = strlen (dup) + 1;
1426  orig = GNUNET_realloc (orig, i + len);
1427  GNUNET_memcpy (orig + i, dup, len);
1428  GNUNET_free (dup);
1429  }
1430  return orig;
1431 }
1432 
1433 
1444 int
1446  const struct GNUNET_CONFIGURATION_Handle *cfg,
1447  const char *section,
1448  const char *option,
1449  char **value)
1450 {
1451  char *tmp;
1452 
1453  if (GNUNET_OK !=
1454  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp))
1455  {
1456  LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to retrieve filename\n");
1457  *value = NULL;
1458  return GNUNET_SYSERR;
1459  }
1460  tmp = GNUNET_CONFIGURATION_expand_dollar (cfg, tmp);
1461  *value = GNUNET_STRINGS_filename_expand (tmp);
1462  GNUNET_free (tmp);
1463  if (*value == NULL)
1464  return GNUNET_SYSERR;
1465  return GNUNET_OK;
1466 }
1467 
1468 
1478 int
1480  const struct GNUNET_CONFIGURATION_Handle *cfg,
1481  const char *section,
1482  const char *option)
1483 {
1484  static const char *yesno[] = { "YES", "NO", NULL };
1485  const char *val;
1486  int ret;
1487 
1488  ret =
1489  GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
1490  if (ret == GNUNET_SYSERR)
1491  return ret;
1492  if (val == yesno[0])
1493  return GNUNET_YES;
1494  return GNUNET_NO;
1495 }
1496 
1497 
1508 int
1510  const struct GNUNET_CONFIGURATION_Handle *cfg,
1511  const char *section,
1512  const char *option,
1514  void *cb_cls)
1515 {
1516  char *list;
1517  char *pos;
1518  char *end;
1519  char old;
1520  int ret;
1521 
1522  if (GNUNET_OK !=
1523  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list))
1524  return 0;
1525  GNUNET_assert (list != NULL);
1526  ret = 0;
1527  pos = list;
1528  while (1)
1529  {
1530  while (pos[0] == ' ')
1531  pos++;
1532  if (strlen (pos) == 0)
1533  break;
1534  end = pos + 1;
1535  while ((end[0] != ' ') && (end[0] != '\0'))
1536  {
1537  if (end[0] == '\\')
1538  {
1539  switch (end[1])
1540  {
1541  case '\\':
1542  case ' ':
1543  memmove (end, &end[1], strlen (&end[1]) + 1);
1544 
1545  case '\0':
1546  /* illegal, but just keep it */
1547  break;
1548 
1549  default:
1550  /* illegal, but just ignore that there was a '/' */
1551  break;
1552  }
1553  }
1554  end++;
1555  }
1556  old = end[0];
1557  end[0] = '\0';
1558  if (strlen (pos) > 0)
1559  {
1560  ret++;
1561  if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos)))
1562  {
1563  ret = GNUNET_SYSERR;
1564  break;
1565  }
1566  }
1567  if (old == '\0')
1568  break;
1569  pos = end + 1;
1570  }
1571  GNUNET_free (list);
1572  return ret;
1573 }
1574 
1575 
1582 static char *
1583 escape_name (const char *value)
1584 {
1585  char *escaped;
1586  const char *rpos;
1587  char *wpos;
1588 
1589  escaped = GNUNET_malloc (strlen (value) * 2 + 1);
1590  memset (escaped, 0, strlen (value) * 2 + 1);
1591  rpos = value;
1592  wpos = escaped;
1593  while (rpos[0] != '\0')
1594  {
1595  switch (rpos[0])
1596  {
1597  case '\\':
1598  case ' ':
1599  wpos[0] = '\\';
1600  wpos[1] = rpos[0];
1601  wpos += 2;
1602  break;
1603 
1604  default:
1605  wpos[0] = rpos[0];
1606  wpos++;
1607  }
1608  rpos++;
1609  }
1610  return escaped;
1611 }
1612 
1613 
1621 static int
1622 test_match (void *cls, const char *fn)
1623 {
1624  const char *of = cls;
1625 
1626  return (0 == strcmp (of, fn)) ? GNUNET_SYSERR : GNUNET_OK;
1627 }
1628 
1629 
1642 int
1645  const char *section,
1646  const char *option,
1647  const char *value)
1648 {
1649  char *escaped;
1650  char *old;
1651  char *nw;
1652 
1653  if (GNUNET_SYSERR ==
1655  section,
1656  option,
1657  &test_match,
1658  (void *) value))
1659  return GNUNET_NO; /* already exists */
1660  if (GNUNET_OK !=
1661  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
1662  old = GNUNET_strdup ("");
1663  escaped = escape_name (value);
1664  nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2);
1665  strcpy (nw, old);
1666  if (strlen (old) > 0)
1667  strcat (nw, " ");
1668  strcat (nw, escaped);
1669  GNUNET_CONFIGURATION_set_value_string (cfg, section, option, nw);
1670  GNUNET_free (old);
1671  GNUNET_free (nw);
1672  GNUNET_free (escaped);
1673  return GNUNET_OK;
1674 }
1675 
1676 
1689 int
1692  const char *section,
1693  const char *option,
1694  const char *value)
1695 {
1696  char *list;
1697  char *pos;
1698  char *end;
1699  char *match;
1700  char old;
1701 
1702  if (GNUNET_OK !=
1703  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list))
1704  return GNUNET_NO;
1705  match = escape_name (value);
1706  pos = list;
1707  while (1)
1708  {
1709  while (pos[0] == ' ')
1710  pos++;
1711  if (strlen (pos) == 0)
1712  break;
1713  end = pos + 1;
1714  while ((end[0] != ' ') && (end[0] != '\0'))
1715  {
1716  if (end[0] == '\\')
1717  {
1718  switch (end[1])
1719  {
1720  case '\\':
1721  case ' ':
1722  end++;
1723  break;
1724 
1725  case '\0':
1726  /* illegal, but just keep it */
1727  break;
1728 
1729  default:
1730  /* illegal, but just ignore that there was a '/' */
1731  break;
1732  }
1733  }
1734  end++;
1735  }
1736  old = end[0];
1737  end[0] = '\0';
1738  if (0 == strcmp (pos, match))
1739  {
1740  if (old != '\0')
1741  memmove (pos, &end[1], strlen (&end[1]) + 1);
1742  else
1743  {
1744  if (pos != list)
1745  pos[-1] = '\0';
1746  else
1747  pos[0] = '\0';
1748  }
1749  GNUNET_CONFIGURATION_set_value_string (cfg, section, option, list);
1750  GNUNET_free (list);
1751  GNUNET_free (match);
1752  return GNUNET_OK;
1753  }
1754  if (old == '\0')
1755  break;
1756  end[0] = old;
1757  pos = end + 1;
1758  }
1759  GNUNET_free (list);
1760  GNUNET_free (match);
1761  return GNUNET_NO;
1762 }
1763 
1764 
1774 static int
1775 parse_configuration_file (void *cls, const char *filename)
1776 {
1777  struct GNUNET_CONFIGURATION_Handle *cfg = cls;
1778  char *ext;
1779  int ret;
1780 
1781  /* Examine file extension */
1782  ext = strrchr (filename, '.');
1783  if ((NULL == ext) || (0 != strcmp (ext, ".conf")))
1784  {
1785  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Skipping file `%s'\n", filename);
1786  return GNUNET_OK;
1787  }
1788 
1789  ret = GNUNET_CONFIGURATION_parse (cfg, filename);
1790  return ret;
1791 }
1792 
1793 
1802 int
1804  const char *defaults_d)
1805 {
1806  if (GNUNET_SYSERR ==
1808  return GNUNET_SYSERR; /* no configuration at all found */
1809  return GNUNET_OK;
1810 }
1811 
1812 
1823 {
1824  const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
1826 
1827  GNUNET_OS_init (dpd);
1828 
1830  const char *xdg = getenv ("XDG_CONFIG_HOME");
1831  char *cfgname = NULL;
1832 
1833  if (NULL != xdg)
1834  GNUNET_asprintf (&cfgname, "%s/%s", xdg, pd->config_file);
1835  else
1836  cfgname = GNUNET_strdup (pd->user_config_file);
1837 
1838  if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgname))
1839  {
1840  GNUNET_OS_init (pd);
1842  GNUNET_free (cfgname);
1843  return NULL;
1844  }
1845 
1846  GNUNET_free (cfgname);
1847 
1848  GNUNET_OS_init (pd);
1849 
1850  return cfg;
1851 }
1852 
1853 
1854 /* end of configuration.c */
void(* GNUNET_CONFIGURATION_Section_Iterator)(void *cls, const char *section)
Function to iterate over section.
Return the directory where translations are installed (share/locale/)
const char * config_file
Configuration file name (in $XDG_CONFIG_HOME) to use.
int 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.
Project-specific data used to help the OS subsystem find installation paths.
int dirty
Modification indication since last save GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on err...
Definition: configuration.c:96
int 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.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
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.
static char * escape_name(const char *value)
FIXME.
int GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
void GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over all options in the configuration.
Return the directory where libraries are installed.
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
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...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct ConfigEntry * entries
entries in the section
Definition: configuration.c:72
int 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:356
int 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.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
int 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.
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.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct Experiment * e
int GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:684
void(* GNUNET_CONFIGURATION_Iterator)(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
const char * user_config_file
Configuration file name to use (if $XDG_CONFIG_HOME is not set).
int 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:324
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_default(void)
Return default project data used by &#39;libgnunetutil&#39; for GNUnet.
configuration entry
Definition: configuration.c:40
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create()
Create a GNUNET_CONFIGURATION_Handle.
int 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...
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.
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:911
static struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define SIZE_MAX
Definition: platform.h:220
ssize_t GNUNET_DISK_fn_write(const char *fn, const void *buffer, size_t n, enum GNUNET_DISK_AccessPermissions mode)
Write a buffer to a file.
Definition: disk.c:879
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_CONFIGURATION_Handle * cfgDiff
uint32_t number
int GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
static char * section
Name of the section.
Definition: gnunet-config.c:33
static int test_match(void *cls, const char *fn)
FIXME.
int(* 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_default(void)
Return GNUnet&#39;s default configuration.
Return the "PREFIX" directory given to configure.
char * name
name of the section
Definition: configuration.c:77
cryptographic primitives for GNUnet
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
int 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.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
static char * line
Desired phone line (string to be converted to a hash).
static struct ConfigSection * find_section(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Find a section entry from a configuration.
Return the prefix of the path with documentation files, including the license (share/doc/gnunet/).
static char * value
Value of the record to add/remove.
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.
static char * fn
Filename of the unique file.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
int 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.
int GNUNET_CONFIGURATION_is_dirty(const struct GNUNET_CONFIGURATION_Handle *cfg)
Test if there are configuration options that were changed since the last save.
int 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.
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, the current running apps installation directory.
void GNUNET_CONFIGURATION_remove_section(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Remove the given section and all options in it.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
static char * option
Name of the option.
Definition: gnunet-config.c:38
static char buf[2048]
static char * filename
static int result
Global testing status.
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.
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 copy_entry(void *cls, const char *section, const char *option, const char *value)
Copy a configuration value to the given target configuration.
struct ConfigSection * sections
Configuration sections.
Definition: configuration.c:89
int(* GNUNET_FileNameCallback)(void *cls, const char *filename)
Function called with a filename.
Return the directory where helper binaries are installed (lib/gnunet/libexec/)
#define LOG(kind,...)
Definition: configuration.c:32
int 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.
int GNUNET_CONFIGURATION_load_from(struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d)
Load default configuration.
static int res
int 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.
static unsigned int size
Size of the "table".
Definition: peer.c:67
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:45
configuration section
Definition: configuration.c:62
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:618
char * getenv()
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
Used for diffing a configuration object against the default one.
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:36
int 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:257
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
char * GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
Serializes the given configuration.
Return the directory where the program binaries are installed.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
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.
configuration data
Definition: configuration.c:84
char * key
key for this entry
Definition: configuration.c:50
static OpusEncoder * enc
OPUS encoder.
void GNUNET_CONFIGURATION_iterate_sections(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Section_Iterator iter, void *iter_cls)
Iterate over all sections in the configuration.
#define GNUNET_log(kind,...)
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
int 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 a string.
static int parse_configuration_file(void *cls, const char *filename)
Wrapper around GNUNET_CONFIGURATION_parse.
void GNUNET_OS_init(const struct GNUNET_OS_ProjectData *pd)
Setup OS subsystem with project data.
const struct GNUNET_CONFIGURATION_Handle * cfg_default
Return the prefix of the path with application icons (share/icons/).
int GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *basedir)
De-serializes configuration.
int 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.
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...
int 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".
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:67
int 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...
static int list
Set if we should print a list of currently running services.
Definition: gnunet-arm.c:69
int 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. ...
#define GNUNET_malloc(size)
Wrapper around malloc.
int 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:971
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:794
char * val
current, commited value
Definition: configuration.c:55
Return the directory where data is installed (share/gnunet/)
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...