2 This file is part of GNUnet.
3 (C) 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file src/util/configuration.c
23 * @brief configuration management
25 * @author Christian Grothoff
29 #include "gnunet_common.h"
30 #include "gnunet_util_lib.h"
31 #include "gnunet_crypto_lib.h"
32 #include "gnunet_strings_lib.h"
34 #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
36 #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
39 * @brief configuration entry
45 * This is a linked list.
47 struct ConfigEntry *next;
55 * current, commited value
62 * @brief configuration section
67 * This is a linked list.
69 struct ConfigSection *next;
72 * entries in the section
74 struct ConfigEntry *entries;
84 * @brief configuration data
86 struct GNUNET_CONFIGURATION_Handle
89 * Configuration sections.
91 struct ConfigSection *sections;
94 * Modification indication since last save
95 * GNUNET_NO if clean, GNUNET_YES if dirty,
96 * GNUNET_SYSERR on error (i.e. last save failed)
104 * Used for diffing a configuration object against
109 const struct GNUNET_CONFIGURATION_Handle *cfgDefault;
110 struct GNUNET_CONFIGURATION_Handle *cfgDiff;
116 * Create a GNUNET_CONFIGURATION_Handle.
118 * @return fresh configuration object
120 struct GNUNET_CONFIGURATION_Handle *
121 GNUNET_CONFIGURATION_create ()
123 return GNUNET_malloc (sizeof (struct GNUNET_CONFIGURATION_Handle));
128 * Destroy configuration object.
130 * @param cfg configuration to destroy
133 GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
135 struct ConfigSection *sec;
137 while (NULL != (sec = cfg->sections))
138 GNUNET_CONFIGURATION_remove_section (cfg, sec->name);
144 * Parse a configuration file, add all of the options in the
145 * file to the configuration environment.
147 * @param cfg configuration to update
148 * @param filename name of the configuration file
149 * @return GNUNET_OK on success, GNUNET_SYSERR on error
152 GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
153 const char *filename)
167 fn = GNUNET_STRINGS_filename_expand (filename);
169 return GNUNET_SYSERR;
170 dirty = cfg->dirty; /* back up value! */
171 if (NULL == (fp = FOPEN (fn, "r")))
173 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn);
175 return GNUNET_SYSERR;
179 section = GNUNET_strdup ("");
180 memset (line, 0, 256);
182 while (NULL != fgets (line, 255, fp))
185 for (i = 0; i < 255; i++)
188 if (line[0] == '\n' || line[0] == '#' || line[0] == '%' || line[0] == '\r')
191 for (i = 0; (i < 255 && line[i] != 0); i++)
192 if (line[i] != ' ' && line[i] != '\n' && line[i] != '\r')
196 /* remove tailing whitespace */
197 for (i = strlen (line) - 1; (i >= 0) && (isspace ((unsigned char) line[i]));
200 if (1 == sscanf (line, "@INLINE@ %191[^\n]", value))
203 if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, value))
204 ret = GNUNET_SYSERR; /* failed to parse included config */
206 else if (1 == sscanf (line, "[%99[^]]]", value))
209 GNUNET_free (section);
210 section = GNUNET_strdup (value);
212 else if (2 == sscanf (line, " %63[^= ] = %191[^\n]", tag, value))
216 i = strlen (value) - 1;
217 while ((i >= 0) && (isspace ((unsigned char) value[i])))
224 while ((value[i] != '\0') && (value[i] != '"'))
234 GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, &value[i]);
236 else if (1 == sscanf (line, " %63[^= ] =[^\n]", tag))
239 GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, "");
244 LOG (GNUNET_ERROR_TYPE_WARNING,
245 _("Syntax error in configuration file `%s' at line %u.\n"), filename,
251 GNUNET_assert (0 == FCLOSE (fp));
252 /* restore dirty flag - anything we set in the meantime
255 GNUNET_free (section);
261 * Test if there are configuration options that were
262 * changed since the last save.
264 * @param cfg configuration to inspect
265 * @return GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error (i.e. last save failed)
268 GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg)
275 * Write configuration file.
277 * @param cfg configuration to write
278 * @param filename where to write the configuration
279 * @return GNUNET_OK on success, GNUNET_SYSERR on error
282 GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
283 const char *filename)
285 struct ConfigSection *sec;
286 struct ConfigEntry *ent;
293 fn = GNUNET_STRINGS_filename_expand (filename);
295 return GNUNET_SYSERR;
296 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn))
299 return GNUNET_SYSERR;
301 if (NULL == (fp = FOPEN (fn, "w")))
303 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn);
305 return GNUNET_SYSERR;
312 if (0 > FPRINTF (fp, "[%s]\n", sec->name))
320 if (ent->val != NULL)
322 val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
323 strcpy (val, ent->val);
324 while (NULL != (pos = strstr (val, "\n")))
326 memmove (&pos[2], &pos[1], strlen (&pos[1]));
330 if (0 > FPRINTF (fp, "%s = %s\n", ent->key, val))
342 if (0 > FPRINTF (fp, "%s\n", ""))
350 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", filename);
351 GNUNET_assert (0 == FCLOSE (fp));
354 cfg->dirty = GNUNET_SYSERR; /* last write failed */
355 return GNUNET_SYSERR;
357 cfg->dirty = GNUNET_NO; /* last write succeeded */
363 * Iterate over all options in the configuration.
365 * @param cfg configuration to inspect
366 * @param iter function to call on each option
367 * @param iter_cls closure for iter
370 GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
371 GNUNET_CONFIGURATION_Iterator iter,
374 struct ConfigSection *spos;
375 struct ConfigEntry *epos;
377 spos = cfg->sections;
380 epos = spos->entries;
383 iter (iter_cls, spos->name, epos->key, epos->val);
392 * Iterate over values of a section in the configuration.
394 * @param cfg configuration to inspect
395 * @param section the section
396 * @param iter function to call on each option
397 * @param iter_cls closure for iter
400 GNUNET_CONFIGURATION_iterate_section_values (const struct
401 GNUNET_CONFIGURATION_Handle *cfg,
403 GNUNET_CONFIGURATION_Iterator iter,
406 struct ConfigSection *spos;
407 struct ConfigEntry *epos;
409 spos = cfg->sections;
410 while ((spos != NULL) && (0 != strcmp (spos->name, section)))
416 epos = spos->entries;
419 iter (iter_cls, spos->name, epos->key, epos->val);
426 * Iterate over all sections in the configuration.
428 * @param cfg configuration to inspect
429 * @param iter function to call on each section
430 * @param iter_cls closure for iter
433 GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle
435 GNUNET_CONFIGURATION_Section_Iterator
436 iter, void *iter_cls)
438 struct ConfigSection *spos;
439 struct ConfigSection *next;
441 next = cfg->sections;
446 iter (iter_cls, spos->name);
451 * Remove the given section and all options in it.
453 * @param cfg configuration to inspect
454 * @param section name of the section to remove
457 GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
460 struct ConfigSection *spos;
461 struct ConfigSection *prev;
462 struct ConfigEntry *ent;
465 spos = cfg->sections;
468 if (0 == strcmp (section, spos->name))
471 cfg->sections = spos->next;
473 prev->next = spos->next;
474 while (NULL != (ent = spos->entries))
476 spos->entries = ent->next;
477 GNUNET_free (ent->key);
478 GNUNET_free_non_null (ent->val);
480 cfg->dirty = GNUNET_YES;
482 GNUNET_free (spos->name);
493 * Copy a configuration value to the given target configuration.
494 * Overwrites existing entries.
496 * @param cls the destination configuration (struct GNUNET_CONFIGURATION_Handle*)
497 * @param section section for the value
498 * @param option option name of the value
499 * @param value value to copy
502 copy_entry (void *cls, const char *section, const char *option,
505 struct GNUNET_CONFIGURATION_Handle *dst = cls;
507 GNUNET_CONFIGURATION_set_value_string (dst, section, option, value);
512 * Duplicate an existing configuration object.
514 * @param cfg configuration to duplicate
515 * @return duplicate configuration
517 struct GNUNET_CONFIGURATION_Handle *
518 GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg)
520 struct GNUNET_CONFIGURATION_Handle *ret;
522 ret = GNUNET_CONFIGURATION_create ();
523 GNUNET_CONFIGURATION_iterate (cfg, ©_entry, ret);
532 * @param section FIXME
533 * @return matching entry, NULL if not found
535 static struct ConfigSection *
536 findSection (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
538 struct ConfigSection *pos;
541 while ((pos != NULL) && (0 != strcasecmp (section, pos->name)))
548 * Find an entry from a configuration.
550 * @param cfg handle to the configuration
551 * @param section section the option is in
552 * @param key the option
553 * @return matching entry, NULL if not found
555 static struct ConfigEntry *
556 findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section,
559 struct ConfigSection *sec;
560 struct ConfigEntry *pos;
562 sec = findSection (cfg, section);
566 while ((pos != NULL) && (0 != strcasecmp (key, pos->key)))
573 * A callback function, compares entries from two configurations
574 * (default against a new configuration) and write the diffs in a
575 * diff-configuration object (the callback object).
577 * @param cls the diff configuration (struct DiffHandle*)
578 * @param section section for the value (of the default conf.)
579 * @param option option name of the value (of the default conf.)
580 * @param value value to copy (of the default conf.)
583 compareEntries (void *cls, const char *section, const char *option,
586 struct DiffHandle *dh = cls;
587 struct ConfigEntry *entNew;
589 entNew = findEntry (dh->cfgDefault, section, option);
590 if ((entNew != NULL) && (strcmp (entNew->val, value) == 0))
592 GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff, section, option, value);
597 * Write only configuration entries that have been changed to configuration file
598 * @param cfgDefault default configuration
599 * @param cfgNew new configuration
600 * @param filename where to write the configuration diff between default and new
601 * @return GNUNET_OK on success, GNUNET_SYSERR on error
604 GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
606 const struct GNUNET_CONFIGURATION_Handle
607 *cfgNew, const char *filename)
610 struct DiffHandle diffHandle;
612 diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
613 diffHandle.cfgDefault = cfgDefault;
614 GNUNET_CONFIGURATION_iterate (cfgNew, compareEntries, &diffHandle);
615 ret = GNUNET_CONFIGURATION_write (diffHandle.cfgDiff, filename);
616 GNUNET_CONFIGURATION_destroy (diffHandle.cfgDiff);
622 * Set a configuration value that should be a string.
624 * @param cfg configuration to update
625 * @param section section of interest
626 * @param option option of interest
627 * @param value value to set
630 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
631 const char *section, const char *option,
634 struct ConfigSection *sec;
635 struct ConfigEntry *e;
637 e = findEntry (cfg, section, option);
640 GNUNET_free_non_null (e->val);
641 e->val = GNUNET_strdup (value);
644 sec = findSection (cfg, section);
647 sec = GNUNET_malloc (sizeof (struct ConfigSection));
648 sec->name = GNUNET_strdup (section);
649 sec->next = cfg->sections;
652 e = GNUNET_malloc (sizeof (struct ConfigEntry));
653 e->key = GNUNET_strdup (option);
654 e->val = GNUNET_strdup (value);
655 e->next = sec->entries;
661 * Set a configuration value that should be a number.
663 * @param cfg configuration to update
664 * @param section section of interest
665 * @param option option of interest
666 * @param number value to set
669 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
670 const char *section, const char *option,
671 unsigned long long number)
675 GNUNET_snprintf (s, 64, "%llu", number);
676 GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s);
681 * Get a configuration value that should be a number.
683 * @param cfg configuration to inspect
684 * @param section section of interest
685 * @param option option of interest
686 * @param number where to store the numeric value of the option
687 * @return GNUNET_OK on success, GNUNET_SYSERR on error
690 GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
691 *cfg, const char *section,
693 unsigned long long *number)
695 struct ConfigEntry *e;
697 e = findEntry (cfg, section, option);
699 return GNUNET_SYSERR;
700 if (1 != SSCANF (e->val, "%llu", number))
701 return GNUNET_SYSERR;
707 * Get a configuration value that should be a relative time.
709 * @param cfg configuration to inspect
710 * @param section section of interest
711 * @param option option of interest
712 * @param time set to the time value stored in the configuration
713 * @return GNUNET_OK on success, GNUNET_SYSERR on error
716 GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
717 *cfg, const char *section,
719 struct GNUNET_TIME_Relative *time)
721 struct ConfigEntry *e;
723 e = findEntry (cfg, section, option);
725 return GNUNET_SYSERR;
727 return GNUNET_STRINGS_fancy_time_to_relative (e->val, time);
732 * Get a configuration value that should be a size in bytes.
734 * @param cfg configuration to inspect
735 * @param section section of interest
736 * @param option option of interest
737 * @param size set to the size in bytes as stored in the configuration
738 * @return GNUNET_OK on success, GNUNET_SYSERR on error
741 GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle
742 *cfg, const char *section,
744 unsigned long long *size)
746 struct ConfigEntry *e;
748 e = findEntry (cfg, section, option);
750 return GNUNET_SYSERR;
751 return GNUNET_STRINGS_fancy_size_to_bytes (e->val, size);
756 * Get a configuration value that should be a string.
758 * @param cfg configuration to inspect
759 * @param section section of interest
760 * @param option option of interest
761 * @param value will be set to a freshly allocated configuration
762 * value, or NULL if option is not specified
763 * @return GNUNET_OK on success, GNUNET_SYSERR on error
766 GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
767 *cfg, const char *section,
768 const char *option, char **value)
770 struct ConfigEntry *e;
772 e = findEntry (cfg, section, option);
773 if ((e == NULL) || (e->val == NULL))
776 return GNUNET_SYSERR;
778 *value = GNUNET_strdup (e->val);
784 * Get a configuration value that should be in a set of
787 * @param cfg configuration to inspect
788 * @param section section of interest
789 * @param option option of interest
790 * @param choices NULL-terminated list of legal values
791 * @param value will be set to an entry in the legal list,
792 * or NULL if option is not specified and no default given
793 * @return GNUNET_OK on success, GNUNET_SYSERR on error
796 GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle
797 *cfg, const char *section,
798 const char *option, const char **choices,
801 struct ConfigEntry *e;
804 e = findEntry (cfg, section, option);
806 return GNUNET_SYSERR;
808 while (choices[i] != NULL)
810 if (0 == strcasecmp (choices[i], e->val))
814 if (choices[i] == NULL)
816 LOG (GNUNET_ERROR_TYPE_ERROR,
817 _("Configuration value '%s' for '%s'"
818 " in section '%s' is not in set of legal choices\n"), e->val, option,
820 return GNUNET_SYSERR;
828 * Test if we have a value for a particular option
829 * @param cfg configuration to inspect
830 * @param section section of interest
831 * @param option option of interest
832 * @return GNUNET_YES if so, GNUNET_NO if not.
835 GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
836 const char *section, const char *option)
838 struct ConfigEntry *e;
840 if ((NULL == (e = findEntry (cfg, section, option))) || (e->val == NULL))
847 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
848 * where either in the "PATHS" section or the environtment
849 * "FOO" is set to "DIRECTORY".
851 * @param cfg configuration to use for path expansion
852 * @param orig string to $-expand (will be freed!)
853 * @return $-expanded string
856 GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle
868 while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0'))
880 GNUNET_CONFIGURATION_get_value_filename (cfg, "PATHS", &orig[1], &prefix))
882 if (NULL == (env = getenv (&orig[1])))
884 orig[i] = DIR_SEPARATOR;
887 prefix = GNUNET_strdup (env);
889 result = GNUNET_malloc (strlen (prefix) + strlen (post) + 2);
890 strcpy (result, prefix);
891 if ((strlen (prefix) == 0) ||
892 ((prefix[strlen (prefix) - 1] != DIR_SEPARATOR) && (strlen (post) > 0)))
893 strcat (result, DIR_SEPARATOR_STR);
894 strcat (result, post);
895 GNUNET_free (prefix);
902 * Get a configuration value that should be a string.
904 * @param cfg configuration to inspect
905 * @param section section of interest
906 * @param option option of interest
907 * @param value will be set to a freshly allocated configuration
908 * value, or NULL if option is not specified
909 * @return GNUNET_OK on success, GNUNET_SYSERR on error
912 GNUNET_CONFIGURATION_get_value_filename (const struct
913 GNUNET_CONFIGURATION_Handle *cfg,
915 const char *option, char **value)
920 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp))
923 return GNUNET_SYSERR;
925 tmp = GNUNET_CONFIGURATION_expand_dollar (cfg, tmp);
926 *value = GNUNET_STRINGS_filename_expand (tmp);
929 return GNUNET_SYSERR;
935 * Get a configuration value that should be in a set of
936 * "GNUNET_YES" or "GNUNET_NO".
938 * @param cfg configuration to inspect
939 * @param section section of interest
940 * @param option option of interest
941 * @return GNUNET_YES, GNUNET_NO or GNUNET_SYSERR
944 GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
945 *cfg, const char *section,
948 static const char *yesno[] = { "YES", "NO", NULL };
953 GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
954 if (ret == GNUNET_SYSERR)
963 * Iterate over the set of filenames stored in a configuration value.
965 * @param cfg configuration to inspect
966 * @param section section of interest
967 * @param option option of interest
968 * @param cb function to call on each filename
969 * @param cb_cls closure for cb
970 * @return number of filenames iterated over, -1 on error
973 GNUNET_CONFIGURATION_iterate_value_filenames (const struct
974 GNUNET_CONFIGURATION_Handle *cfg,
977 GNUNET_FileNameCallback cb,
987 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list))
989 GNUNET_assert (list != NULL);
994 while (pos[0] == ' ')
996 if (strlen (pos) == 0)
999 while ((end[0] != ' ') && (end[0] != '\0'))
1007 memmove (end, &end[1], strlen (&end[1]) + 1);
1009 /* illegal, but just keep it */
1012 /* illegal, but just ignore that there was a '/' */
1020 if (strlen (pos) > 0)
1023 if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos)))
1025 ret = GNUNET_SYSERR;
1041 * @param value FIXME
1045 escape_name (const char *value)
1051 escaped = GNUNET_malloc (strlen (value) * 2 + 1);
1052 memset (escaped, 0, strlen (value) * 2 + 1);
1055 while (rpos[0] != '\0')
1078 * @param cls string we compare with (const char*)
1079 * @param fn filename we are currently looking at
1080 * @return GNUNET_OK if the names do not match, GNUNET_SYSERR if they do
1083 test_match (void *cls, const char *fn)
1085 const char *of = cls;
1087 return (0 == strcmp (of, fn)) ? GNUNET_SYSERR : GNUNET_OK;
1092 * Append a filename to a configuration value that
1093 * represents a list of filenames
1095 * @param cfg configuration to update
1096 * @param section section of interest
1097 * @param option option of interest
1098 * @param value filename to append
1099 * @return GNUNET_OK on success,
1100 * GNUNET_NO if the filename already in the list
1101 * GNUNET_SYSERR on error
1104 GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
1105 *cfg, const char *section,
1113 if (GNUNET_SYSERR ==
1114 GNUNET_CONFIGURATION_iterate_value_filenames (cfg, section, option,
1117 return GNUNET_NO; /* already exists */
1119 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
1120 old = GNUNET_strdup ("");
1121 escaped = escape_name (value);
1122 nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2);
1124 if (strlen (old) > 0)
1126 strcat (nw, escaped);
1127 GNUNET_CONFIGURATION_set_value_string (cfg, section, option, nw);
1130 GNUNET_free (escaped);
1136 * Remove a filename from a configuration value that
1137 * represents a list of filenames
1139 * @param cfg configuration to update
1140 * @param section section of interest
1141 * @param option option of interest
1142 * @param value filename to remove
1143 * @return GNUNET_OK on success,
1144 * GNUNET_NO if the filename is not in the list,
1145 * GNUNET_SYSERR on error
1148 GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle
1149 *cfg, const char *section,
1160 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list))
1162 match = escape_name (value);
1166 while (pos[0] == ' ')
1168 if (strlen (pos) == 0)
1171 while ((end[0] != ' ') && (end[0] != '\0'))
1182 /* illegal, but just keep it */
1185 /* illegal, but just ignore that there was a '/' */
1193 if (0 == strcmp (pos, match))
1196 memmove (pos, &end[1], strlen (&end[1]) + 1);
1204 GNUNET_CONFIGURATION_set_value_string (cfg, section, option, list);
1206 GNUNET_free (match);
1215 GNUNET_free (match);
1221 * Wrapper around GNUNET_CONFIGURATION_parse.
1223 * @param cls the cfg
1224 * @param filename file to parse
1225 * @return GNUNET_OK on success
1228 parse_configuration_file (void *cls, const char *filename)
1230 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
1233 ret = GNUNET_CONFIGURATION_parse (cfg, filename);
1239 * Load configuration (starts with defaults, then loads
1240 * system-specific configuration).
1242 * @param cfg configuration to update
1243 * @param filename name of the configuration file, NULL to load defaults
1244 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1247 GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
1248 const char *filename)
1253 ipath = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
1255 return GNUNET_SYSERR;
1257 GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d");
1258 GNUNET_free (ipath);
1259 if (GNUNET_SYSERR ==
1260 GNUNET_DISK_directory_scan (baseconfig, &parse_configuration_file, cfg))
1262 GNUNET_free (baseconfig);
1263 return GNUNET_SYSERR; /* no configuration at all found */
1265 GNUNET_free (baseconfig);
1266 if ((filename != NULL) &&
1267 (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, filename)))
1269 /* specified configuration not found */
1270 return GNUNET_SYSERR;
1273 GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) &&
1275 GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG",
1278 GNUNET_CONFIGURATION_have_value (cfg, "TESTING", "WEAKRANDOM")) &&
1280 GNUNET_CONFIGURATION_get_value_yesno (cfg, "TESTING", "WEAKRANDOM")))
1281 GNUNET_CRYPTO_random_disable_entropy_gathering ();
1287 /* end of configuration.c */