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 
97 };
98 
99 
105 {
107 
109 };
110 
111 
114 {
116  char *p;
117 
119  /* make certain values from the project data available
120  as PATHS */
122  if (NULL != p)
123  {
125  "PATHS",
126  "DATADIR",
127  p);
128  GNUNET_free (p);
129  }
131  if (NULL != p)
132  {
134  "PATHS",
135  "LIBDIR",
136  p);
137  GNUNET_free (p);
138  }
140  if (NULL != p)
141  {
143  "PATHS",
144  "BINDIR",
145  p);
146  GNUNET_free (p);
147  }
149  if (NULL != p)
150  {
152  "PATHS",
153  "PREFIX",
154  p);
155  GNUNET_free (p);
156  }
158  if (NULL != p)
159  {
161  "PATHS",
162  "LOCALEDIR",
163  p);
164  GNUNET_free (p);
165  }
167  if (NULL != p)
168  {
170  "PATHS",
171  "ICONDIR",
172  p);
173  GNUNET_free (p);
174  }
176  if (NULL != p)
177  {
179  "PATHS",
180  "DOCDIR",
181  p);
182  GNUNET_free (p);
183  }
185  if (NULL != p)
186  {
188  "PATHS",
189  "LIBEXECDIR",
190  p);
191  GNUNET_free (p);
192  }
193  return cfg;
194 }
195 
196 
197 void
199 {
200  struct ConfigSection *sec;
201 
202  while (NULL != (sec = cfg->sections))
204  GNUNET_free (cfg);
205 }
206 
207 
211  void *cb_cls)
212 {
215 
217  if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, filename))
218  {
219  GNUNET_break (0);
221  return GNUNET_SYSERR;
222  }
223  ret = cb (cb_cls, cfg);
225  return ret;
226 }
227 
228 
231  const char *mem,
232  size_t size,
233  const char *basedir)
234 {
235  char *line;
236  char *line_orig;
237  size_t line_size;
238  char *pos;
239  unsigned int nr;
240  size_t r_bytes;
241  size_t to_read;
242  size_t i;
243  int emptyline;
245  char *section;
246  char *eq;
247  char *tag;
248  char *value;
249 
250  ret = GNUNET_OK;
251  section = GNUNET_strdup ("");
252  nr = 0;
253  r_bytes = 0;
254  line_orig = NULL;
255  while (r_bytes < size)
256  {
257  GNUNET_free (line_orig);
258  /* fgets-like behaviour on buffer */
259  to_read = size - r_bytes;
260  pos = memchr (&mem[r_bytes], '\n', to_read);
261  if (NULL == pos)
262  {
263  line_orig = GNUNET_strndup (&mem[r_bytes], line_size = to_read);
264  r_bytes += line_size;
265  }
266  else
267  {
268  line_orig =
269  GNUNET_strndup (&mem[r_bytes], line_size = (pos - &mem[r_bytes]));
270  r_bytes += line_size + 1;
271  }
272  line = line_orig;
273  /* increment line number */
274  nr++;
275  /* tabs and '\r' are whitespace */
276  emptyline = GNUNET_YES;
277  for (i = 0; i < line_size; i++)
278  {
279  if (line[i] == '\t')
280  line[i] = ' ';
281  if (line[i] == '\r')
282  line[i] = ' ';
283  if (' ' != line[i])
284  emptyline = GNUNET_NO;
285  }
286  /* ignore empty lines */
287  if (GNUNET_YES == emptyline)
288  continue;
289 
290  /* remove tailing whitespace */
291  for (i = line_size - 1; (i >= 1) && (isspace ((unsigned char) line[i]));
292  i--)
293  line[i] = '\0';
294 
295  /* remove leading whitespace */
296  for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++)
297  ;
298 
299  /* ignore comments */
300  if (('#' == line[0]) || ('%' == line[0]))
301  continue;
302 
303  /* handle special "@INLINE@" directive */
304  if (0 == strncasecmp (line, "@INLINE@ ", strlen ("@INLINE@ ")))
305  {
306  /* @INLINE@ value */
307  value = &line[strlen ("@INLINE@ ")];
308  if (NULL != basedir)
309  {
310  char *fn;
311 
312  GNUNET_asprintf (&fn, "%s/%s", basedir, value);
313  if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, fn))
314  {
315  GNUNET_free (fn);
316  ret = GNUNET_SYSERR; /* failed to parse included config */
317  break;
318  }
319  GNUNET_free (fn);
320  }
321  else
322  {
324  "Ignoring parsing @INLINE@ configurations, not allowed!\n");
325  ret = GNUNET_SYSERR;
326  break;
327  }
328  continue;
329  }
330  if (('[' == line[0]) && (']' == line[line_size - 1]))
331  {
332  /* [value] */
333  line[line_size - 1] = '\0';
334  value = &line[1];
335  GNUNET_free (section);
336  section = GNUNET_strdup (value);
337  continue;
338  }
339  if (NULL != (eq = strchr (line, '=')))
340  {
341  /* tag = value */
342  tag = GNUNET_strndup (line, eq - line);
343  /* remove tailing whitespace */
344  for (i = strlen (tag) - 1; (i >= 1) && (isspace ((unsigned char) tag[i]));
345  i--)
346  tag[i] = '\0';
347 
348  /* Strip whitespace */
349  value = eq + 1;
350  while (isspace ((unsigned char) value[0]))
351  value++;
352  for (i = strlen (value) - 1;
353  (i >= 1) && (isspace ((unsigned char) value[i]));
354  i--)
355  value[i] = '\0';
356 
357  /* remove quotes */
358  i = 0;
359  if (('"' == value[0]) && ('"' == value[strlen (value) - 1]))
360  {
361  value[strlen (value) - 1] = '\0';
362  value++;
363  }
364  GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, &value[i]);
365  GNUNET_free (tag);
366  continue;
367  }
368  /* parse error */
370  _ ("Syntax error while deserializing in line %u\n"),
371  nr);
372  ret = GNUNET_SYSERR;
373  break;
374  }
375  GNUNET_free (line_orig);
376  GNUNET_free (section);
377  GNUNET_assert ((GNUNET_OK != ret) || (r_bytes == size));
378  return ret;
379 }
380 
381 
384  const char *filename)
385 {
386  uint64_t fs64;
387  size_t fs;
388  char *fn;
389  char *mem;
390  char *endsep;
391  int dirty;
393  ssize_t sret;
394 
395  fn = GNUNET_STRINGS_filename_expand (filename);
396  LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to parse config file `%s'\n", fn);
397  if (NULL == fn)
398  return GNUNET_SYSERR;
399  dirty = cfg->dirty; /* back up value! */
400  if (GNUNET_SYSERR ==
402  {
404  "Error while determining the file size of `%s'\n",
405  fn);
406  GNUNET_free (fn);
407  return GNUNET_SYSERR;
408  }
409  if (fs64 > SIZE_MAX)
410  {
411  GNUNET_break (0); /* File size is more than the heap size */
412  GNUNET_free (fn);
413  return GNUNET_SYSERR;
414  }
415  fs = fs64;
416  mem = GNUNET_malloc (fs);
417  sret = GNUNET_DISK_fn_read (fn, mem, fs);
418  if ((sret < 0) || (fs != (size_t) sret))
419  {
420  LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Error while reading file `%s'\n"), fn);
421  GNUNET_free (fn);
422  GNUNET_free (mem);
423  return GNUNET_SYSERR;
424  }
425  LOG (GNUNET_ERROR_TYPE_DEBUG, "Deserializing contents of file `%s'\n", fn);
426  endsep = strrchr (fn, (int) '/');
427  if (NULL != endsep)
428  *endsep = '\0';
429  ret = GNUNET_CONFIGURATION_deserialize (cfg, mem, fs, fn);
430  GNUNET_free (fn);
431  GNUNET_free (mem);
432  /* restore dirty flag - anything we set in the meantime
433  * came from disk */
434  cfg->dirty = dirty;
435  return ret;
436 }
437 
438 
441 {
442  return cfg->dirty;
443 }
444 
445 
453 static bool
454 do_skip (const char *sec,
455  const char *key)
456 {
457  if (0 != strcasecmp ("PATHS",
458  sec))
459  return false;
460  return ( (0 == strcasecmp ("DATADIR",
461  key)) ||
462  (0 == strcasecmp ("LIBDIR",
463  key)) ||
464  (0 == strcasecmp ("BINDIR",
465  key)) ||
466  (0 == strcasecmp ("PREFIX",
467  key)) ||
468  (0 == strcasecmp ("LOCALEDIR",
469  key)) ||
470  (0 == strcasecmp ("ICONDIR",
471  key)) ||
472  (0 == strcasecmp ("DOCDIR",
473  key)) ||
474  (0 == strcasecmp ("DEFAULTCONFIG",
475  key)) ||
476  (0 == strcasecmp ("LIBEXECDIR",
477  key)) );
478 }
479 
480 
481 char *
483  size_t *size)
484 {
485  char *mem;
486  char *cbuf;
487  char *val;
488  char *pos;
489  size_t m_size;
490  size_t c_size;
491 
492  /* Pass1 : calculate the buffer size required */
493  m_size = 0;
494  for (struct ConfigSection *sec = cfg->sections;
495  NULL != sec;
496  sec = sec->next)
497  {
498  /* For each section we need to add 3 characters: {'[',']','\n'} */
499  m_size += strlen (sec->name) + 3;
500  for (struct ConfigEntry *ent = sec->entries;
501  NULL != ent;
502  ent = ent->next)
503  {
504  if (do_skip (sec->name,
505  ent->key))
506  continue;
507  if (NULL != ent->val)
508  {
509  /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */
510  pos = ent->val;
511  while (NULL != (pos = strstr (pos, "\n")))
512  {
513  m_size++;
514  pos++;
515  }
516  /* For each key = value pair we need to add 4 characters (2
517  spaces and 1 equal-to character and 1 new line) */
518  m_size += strlen (ent->key) + strlen (ent->val) + 4;
519  }
520  }
521  /* A new line after section end */
522  m_size++;
523  }
524 
525  /* Pass2: Allocate memory and write the configuration to it */
526  mem = GNUNET_malloc (m_size);
527  c_size = 0;
528  *size = c_size;
529  for (struct ConfigSection *sec = cfg->sections;
530  NULL != sec;
531  sec = sec->next)
532  {
533  int len;
534 
535  len = GNUNET_asprintf (&cbuf,
536  "[%s]\n",
537  sec->name);
538  GNUNET_assert (0 < len);
539  GNUNET_memcpy (mem + c_size,
540  cbuf,
541  len);
542  c_size += len;
543  GNUNET_free (cbuf);
544  for (struct ConfigEntry *ent = sec->entries;
545  NULL != ent;
546  ent = ent->next)
547  {
548  if (do_skip (sec->name,
549  ent->key))
550  continue;
551  if (NULL != ent->val)
552  {
553  val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
554  strcpy (val, ent->val);
555  while (NULL != (pos = strstr (val, "\n")))
556  {
557  memmove (&pos[2], &pos[1], strlen (&pos[1]));
558  pos[0] = '\\';
559  pos[1] = 'n';
560  }
561  len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
562  GNUNET_free (val);
563  GNUNET_memcpy (mem + c_size, cbuf, len);
564  c_size += len;
565  GNUNET_free (cbuf);
566  }
567  }
568  GNUNET_memcpy (mem + c_size, "\n", 1);
569  c_size++;
570  }
571  GNUNET_assert (c_size == m_size);
572  *size = c_size;
573  return mem;
574 }
575 
576 
579  const char *filename)
580 {
581  char *fn;
582  char *cfg_buf;
583  size_t size;
584 
585  fn = GNUNET_STRINGS_filename_expand (filename);
586  if (fn == NULL)
587  return GNUNET_SYSERR;
589  {
590  GNUNET_free (fn);
591  return GNUNET_SYSERR;
592  }
593  cfg_buf = GNUNET_CONFIGURATION_serialize (cfg,
594  &size);
595  {
596  struct GNUNET_DISK_FileHandle *h;
597 
598  h = GNUNET_DISK_file_open (fn,
606  if (NULL == h)
607  {
608  GNUNET_free (fn);
609  return GNUNET_SYSERR;
610  }
611  if (((ssize_t) size) !=
613  cfg_buf,
614  size))
615  {
617  "write",
618  fn);
620  (void) GNUNET_DISK_directory_remove (fn);
621  GNUNET_free (fn);
622  GNUNET_free (cfg_buf);
623  cfg->dirty = GNUNET_SYSERR; /* last write failed */
624  return GNUNET_SYSERR;
625  }
628  }
629  GNUNET_free (fn);
630  GNUNET_free (cfg_buf);
631  cfg->dirty = GNUNET_NO; /* last write succeeded */
632  return GNUNET_OK;
633 }
634 
635 
636 void
639  void *iter_cls)
640 {
641  for (struct ConfigSection *spos = cfg->sections;
642  NULL != spos;
643  spos = spos->next)
644  for (struct ConfigEntry *epos = spos->entries;
645  NULL != epos;
646  epos = epos->next)
647  if (NULL != epos->val)
648  iter (iter_cls,
649  spos->name,
650  epos->key,
651  epos->val);
652 }
653 
654 
655 void
657  const struct GNUNET_CONFIGURATION_Handle *cfg,
658  const char *section,
660  void *iter_cls)
661 {
662  struct ConfigSection *spos;
663  struct ConfigEntry *epos;
664 
665  spos = cfg->sections;
666  while ((spos != NULL) && (0 != strcasecmp (spos->name, section)))
667  spos = spos->next;
668  if (NULL == spos)
669  return;
670  for (epos = spos->entries; NULL != epos; epos = epos->next)
671  if (NULL != epos->val)
672  iter (iter_cls, spos->name, epos->key, epos->val);
673 }
674 
675 
676 void
678  const struct GNUNET_CONFIGURATION_Handle *cfg,
680  void *iter_cls)
681 {
682  struct ConfigSection *spos;
683  struct ConfigSection *next;
684 
685  next = cfg->sections;
686  while (next != NULL)
687  {
688  spos = next;
689  next = spos->next;
690  iter (iter_cls, spos->name);
691  }
692 }
693 
694 
695 void
697  const char *section)
698 {
699  struct ConfigSection *spos;
700  struct ConfigSection *prev;
701  struct ConfigEntry *ent;
702 
703  prev = NULL;
704  spos = cfg->sections;
705  while (NULL != spos)
706  {
707  if (0 == strcasecmp (section, spos->name))
708  {
709  if (NULL == prev)
710  cfg->sections = spos->next;
711  else
712  prev->next = spos->next;
713  while (NULL != (ent = spos->entries))
714  {
715  spos->entries = ent->next;
716  GNUNET_free (ent->key);
717  GNUNET_free (ent->val);
718  GNUNET_free (ent);
719  cfg->dirty = GNUNET_YES;
720  }
721  GNUNET_free (spos->name);
722  GNUNET_free (spos);
723  return;
724  }
725  prev = spos;
726  spos = spos->next;
727  }
728 }
729 
730 
740 static void
741 copy_entry (void *cls,
742  const char *section,
743  const char *option,
744  const char *value)
745 {
746  struct GNUNET_CONFIGURATION_Handle *dst = cls;
747 
748  GNUNET_CONFIGURATION_set_value_string (dst, section, option, value);
749 }
750 
751 
754 {
756 
759  return ret;
760 }
761 
762 
770 static struct ConfigSection *
772  const char *section)
773 {
774  struct ConfigSection *pos;
775 
776  pos = cfg->sections;
777  while ((pos != NULL) && (0 != strcasecmp (section, pos->name)))
778  pos = pos->next;
779  return pos;
780 }
781 
782 
791 static struct ConfigEntry *
793  const char *section,
794  const char *key)
795 {
796  struct ConfigSection *sec;
797  struct ConfigEntry *pos;
798 
799  if (NULL == (sec = find_section (cfg, section)))
800  return NULL;
801  pos = sec->entries;
802  while ((pos != NULL) && (0 != strcasecmp (key, pos->key)))
803  pos = pos->next;
804  return pos;
805 }
806 
807 
818 static void
819 compare_entries (void *cls,
820  const char *section,
821  const char *option,
822  const char *value)
823 {
824  struct DiffHandle *dh = cls;
825  struct ConfigEntry *entNew;
826 
827  entNew = find_entry (dh->cfg_default, section, option);
828  if ((NULL != entNew) && (NULL != entNew->val) &&
829  (0 == strcmp (entNew->val, value)))
830  return;
831  GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff, section, option, value);
832 }
833 
834 
837  const struct GNUNET_CONFIGURATION_Handle *cfg_default,
838  const struct GNUNET_CONFIGURATION_Handle *cfg_new)
839 {
840  struct DiffHandle diffHandle;
841 
842  diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
843  diffHandle.cfg_default = cfg_default;
844  GNUNET_CONFIGURATION_iterate (cfg_new, &compare_entries, &diffHandle);
845  return diffHandle.cfgDiff;
846 }
847 
848 
852  const struct GNUNET_CONFIGURATION_Handle *cfg_new,
853  const char *filename)
854 {
855  int ret;
856  struct GNUNET_CONFIGURATION_Handle *diff;
857 
858  diff = GNUNET_CONFIGURATION_get_diff (cfg_default, cfg_new);
859  ret = GNUNET_CONFIGURATION_write (diff, filename);
861  return ret;
862 }
863 
864 
865 void
867  const char *section,
868  const char *option,
869  const char *value)
870 {
871  struct ConfigSection *sec;
872  struct ConfigEntry *e;
873  char *nv;
874 
875  e = find_entry (cfg, section, option);
876  if (NULL != e)
877  {
878  if (NULL == value)
879  {
880  GNUNET_free (e->val);
881  e->val = NULL;
882  }
883  else
884  {
885  nv = GNUNET_strdup (value);
886  GNUNET_free (e->val);
887  e->val = nv;
888  }
889  return;
890  }
891  sec = find_section (cfg, section);
892  if (sec == NULL)
893  {
894  sec = GNUNET_new (struct ConfigSection);
895  sec->name = GNUNET_strdup (section);
896  sec->next = cfg->sections;
897  cfg->sections = sec;
898  }
899  e = GNUNET_new (struct ConfigEntry);
900  e->key = GNUNET_strdup (option);
901  e->val = GNUNET_strdup (value);
902  e->next = sec->entries;
903  sec->entries = e;
904 }
905 
906 
907 void
909  const char *section,
910  const char *option,
911  unsigned long long number)
912 {
913  char s[64];
914 
915  GNUNET_snprintf (s, 64, "%llu", number);
916  GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s);
917 }
918 
919 
922  const struct GNUNET_CONFIGURATION_Handle *cfg,
923  const char *section,
924  const char *option,
925  unsigned long long *number)
926 {
927  struct ConfigEntry *e;
928  char dummy[2];
929 
930  if (NULL == (e = find_entry (cfg, section, option)))
931  return GNUNET_SYSERR;
932  if (NULL == e->val)
933  return GNUNET_SYSERR;
934  if (1 != sscanf (e->val, "%llu%1s", number, dummy))
935  return GNUNET_SYSERR;
936  return GNUNET_OK;
937 }
938 
939 
942  const struct GNUNET_CONFIGURATION_Handle *cfg,
943  const char *section,
944  const char *option,
945  float *number)
946 {
947  struct ConfigEntry *e;
948  char dummy[2];
949 
950  if (NULL == (e = find_entry (cfg, section, option)))
951  return GNUNET_SYSERR;
952  if (NULL == e->val)
953  return GNUNET_SYSERR;
954  if (1 != sscanf (e->val, "%f%1s", number, dummy))
955  return GNUNET_SYSERR;
956  return GNUNET_OK;
957 }
958 
959 
962  const struct GNUNET_CONFIGURATION_Handle *cfg,
963  const char *section,
964  const char *option,
965  struct GNUNET_TIME_Relative *time)
966 {
967  struct ConfigEntry *e;
968  int ret;
969 
970  if (NULL == (e = find_entry (cfg, section, option)))
971  return GNUNET_SYSERR;
972  if (NULL == e->val)
973  return GNUNET_SYSERR;
975  if (GNUNET_OK != ret)
977  section,
978  option,
979  _ ("Not a valid relative time specification"));
980  return ret;
981 }
982 
983 
986  const struct GNUNET_CONFIGURATION_Handle *cfg,
987  const char *section,
988  const char *option,
989  unsigned long long *size)
990 {
991  struct ConfigEntry *e;
992 
993  if (NULL == (e = find_entry (cfg, section, option)))
994  return GNUNET_SYSERR;
995  if (NULL == e->val)
996  return GNUNET_SYSERR;
997  return GNUNET_STRINGS_fancy_size_to_bytes (e->val, size);
998 }
999 
1000 
1013  const struct GNUNET_CONFIGURATION_Handle *cfg,
1014  const char *section,
1015  const char *option,
1016  char **value)
1017 {
1018  struct ConfigEntry *e;
1019 
1020  if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1021  {
1022  *value = NULL;
1023  return GNUNET_SYSERR;
1024  }
1025  *value = GNUNET_strdup (e->val);
1026  return GNUNET_OK;
1027 }
1028 
1029 
1032  const struct GNUNET_CONFIGURATION_Handle *cfg,
1033  const char *section,
1034  const char *option,
1035  const char *const *choices,
1036  const char **value)
1037 {
1038  struct ConfigEntry *e;
1039  unsigned int i;
1040 
1041  if (NULL == (e = find_entry (cfg, section, option)))
1042  return GNUNET_SYSERR;
1043  for (i = 0; NULL != choices[i]; i++)
1044  if (0 == strcasecmp (choices[i], e->val))
1045  break;
1046  if (NULL == choices[i])
1047  {
1049  _ ("Configuration value '%s' for '%s'"
1050  " in section '%s' is not in set of legal choices\n"),
1051  e->val,
1052  option,
1053  section);
1054  return GNUNET_SYSERR;
1055  }
1056  *value = choices[i];
1057  return GNUNET_OK;
1058 }
1059 
1060 
1063  const char *section,
1064  const char *option,
1065  void *buf,
1066  size_t buf_size)
1067 {
1068  char *enc;
1069  int res;
1070  size_t data_size;
1071 
1072  if (GNUNET_OK !=
1073  (res =
1074  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &enc)))
1075  return res;
1076  data_size = (strlen (enc) * 5) / 8;
1077  if (data_size != buf_size)
1078  {
1079  GNUNET_free (enc);
1080  return GNUNET_SYSERR;
1081  }
1082  if (GNUNET_OK !=
1083  GNUNET_STRINGS_string_to_data (enc, strlen (enc), buf, buf_size))
1084  {
1085  GNUNET_free (enc);
1086  return GNUNET_SYSERR;
1087  }
1088  GNUNET_free (enc);
1089  return GNUNET_OK;
1090 }
1091 
1092 
1095  const char *section,
1096  const char *option)
1097 {
1098  struct ConfigEntry *e;
1099 
1100  if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1101  return GNUNET_NO;
1102  return GNUNET_YES;
1103 }
1104 
1105 
1121 static char *
1123  char *orig,
1124  unsigned int depth)
1125 {
1126  char *prefix;
1127  char *result;
1128  char *start;
1129  const char *post;
1130  const char *env;
1131  char *def;
1132  char *end;
1133  unsigned int lopen;
1134  char erased_char;
1135  char *erased_pos;
1136  size_t len;
1137 
1138  if (NULL == orig)
1139  return NULL;
1140  if (depth > 128)
1141  {
1143  _ (
1144  "Recursive expansion suspected, aborting $-expansion for term `%s'\n"),
1145  orig);
1146  return orig;
1147  }
1148  LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to $-expand %s\n", orig);
1149  if ('$' != orig[0])
1150  {
1151  LOG (GNUNET_ERROR_TYPE_DEBUG, "Doesn't start with $ - not expanding\n");
1152  return orig;
1153  }
1154  erased_char = 0;
1155  erased_pos = NULL;
1156  if ('{' == orig[1])
1157  {
1158  start = &orig[2];
1159  lopen = 1;
1160  end = &orig[1];
1161  while (lopen > 0)
1162  {
1163  end++;
1164  switch (*end)
1165  {
1166  case '}':
1167  lopen--;
1168  break;
1169 
1170  case '{':
1171  lopen++;
1172  break;
1173 
1174  case '\0':
1176  _ ("Missing closing `%s' in option `%s'\n"),
1177  "}",
1178  orig);
1179  return orig;
1180 
1181  default:
1182  break;
1183  }
1184  }
1185  erased_char = *end;
1186  erased_pos = end;
1187  *end = '\0';
1188  post = end + 1;
1189  def = strchr (orig, ':');
1190  if (NULL != def)
1191  {
1192  *def = '\0';
1193  def++;
1194  if (('-' == *def) || ('=' == *def))
1195  def++;
1196  def = GNUNET_strdup (def);
1197  }
1198  }
1199  else
1200  {
1201  int i;
1202 
1203  start = &orig[1];
1204  def = NULL;
1205  i = 0;
1206  while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0') &&
1207  (orig[i] != ' '))
1208  i++;
1209  if (orig[i] == '\0')
1210  {
1211  post = "";
1212  }
1213  else
1214  {
1215  erased_char = orig[i];
1216  erased_pos = &orig[i];
1217  orig[i] = '\0';
1218  post = &orig[i + 1];
1219  }
1220  }
1222  "Split into `%s' and `%s' with default %s\n",
1223  start,
1224  post,
1225  def);
1226  if (GNUNET_OK !=
1227  GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", start, &prefix))
1228  {
1229  if (NULL == (env = getenv (start)))
1230  {
1231  /* try default */
1232  def = expand_dollar (cfg, def, depth + 1);
1233  env = def;
1234  }
1235  if (NULL == env)
1236  {
1237  start = GNUNET_strdup (start);
1238  if (erased_pos)
1239  *erased_pos = erased_char;
1241  _ (
1242  "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n"),
1243  start,
1244  orig);
1245  GNUNET_free (start);
1246  return orig;
1247  }
1248  prefix = GNUNET_strdup (env);
1249  }
1250  prefix = GNUNET_CONFIGURATION_expand_dollar (cfg, prefix);
1251  if ((erased_pos) && ('}' != erased_char))
1252  {
1253  len = strlen (prefix) + 1;
1254  prefix = GNUNET_realloc (prefix, len + 1);
1255  prefix[len - 1] = erased_char;
1256  prefix[len] = '\0';
1257  }
1258  result = GNUNET_malloc (strlen (prefix) + strlen (post) + 1);
1259  strcpy (result, prefix);
1260  strcat (result, post);
1261  GNUNET_free (def);
1262  GNUNET_free (prefix);
1263  GNUNET_free (orig);
1264  return result;
1265 }
1266 
1267 
1268 char *
1270  const struct GNUNET_CONFIGURATION_Handle *cfg,
1271  char *orig)
1272 {
1273  char *dup;
1274  size_t i;
1275  size_t len;
1276 
1277  for (i = 0; '\0' != orig[i]; i++)
1278  {
1279  if ('$' != orig[i])
1280  continue;
1281  dup = GNUNET_strdup (orig + i);
1282  dup = expand_dollar (cfg, dup, 0);
1283  GNUNET_assert (NULL != dup); /* make compiler happy */
1284  len = strlen (dup) + 1;
1285  orig = GNUNET_realloc (orig, i + len);
1286  GNUNET_memcpy (orig + i, dup, len);
1287  GNUNET_free (dup);
1288  }
1289  return orig;
1290 }
1291 
1292 
1295  const struct GNUNET_CONFIGURATION_Handle *cfg,
1296  const char *section,
1297  const char *option,
1298  char **value)
1299 {
1300  char *tmp;
1301 
1302  if (GNUNET_OK !=
1303  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp))
1304  {
1305  LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to retrieve filename\n");
1306  *value = NULL;
1307  return GNUNET_SYSERR;
1308  }
1309  tmp = GNUNET_CONFIGURATION_expand_dollar (cfg, tmp);
1310  *value = GNUNET_STRINGS_filename_expand (tmp);
1311  GNUNET_free (tmp);
1312  if (*value == NULL)
1313  return GNUNET_SYSERR;
1314  return GNUNET_OK;
1315 }
1316 
1317 
1320  const struct GNUNET_CONFIGURATION_Handle *cfg,
1321  const char *section,
1322  const char *option)
1323 {
1324  static const char *yesno[] = { "YES", "NO", NULL };
1325  const char *val;
1326  int ret;
1327 
1328  ret =
1329  GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
1330  if (ret == GNUNET_SYSERR)
1331  return ret;
1332  if (val == yesno[0])
1333  return GNUNET_YES;
1334  return GNUNET_NO;
1335 }
1336 
1337 
1338 int
1340  const struct GNUNET_CONFIGURATION_Handle *cfg,
1341  const char *section,
1342  const char *option,
1344  void *cb_cls)
1345 {
1346  char *list;
1347  char *pos;
1348  char *end;
1349  char old;
1350  int ret;
1351 
1352  if (GNUNET_OK !=
1353  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list))
1354  return 0;
1355  GNUNET_assert (list != NULL);
1356  ret = 0;
1357  pos = list;
1358  while (1)
1359  {
1360  while (pos[0] == ' ')
1361  pos++;
1362  if (strlen (pos) == 0)
1363  break;
1364  end = pos + 1;
1365  while ((end[0] != ' ') && (end[0] != '\0'))
1366  {
1367  if (end[0] == '\\')
1368  {
1369  switch (end[1])
1370  {
1371  case '\\':
1372  case ' ':
1373  memmove (end, &end[1], strlen (&end[1]) + 1);
1374 
1375  case '\0':
1376  /* illegal, but just keep it */
1377  break;
1378 
1379  default:
1380  /* illegal, but just ignore that there was a '/' */
1381  break;
1382  }
1383  }
1384  end++;
1385  }
1386  old = end[0];
1387  end[0] = '\0';
1388  if (strlen (pos) > 0)
1389  {
1390  ret++;
1391  if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos)))
1392  {
1393  ret = GNUNET_SYSERR;
1394  break;
1395  }
1396  }
1397  if (old == '\0')
1398  break;
1399  pos = end + 1;
1400  }
1401  GNUNET_free (list);
1402  return ret;
1403 }
1404 
1405 
1412 static char *
1413 escape_name (const char *value)
1414 {
1415  char *escaped;
1416  const char *rpos;
1417  char *wpos;
1418 
1419  escaped = GNUNET_malloc (strlen (value) * 2 + 1);
1420  memset (escaped, 0, strlen (value) * 2 + 1);
1421  rpos = value;
1422  wpos = escaped;
1423  while (rpos[0] != '\0')
1424  {
1425  switch (rpos[0])
1426  {
1427  case '\\':
1428  case ' ':
1429  wpos[0] = '\\';
1430  wpos[1] = rpos[0];
1431  wpos += 2;
1432  break;
1433 
1434  default:
1435  wpos[0] = rpos[0];
1436  wpos++;
1437  }
1438  rpos++;
1439  }
1440  return escaped;
1441 }
1442 
1443 
1451 static enum GNUNET_GenericReturnValue
1452 test_match (void *cls, const char *fn)
1453 {
1454  const char *of = cls;
1455 
1456  return (0 == strcmp (of, fn)) ? GNUNET_SYSERR : GNUNET_OK;
1457 }
1458 
1459 
1463  const char *section,
1464  const char *option,
1465  const char *value)
1466 {
1467  char *escaped;
1468  char *old;
1469  char *nw;
1470 
1471  if (GNUNET_SYSERR ==
1473  section,
1474  option,
1475  &test_match,
1476  (void *) value))
1477  return GNUNET_NO; /* already exists */
1478  if (GNUNET_OK !=
1479  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
1480  old = GNUNET_strdup ("");
1481  escaped = escape_name (value);
1482  nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2);
1483  strcpy (nw, old);
1484  if (strlen (old) > 0)
1485  strcat (nw, " ");
1486  strcat (nw, escaped);
1487  GNUNET_CONFIGURATION_set_value_string (cfg, section, option, nw);
1488  GNUNET_free (old);
1489  GNUNET_free (nw);
1490  GNUNET_free (escaped);
1491  return GNUNET_OK;
1492 }
1493 
1494 
1498  const char *section,
1499  const char *option,
1500  const char *value)
1501 {
1502  char *list;
1503  char *pos;
1504  char *end;
1505  char *match;
1506  char old;
1507 
1508  if (GNUNET_OK !=
1509  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list))
1510  return GNUNET_NO;
1511  match = escape_name (value);
1512  pos = list;
1513  while (1)
1514  {
1515  while (pos[0] == ' ')
1516  pos++;
1517  if (strlen (pos) == 0)
1518  break;
1519  end = pos + 1;
1520  while ((end[0] != ' ') && (end[0] != '\0'))
1521  {
1522  if (end[0] == '\\')
1523  {
1524  switch (end[1])
1525  {
1526  case '\\':
1527  case ' ':
1528  end++;
1529  break;
1530 
1531  case '\0':
1532  /* illegal, but just keep it */
1533  break;
1534 
1535  default:
1536  /* illegal, but just ignore that there was a '/' */
1537  break;
1538  }
1539  }
1540  end++;
1541  }
1542  old = end[0];
1543  end[0] = '\0';
1544  if (0 == strcmp (pos, match))
1545  {
1546  if (old != '\0')
1547  memmove (pos, &end[1], strlen (&end[1]) + 1);
1548  else
1549  {
1550  if (pos != list)
1551  pos[-1] = '\0';
1552  else
1553  pos[0] = '\0';
1554  }
1555  GNUNET_CONFIGURATION_set_value_string (cfg, section, option, list);
1556  GNUNET_free (list);
1557  GNUNET_free (match);
1558  return GNUNET_OK;
1559  }
1560  if (old == '\0')
1561  break;
1562  end[0] = old;
1563  pos = end + 1;
1564  }
1565  GNUNET_free (list);
1566  GNUNET_free (match);
1567  return GNUNET_NO;
1568 }
1569 
1570 
1580 static enum GNUNET_GenericReturnValue
1581 parse_configuration_file (void *cls, const char *filename)
1582 {
1583  struct GNUNET_CONFIGURATION_Handle *cfg = cls;
1584  char *ext;
1585 
1586  /* Examine file extension */
1587  ext = strrchr (filename, '.');
1588  if ((NULL == ext) || (0 != strcmp (ext, ".conf")))
1589  {
1590  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Skipping file `%s'\n", filename);
1591  return GNUNET_OK;
1592  }
1593 
1594  return GNUNET_CONFIGURATION_parse (cfg, filename);
1595 }
1596 
1597 
1600  const char *defaults_d)
1601 {
1602  if (GNUNET_SYSERR ==
1604  return GNUNET_SYSERR; /* no configuration at all found */
1605  return GNUNET_OK;
1606 }
1607 
1608 
1611 {
1612  const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
1614  const char *xdg = getenv ("XDG_CONFIG_HOME");
1615  char *cfgname = NULL;
1617 
1618  GNUNET_OS_init (dpd);
1619  cfg = GNUNET_CONFIGURATION_create ();
1620  if (NULL != xdg)
1621  GNUNET_asprintf (&cfgname, "%s/%s", xdg, pd->config_file);
1622  else
1623  cfgname = GNUNET_strdup (pd->user_config_file);
1624  if (GNUNET_OK !=
1625  GNUNET_CONFIGURATION_load (cfg, cfgname))
1626  {
1627  GNUNET_OS_init (pd);
1629  GNUNET_free (cfgname);
1630  return NULL;
1631  }
1632  GNUNET_free (cfgname);
1633  GNUNET_OS_init (pd);
1634  return cfg;
1635 }
1636 
1637 
1638 /* end of configuration.c */
static enum GNUNET_GenericReturnValue test_match(void *cls, const char *fn)
FIXME.
enum GNUNET_GenericReturnValue dirty
Modification indication since last save GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on err...
Definition: configuration.c:96
void(* GNUNET_CONFIGURATION_Section_Iterator)(void *cls, const char *section)
Function to iterate over section.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *basedir)
De-serializes configuration.
Return the directory where translations are installed (share/locale/)
const char * config_file
Configuration file name (in $XDG_CONFIG_HOME) to use.
Create file if it doesn&#39;t exist.
Project-specific data used to help the OS subsystem find installation paths.
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.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Parse a configuration file, add all of the options in the file to the configuration environment...
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 bool do_skip(const char *sec, const char *key)
Should we skip this configuration entry when serializing?
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.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1126
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
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.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
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
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.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:83
static struct Experiment * e
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.
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.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create()
Create a new configuration object.
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:794
static struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_data(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, void *buf, size_t buf_size)
Get Crockford32-encoded fixed-size binary data from a configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define SIZE_MAX
Definition: platform.h:220
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
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.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
struct GNUNET_CONFIGURATION_Handle * cfgDiff
uint32_t number
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
static char * section
Name of the section.
Definition: gnunet-config.c:33
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.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_default(void)
Return GNUnet&#39;s default configuration.
Return the "PREFIX" directory given to configure.
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.
char * name
name of the section
Definition: configuration.c:77
cryptographic primitives for GNUnet
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.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
static char * fn
Filename of the unique file.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
Truncate file if it exists.
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:666
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
Return the directory where helper binaries are installed (lib/gnunet/libexec/)
#define LOG(kind,...)
Definition: configuration.c:32
static int res
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
static unsigned int size
Size of the "table".
Definition: peer.c:67
Open the file for writing.
struct ConfigEntry * next
This is a linked list.
Definition: configuration.c:45
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_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
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.
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. ...
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:36
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.
static enum GNUNET_GenericReturnValue parse_configuration_file(void *cls, const char *filename)
Wrapper around GNUNET_CONFIGURATION_parse.
char * GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
Serializes the given configuration.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition: disk.c:222
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
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.
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.
enum GNUNET_GenericReturnValue(* GNUNET_FileNameCallback)(void *cls, const char *filename)
Function called with a filename.
#define GNUNET_log(kind,...)
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load_from(struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d)
Load default configuration.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
enum GNUNET_GenericReturnValue(* GNUNET_CONFIGURATION_Callback)(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Signature of a function to be run with a configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
void GNUNET_OS_init(const struct GNUNET_OS_ProjectData *pd)
Setup OS subsystem with project data.
const struct GNUNET_CONFIGURATION_Handle * cfg_default
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:905
Return the prefix of the path with application icons (share/icons/).
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:562
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...
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.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1055
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.
struct ConfigSection * next
This is a linked list.
Definition: configuration.c:67
Handle used to access files (and pipes).
static int list
Set if we should print a list of currently running services.
Definition: gnunet-arm.c:69
#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:972
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:644
char * val
current, committed 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...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse_and_run(const char *filename, GNUNET_CONFIGURATION_Callback cb, void *cb_cls)
Parse a configuration file filename and run the function cb with the resulting configuration object...