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  GNUNET_free (cfg_buf);
610  return GNUNET_SYSERR;
611  }
612  if (((ssize_t) size) !=
614  cfg_buf,
615  size))
616  {
618  "write",
619  fn);
621  (void) GNUNET_DISK_directory_remove (fn);
622  GNUNET_free (fn);
623  GNUNET_free (cfg_buf);
624  cfg->dirty = GNUNET_SYSERR; /* last write failed */
625  return GNUNET_SYSERR;
626  }
629  }
630  GNUNET_free (fn);
631  GNUNET_free (cfg_buf);
632  cfg->dirty = GNUNET_NO; /* last write succeeded */
633  return GNUNET_OK;
634 }
635 
636 
637 void
640  void *iter_cls)
641 {
642  for (struct ConfigSection *spos = cfg->sections;
643  NULL != spos;
644  spos = spos->next)
645  for (struct ConfigEntry *epos = spos->entries;
646  NULL != epos;
647  epos = epos->next)
648  if (NULL != epos->val)
649  iter (iter_cls,
650  spos->name,
651  epos->key,
652  epos->val);
653 }
654 
655 
656 void
658  const struct GNUNET_CONFIGURATION_Handle *cfg,
659  const char *section,
661  void *iter_cls)
662 {
663  struct ConfigSection *spos;
664  struct ConfigEntry *epos;
665 
666  spos = cfg->sections;
667  while ((spos != NULL) && (0 != strcasecmp (spos->name, section)))
668  spos = spos->next;
669  if (NULL == spos)
670  return;
671  for (epos = spos->entries; NULL != epos; epos = epos->next)
672  if (NULL != epos->val)
673  iter (iter_cls, spos->name, epos->key, epos->val);
674 }
675 
676 
677 void
679  const struct GNUNET_CONFIGURATION_Handle *cfg,
681  void *iter_cls)
682 {
683  struct ConfigSection *spos;
684  struct ConfigSection *next;
685 
686  next = cfg->sections;
687  while (next != NULL)
688  {
689  spos = next;
690  next = spos->next;
691  iter (iter_cls, spos->name);
692  }
693 }
694 
695 
696 void
698  const char *section)
699 {
700  struct ConfigSection *spos;
701  struct ConfigSection *prev;
702  struct ConfigEntry *ent;
703 
704  prev = NULL;
705  spos = cfg->sections;
706  while (NULL != spos)
707  {
708  if (0 == strcasecmp (section, spos->name))
709  {
710  if (NULL == prev)
711  cfg->sections = spos->next;
712  else
713  prev->next = spos->next;
714  while (NULL != (ent = spos->entries))
715  {
716  spos->entries = ent->next;
717  GNUNET_free (ent->key);
718  GNUNET_free (ent->val);
719  GNUNET_free (ent);
720  cfg->dirty = GNUNET_YES;
721  }
722  GNUNET_free (spos->name);
723  GNUNET_free (spos);
724  return;
725  }
726  prev = spos;
727  spos = spos->next;
728  }
729 }
730 
731 
741 static void
742 copy_entry (void *cls,
743  const char *section,
744  const char *option,
745  const char *value)
746 {
747  struct GNUNET_CONFIGURATION_Handle *dst = cls;
748 
749  GNUNET_CONFIGURATION_set_value_string (dst, section, option, value);
750 }
751 
752 
755 {
757 
760  return ret;
761 }
762 
763 
771 static struct ConfigSection *
773  const char *section)
774 {
775  struct ConfigSection *pos;
776 
777  pos = cfg->sections;
778  while ((pos != NULL) && (0 != strcasecmp (section, pos->name)))
779  pos = pos->next;
780  return pos;
781 }
782 
783 
792 static struct ConfigEntry *
794  const char *section,
795  const char *key)
796 {
797  struct ConfigSection *sec;
798  struct ConfigEntry *pos;
799 
800  if (NULL == (sec = find_section (cfg, section)))
801  return NULL;
802  pos = sec->entries;
803  while ((pos != NULL) && (0 != strcasecmp (key, pos->key)))
804  pos = pos->next;
805  return pos;
806 }
807 
808 
819 static void
820 compare_entries (void *cls,
821  const char *section,
822  const char *option,
823  const char *value)
824 {
825  struct DiffHandle *dh = cls;
826  struct ConfigEntry *entNew;
827 
828  entNew = find_entry (dh->cfg_default, section, option);
829  if ((NULL != entNew) && (NULL != entNew->val) &&
830  (0 == strcmp (entNew->val, value)))
831  return;
832  GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff, section, option, value);
833 }
834 
835 
838  const struct GNUNET_CONFIGURATION_Handle *cfg_default,
839  const struct GNUNET_CONFIGURATION_Handle *cfg_new)
840 {
841  struct DiffHandle diffHandle;
842 
843  diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
844  diffHandle.cfg_default = cfg_default;
845  GNUNET_CONFIGURATION_iterate (cfg_new, &compare_entries, &diffHandle);
846  return diffHandle.cfgDiff;
847 }
848 
849 
853  const struct GNUNET_CONFIGURATION_Handle *cfg_new,
854  const char *filename)
855 {
856  int ret;
857  struct GNUNET_CONFIGURATION_Handle *diff;
858 
859  diff = GNUNET_CONFIGURATION_get_diff (cfg_default, cfg_new);
860  ret = GNUNET_CONFIGURATION_write (diff, filename);
862  return ret;
863 }
864 
865 
866 void
868  const char *section,
869  const char *option,
870  const char *value)
871 {
872  struct ConfigSection *sec;
873  struct ConfigEntry *e;
874  char *nv;
875 
876  e = find_entry (cfg, section, option);
877  if (NULL != e)
878  {
879  if (NULL == value)
880  {
881  GNUNET_free (e->val);
882  e->val = NULL;
883  }
884  else
885  {
886  nv = GNUNET_strdup (value);
887  GNUNET_free (e->val);
888  e->val = nv;
889  }
890  return;
891  }
892  sec = find_section (cfg, section);
893  if (sec == NULL)
894  {
895  sec = GNUNET_new (struct ConfigSection);
896  sec->name = GNUNET_strdup (section);
897  sec->next = cfg->sections;
898  cfg->sections = sec;
899  }
900  e = GNUNET_new (struct ConfigEntry);
901  e->key = GNUNET_strdup (option);
902  e->val = GNUNET_strdup (value);
903  e->next = sec->entries;
904  sec->entries = e;
905 }
906 
907 
908 void
910  const char *section,
911  const char *option,
912  unsigned long long number)
913 {
914  char s[64];
915 
916  GNUNET_snprintf (s, 64, "%llu", number);
917  GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s);
918 }
919 
920 
923  const struct GNUNET_CONFIGURATION_Handle *cfg,
924  const char *section,
925  const char *option,
926  unsigned long long *number)
927 {
928  struct ConfigEntry *e;
929  char dummy[2];
930 
931  if (NULL == (e = find_entry (cfg, section, option)))
932  return GNUNET_SYSERR;
933  if (NULL == e->val)
934  return GNUNET_SYSERR;
935  if (1 != sscanf (e->val, "%llu%1s", number, dummy))
936  return GNUNET_SYSERR;
937  return GNUNET_OK;
938 }
939 
940 
943  const struct GNUNET_CONFIGURATION_Handle *cfg,
944  const char *section,
945  const char *option,
946  float *number)
947 {
948  struct ConfigEntry *e;
949  char dummy[2];
950 
951  if (NULL == (e = find_entry (cfg, section, option)))
952  return GNUNET_SYSERR;
953  if (NULL == e->val)
954  return GNUNET_SYSERR;
955  if (1 != sscanf (e->val, "%f%1s", number, dummy))
956  return GNUNET_SYSERR;
957  return GNUNET_OK;
958 }
959 
960 
963  const struct GNUNET_CONFIGURATION_Handle *cfg,
964  const char *section,
965  const char *option,
966  struct GNUNET_TIME_Relative *time)
967 {
968  struct ConfigEntry *e;
969  int ret;
970 
971  if (NULL == (e = find_entry (cfg, section, option)))
972  return GNUNET_SYSERR;
973  if (NULL == e->val)
974  return GNUNET_SYSERR;
976  if (GNUNET_OK != ret)
978  section,
979  option,
980  _ ("Not a valid relative time specification"));
981  return ret;
982 }
983 
984 
987  const struct GNUNET_CONFIGURATION_Handle *cfg,
988  const char *section,
989  const char *option,
990  unsigned long long *size)
991 {
992  struct ConfigEntry *e;
993 
994  if (NULL == (e = find_entry (cfg, section, option)))
995  return GNUNET_SYSERR;
996  if (NULL == e->val)
997  return GNUNET_SYSERR;
998  return GNUNET_STRINGS_fancy_size_to_bytes (e->val, size);
999 }
1000 
1001 
1014  const struct GNUNET_CONFIGURATION_Handle *cfg,
1015  const char *section,
1016  const char *option,
1017  char **value)
1018 {
1019  struct ConfigEntry *e;
1020 
1021  if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1022  {
1023  *value = NULL;
1024  return GNUNET_SYSERR;
1025  }
1026  *value = GNUNET_strdup (e->val);
1027  return GNUNET_OK;
1028 }
1029 
1030 
1033  const struct GNUNET_CONFIGURATION_Handle *cfg,
1034  const char *section,
1035  const char *option,
1036  const char *const *choices,
1037  const char **value)
1038 {
1039  struct ConfigEntry *e;
1040  unsigned int i;
1041 
1042  if (NULL == (e = find_entry (cfg, section, option)))
1043  return GNUNET_SYSERR;
1044  for (i = 0; NULL != choices[i]; i++)
1045  if (0 == strcasecmp (choices[i], e->val))
1046  break;
1047  if (NULL == choices[i])
1048  {
1050  _ ("Configuration value '%s' for '%s'"
1051  " in section '%s' is not in set of legal choices\n"),
1052  e->val,
1053  option,
1054  section);
1055  return GNUNET_SYSERR;
1056  }
1057  *value = choices[i];
1058  return GNUNET_OK;
1059 }
1060 
1061 
1064  const char *section,
1065  const char *option,
1066  void *buf,
1067  size_t buf_size)
1068 {
1069  char *enc;
1070  int res;
1071  size_t data_size;
1072 
1073  if (GNUNET_OK !=
1074  (res =
1075  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &enc)))
1076  return res;
1077  data_size = (strlen (enc) * 5) / 8;
1078  if (data_size != buf_size)
1079  {
1080  GNUNET_free (enc);
1081  return GNUNET_SYSERR;
1082  }
1083  if (GNUNET_OK !=
1084  GNUNET_STRINGS_string_to_data (enc, strlen (enc), buf, buf_size))
1085  {
1086  GNUNET_free (enc);
1087  return GNUNET_SYSERR;
1088  }
1089  GNUNET_free (enc);
1090  return GNUNET_OK;
1091 }
1092 
1093 
1096  const char *section,
1097  const char *option)
1098 {
1099  struct ConfigEntry *e;
1100 
1101  if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
1102  return GNUNET_NO;
1103  return GNUNET_YES;
1104 }
1105 
1106 
1122 static char *
1124  char *orig,
1125  unsigned int depth)
1126 {
1127  char *prefix;
1128  char *result;
1129  char *start;
1130  const char *post;
1131  const char *env;
1132  char *def;
1133  char *end;
1134  unsigned int lopen;
1135  char erased_char;
1136  char *erased_pos;
1137  size_t len;
1138 
1139  if (NULL == orig)
1140  return NULL;
1141  if (depth > 128)
1142  {
1144  _ (
1145  "Recursive expansion suspected, aborting $-expansion for term `%s'\n"),
1146  orig);
1147  return orig;
1148  }
1149  LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to $-expand %s\n", orig);
1150  if ('$' != orig[0])
1151  {
1152  LOG (GNUNET_ERROR_TYPE_DEBUG, "Doesn't start with $ - not expanding\n");
1153  return orig;
1154  }
1155  erased_char = 0;
1156  erased_pos = NULL;
1157  if ('{' == orig[1])
1158  {
1159  start = &orig[2];
1160  lopen = 1;
1161  end = &orig[1];
1162  while (lopen > 0)
1163  {
1164  end++;
1165  switch (*end)
1166  {
1167  case '}':
1168  lopen--;
1169  break;
1170 
1171  case '{':
1172  lopen++;
1173  break;
1174 
1175  case '\0':
1177  _ ("Missing closing `%s' in option `%s'\n"),
1178  "}",
1179  orig);
1180  return orig;
1181 
1182  default:
1183  break;
1184  }
1185  }
1186  erased_char = *end;
1187  erased_pos = end;
1188  *end = '\0';
1189  post = end + 1;
1190  def = strchr (orig, ':');
1191  if (NULL != def)
1192  {
1193  *def = '\0';
1194  def++;
1195  if (('-' == *def) || ('=' == *def))
1196  def++;
1197  def = GNUNET_strdup (def);
1198  }
1199  }
1200  else
1201  {
1202  int i;
1203 
1204  start = &orig[1];
1205  def = NULL;
1206  i = 0;
1207  while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0') &&
1208  (orig[i] != ' '))
1209  i++;
1210  if (orig[i] == '\0')
1211  {
1212  post = "";
1213  }
1214  else
1215  {
1216  erased_char = orig[i];
1217  erased_pos = &orig[i];
1218  orig[i] = '\0';
1219  post = &orig[i + 1];
1220  }
1221  }
1223  "Split into `%s' and `%s' with default %s\n",
1224  start,
1225  post,
1226  def);
1227  if (GNUNET_OK !=
1228  GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", start, &prefix))
1229  {
1230  if (NULL == (env = getenv (start)))
1231  {
1232  /* try default */
1233  def = expand_dollar (cfg, def, depth + 1);
1234  env = def;
1235  }
1236  if (NULL == env)
1237  {
1238  start = GNUNET_strdup (start);
1239  if (erased_pos)
1240  *erased_pos = erased_char;
1242  _ (
1243  "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n"),
1244  start,
1245  orig);
1246  GNUNET_free (start);
1247  return orig;
1248  }
1249  prefix = GNUNET_strdup (env);
1250  }
1251  prefix = GNUNET_CONFIGURATION_expand_dollar (cfg, prefix);
1252  if ((erased_pos) && ('}' != erased_char))
1253  {
1254  len = strlen (prefix) + 1;
1255  prefix = GNUNET_realloc (prefix, len + 1);
1256  prefix[len - 1] = erased_char;
1257  prefix[len] = '\0';
1258  }
1259  result = GNUNET_malloc (strlen (prefix) + strlen (post) + 1);
1260  strcpy (result, prefix);
1261  strcat (result, post);
1262  GNUNET_free (def);
1263  GNUNET_free (prefix);
1264  GNUNET_free (orig);
1265  return result;
1266 }
1267 
1268 
1269 char *
1271  const struct GNUNET_CONFIGURATION_Handle *cfg,
1272  char *orig)
1273 {
1274  char *dup;
1275  size_t i;
1276  size_t len;
1277 
1278  for (i = 0; '\0' != orig[i]; i++)
1279  {
1280  if ('$' != orig[i])
1281  continue;
1282  dup = GNUNET_strdup (orig + i);
1283  dup = expand_dollar (cfg, dup, 0);
1284  GNUNET_assert (NULL != dup); /* make compiler happy */
1285  len = strlen (dup) + 1;
1286  orig = GNUNET_realloc (orig, i + len);
1287  GNUNET_memcpy (orig + i, dup, len);
1288  GNUNET_free (dup);
1289  }
1290  return orig;
1291 }
1292 
1293 
1296  const struct GNUNET_CONFIGURATION_Handle *cfg,
1297  const char *section,
1298  const char *option,
1299  char **value)
1300 {
1301  char *tmp;
1302 
1303  if (GNUNET_OK !=
1304  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp))
1305  {
1306  LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to retrieve filename\n");
1307  *value = NULL;
1308  return GNUNET_SYSERR;
1309  }
1310  tmp = GNUNET_CONFIGURATION_expand_dollar (cfg, tmp);
1311  *value = GNUNET_STRINGS_filename_expand (tmp);
1312  GNUNET_free (tmp);
1313  if (*value == NULL)
1314  return GNUNET_SYSERR;
1315  return GNUNET_OK;
1316 }
1317 
1318 
1321  const struct GNUNET_CONFIGURATION_Handle *cfg,
1322  const char *section,
1323  const char *option)
1324 {
1325  static const char *yesno[] = { "YES", "NO", NULL };
1326  const char *val;
1327  int ret;
1328 
1329  ret =
1330  GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
1331  if (ret == GNUNET_SYSERR)
1332  return ret;
1333  if (val == yesno[0])
1334  return GNUNET_YES;
1335  return GNUNET_NO;
1336 }
1337 
1338 
1339 int
1341  const struct GNUNET_CONFIGURATION_Handle *cfg,
1342  const char *section,
1343  const char *option,
1345  void *cb_cls)
1346 {
1347  char *list;
1348  char *pos;
1349  char *end;
1350  char old;
1351  int ret;
1352 
1353  if (GNUNET_OK !=
1354  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list))
1355  return 0;
1356  GNUNET_assert (list != NULL);
1357  ret = 0;
1358  pos = list;
1359  while (1)
1360  {
1361  while (pos[0] == ' ')
1362  pos++;
1363  if (strlen (pos) == 0)
1364  break;
1365  end = pos + 1;
1366  while ((end[0] != ' ') && (end[0] != '\0'))
1367  {
1368  if (end[0] == '\\')
1369  {
1370  switch (end[1])
1371  {
1372  case '\\':
1373  case ' ':
1374  memmove (end, &end[1], strlen (&end[1]) + 1);
1375 
1376  case '\0':
1377  /* illegal, but just keep it */
1378  break;
1379 
1380  default:
1381  /* illegal, but just ignore that there was a '/' */
1382  break;
1383  }
1384  }
1385  end++;
1386  }
1387  old = end[0];
1388  end[0] = '\0';
1389  if (strlen (pos) > 0)
1390  {
1391  ret++;
1392  if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos)))
1393  {
1394  ret = GNUNET_SYSERR;
1395  break;
1396  }
1397  }
1398  if (old == '\0')
1399  break;
1400  pos = end + 1;
1401  }
1402  GNUNET_free (list);
1403  return ret;
1404 }
1405 
1406 
1413 static char *
1414 escape_name (const char *value)
1415 {
1416  char *escaped;
1417  const char *rpos;
1418  char *wpos;
1419 
1420  escaped = GNUNET_malloc (strlen (value) * 2 + 1);
1421  memset (escaped, 0, strlen (value) * 2 + 1);
1422  rpos = value;
1423  wpos = escaped;
1424  while (rpos[0] != '\0')
1425  {
1426  switch (rpos[0])
1427  {
1428  case '\\':
1429  case ' ':
1430  wpos[0] = '\\';
1431  wpos[1] = rpos[0];
1432  wpos += 2;
1433  break;
1434 
1435  default:
1436  wpos[0] = rpos[0];
1437  wpos++;
1438  }
1439  rpos++;
1440  }
1441  return escaped;
1442 }
1443 
1444 
1452 static enum GNUNET_GenericReturnValue
1453 test_match (void *cls, const char *fn)
1454 {
1455  const char *of = cls;
1456 
1457  return (0 == strcmp (of, fn)) ? GNUNET_SYSERR : GNUNET_OK;
1458 }
1459 
1460 
1464  const char *section,
1465  const char *option,
1466  const char *value)
1467 {
1468  char *escaped;
1469  char *old;
1470  char *nw;
1471 
1472  if (GNUNET_SYSERR ==
1474  section,
1475  option,
1476  &test_match,
1477  (void *) value))
1478  return GNUNET_NO; /* already exists */
1479  if (GNUNET_OK !=
1480  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
1481  old = GNUNET_strdup ("");
1482  escaped = escape_name (value);
1483  nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2);
1484  strcpy (nw, old);
1485  if (strlen (old) > 0)
1486  strcat (nw, " ");
1487  strcat (nw, escaped);
1488  GNUNET_CONFIGURATION_set_value_string (cfg, section, option, nw);
1489  GNUNET_free (old);
1490  GNUNET_free (nw);
1491  GNUNET_free (escaped);
1492  return GNUNET_OK;
1493 }
1494 
1495 
1499  const char *section,
1500  const char *option,
1501  const char *value)
1502 {
1503  char *list;
1504  char *pos;
1505  char *end;
1506  char *match;
1507  char old;
1508 
1509  if (GNUNET_OK !=
1510  GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list))
1511  return GNUNET_NO;
1512  match = escape_name (value);
1513  pos = list;
1514  while (1)
1515  {
1516  while (pos[0] == ' ')
1517  pos++;
1518  if (strlen (pos) == 0)
1519  break;
1520  end = pos + 1;
1521  while ((end[0] != ' ') && (end[0] != '\0'))
1522  {
1523  if (end[0] == '\\')
1524  {
1525  switch (end[1])
1526  {
1527  case '\\':
1528  case ' ':
1529  end++;
1530  break;
1531 
1532  case '\0':
1533  /* illegal, but just keep it */
1534  break;
1535 
1536  default:
1537  /* illegal, but just ignore that there was a '/' */
1538  break;
1539  }
1540  }
1541  end++;
1542  }
1543  old = end[0];
1544  end[0] = '\0';
1545  if (0 == strcmp (pos, match))
1546  {
1547  if (old != '\0')
1548  memmove (pos, &end[1], strlen (&end[1]) + 1);
1549  else
1550  {
1551  if (pos != list)
1552  pos[-1] = '\0';
1553  else
1554  pos[0] = '\0';
1555  }
1556  GNUNET_CONFIGURATION_set_value_string (cfg, section, option, list);
1557  GNUNET_free (list);
1558  GNUNET_free (match);
1559  return GNUNET_OK;
1560  }
1561  if (old == '\0')
1562  break;
1563  end[0] = old;
1564  pos = end + 1;
1565  }
1566  GNUNET_free (list);
1567  GNUNET_free (match);
1568  return GNUNET_NO;
1569 }
1570 
1571 
1581 static enum GNUNET_GenericReturnValue
1582 parse_configuration_file (void *cls, const char *filename)
1583 {
1584  struct GNUNET_CONFIGURATION_Handle *cfg = cls;
1585  char *ext;
1586 
1587  /* Examine file extension */
1588  ext = strrchr (filename, '.');
1589  if ((NULL == ext) || (0 != strcmp (ext, ".conf")))
1590  {
1591  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Skipping file `%s'\n", filename);
1592  return GNUNET_OK;
1593  }
1594 
1595  return GNUNET_CONFIGURATION_parse (cfg, filename);
1596 }
1597 
1598 
1601  const char *defaults_d)
1602 {
1603  if (GNUNET_SYSERR ==
1605  return GNUNET_SYSERR; /* no configuration at all found */
1606  return GNUNET_OK;
1607 }
1608 
1609 
1612 {
1613  const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
1615  const char *xdg = getenv ("XDG_CONFIG_HOME");
1616  char *cfgname = NULL;
1618 
1619  GNUNET_OS_init (dpd);
1620  cfg = GNUNET_CONFIGURATION_create ();
1621  if (NULL != xdg)
1622  GNUNET_asprintf (&cfgname, "%s/%s", xdg, pd->config_file);
1623  else
1624  cfgname = GNUNET_strdup (pd->user_config_file);
1625  if (GNUNET_OK !=
1626  GNUNET_CONFIGURATION_load (cfg, cfgname))
1627  {
1628  GNUNET_OS_init (pd);
1630  GNUNET_free (cfgname);
1631  return NULL;
1632  }
1633  GNUNET_free (cfgname);
1634  GNUNET_OS_init (pd);
1635  return cfg;
1636 }
1637 
1638 
1639 /* 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:214
#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:178
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...