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_configuration_lib.h"
31 #include "gnunet_crypto_lib.h"
32 #include "gnunet_disk_lib.h"
33 #include "gnunet_os_lib.h"
34 #include "gnunet_strings_lib.h"
36 #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
38 #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
41 * @brief configuration entry
47 * This is a linked list.
49 struct ConfigEntry *next;
57 * current, commited value
64 * @brief configuration section
69 * This is a linked list.
71 struct ConfigSection *next;
74 * entries in the section
76 struct ConfigEntry *entries;
86 * @brief configuration data
88 struct GNUNET_CONFIGURATION_Handle
91 * Configuration sections.
93 struct ConfigSection *sections;
96 * Modification indication since last save
97 * GNUNET_NO if clean, GNUNET_YES if dirty,
98 * GNUNET_SYSERR on error (i.e. last save failed)
106 * Used for diffing a configuration object against
111 const struct GNUNET_CONFIGURATION_Handle *cfgDefault;
112 struct GNUNET_CONFIGURATION_Handle *cfgDiff;
118 * Create a GNUNET_CONFIGURATION_Handle.
120 * @return fresh configuration object
122 struct GNUNET_CONFIGURATION_Handle *
123 GNUNET_CONFIGURATION_create ()
125 return GNUNET_malloc (sizeof (struct GNUNET_CONFIGURATION_Handle));
130 * Destroy configuration object.
132 * @param cfg configuration to destroy
135 GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
137 struct ConfigSection *sec;
139 while (NULL != (sec = cfg->sections))
140 GNUNET_CONFIGURATION_remove_section (cfg, sec->name);
146 * Parse a configuration file, add all of the options in the
147 * file to the configuration environment.
149 * @param cfg configuration to update
150 * @param filename name of the configuration file
151 * @return GNUNET_OK on success, GNUNET_SYSERR on error
154 GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
155 const char *filename)
169 fn = GNUNET_STRINGS_filename_expand (filename);
171 return GNUNET_SYSERR;
172 dirty = cfg->dirty; /* back up value! */
173 if (NULL == (fp = FOPEN (fn, "r")))
175 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn);
177 return GNUNET_SYSERR;
181 section = GNUNET_strdup ("");
182 memset (line, 0, 256);
184 while (NULL != fgets (line, 255, fp))
187 for (i = 0; i < 255; i++)
190 if (line[0] == '\n' || line[0] == '#' || line[0] == '%'
194 for (i = 0; (i < 255 && line[i] != 0); i++)
195 if (line[i] != ' ' && line[i] != '\n' && line[i] != '\r')
199 /* remove tailing whitespace */
200 for (i = strlen (line) - 1;
201 (i >= 0) && (isspace ((unsigned char) line[i])); i--)
203 if (1 == sscanf (line, "@INLINE@ %191[^\n]", value))
206 if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, value))
207 ret = GNUNET_SYSERR; /* failed to parse included config */
209 else if (1 == sscanf (line, "[%99[^]]]", value))
212 GNUNET_free (section);
213 section = GNUNET_strdup (value);
215 else if (2 == sscanf (line, " %63[^= ] = %191[^\n]", tag, value))
219 i = strlen (value) - 1;
220 while ((i >= 0) && (isspace ((unsigned char) value[i])))
227 while ((value[i] != '\0') && (value[i] != '"'))
237 GNUNET_CONFIGURATION_set_value_string (cfg, section, tag,
240 else if (1 == sscanf (line, " %63[^= ] =[^\n]", tag))
243 GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, "");
248 LOG (GNUNET_ERROR_TYPE_WARNING,
249 _("Syntax error in configuration file `%s' at line %u.\n"),
255 GNUNET_assert (0 == fclose (fp));
256 /* restore dirty flag - anything we set in the meantime
259 GNUNET_free (section);
265 * Test if there are configuration options that were
266 * changed since the last save.
268 * @param cfg configuration to inspect
269 * @return GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error (i.e. last save failed)
272 GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg)
279 * Write configuration file.
281 * @param cfg configuration to write
282 * @param filename where to write the configuration
283 * @return GNUNET_OK on success, GNUNET_SYSERR on error
286 GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
287 const char *filename)
289 struct ConfigSection *sec;
290 struct ConfigEntry *ent;
297 fn = GNUNET_STRINGS_filename_expand (filename);
299 return GNUNET_SYSERR;
300 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn))
303 return GNUNET_SYSERR;
305 if (NULL == (fp = FOPEN (fn, "w")))
307 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn);
309 return GNUNET_SYSERR;
316 if (0 > fprintf (fp, "[%s]\n", sec->name))
324 if (ent->val != NULL)
326 val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
327 strcpy (val, ent->val);
328 while (NULL != (pos = strstr (val, "\n")))
330 memmove (&pos[2], &pos[1], strlen (&pos[1]));
334 if (0 > fprintf (fp, "%s = %s\n", ent->key, val))
346 if (0 > fprintf (fp, "\n"))
354 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", filename);
355 GNUNET_assert (0 == fclose (fp));
358 cfg->dirty = GNUNET_SYSERR; /* last write failed */
359 return GNUNET_SYSERR;
361 cfg->dirty = GNUNET_NO; /* last write succeeded */
367 * Iterate over all options in the configuration.
369 * @param cfg configuration to inspect
370 * @param iter function to call on each option
371 * @param iter_cls closure for iter
374 GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
375 GNUNET_CONFIGURATION_Iterator iter,
378 struct ConfigSection *spos;
379 struct ConfigEntry *epos;
381 spos = cfg->sections;
384 epos = spos->entries;
387 iter (iter_cls, spos->name, epos->key, epos->val);
396 * Iterate over values of a section in the configuration.
398 * @param cfg configuration to inspect
399 * @param section the section
400 * @param iter function to call on each option
401 * @param iter_cls closure for iter
404 GNUNET_CONFIGURATION_iterate_section_values (const struct
405 GNUNET_CONFIGURATION_Handle *cfg,
407 GNUNET_CONFIGURATION_Iterator
408 iter, void *iter_cls)
410 struct ConfigSection *spos;
411 struct ConfigEntry *epos;
413 spos = cfg->sections;
414 while ((spos != NULL) && (0 != strcmp (spos->name, section)))
420 epos = spos->entries;
423 iter (iter_cls, spos->name, epos->key, epos->val);
430 * Iterate over all sections in the configuration.
432 * @param cfg configuration to inspect
433 * @param iter function to call on each section
434 * @param iter_cls closure for iter
437 GNUNET_CONFIGURATION_iterate_sections (const struct
438 GNUNET_CONFIGURATION_Handle *cfg,
439 GNUNET_CONFIGURATION_Section_Iterator
440 iter, void *iter_cls)
442 struct ConfigSection *spos;
443 struct ConfigSection *next;
445 next = cfg->sections;
450 iter (iter_cls, spos->name);
455 * Remove the given section and all options in it.
457 * @param cfg configuration to inspect
458 * @param section name of the section to remove
461 GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
464 struct ConfigSection *spos;
465 struct ConfigSection *prev;
466 struct ConfigEntry *ent;
469 spos = cfg->sections;
472 if (0 == strcmp (section, spos->name))
475 cfg->sections = spos->next;
477 prev->next = spos->next;
478 while (NULL != (ent = spos->entries))
480 spos->entries = ent->next;
481 GNUNET_free (ent->key);
482 GNUNET_free_non_null (ent->val);
484 cfg->dirty = GNUNET_YES;
486 GNUNET_free (spos->name);
497 * Copy a configuration value to the given target configuration.
498 * Overwrites existing entries.
500 * @param cls the destination configuration (struct GNUNET_CONFIGURATION_Handle*)
501 * @param section section for the value
502 * @param option option name of the value
503 * @param value value to copy
506 copy_entry (void *cls, const char *section, const char *option,
509 struct GNUNET_CONFIGURATION_Handle *dst = cls;
511 GNUNET_CONFIGURATION_set_value_string (dst, section, option, value);
516 * Duplicate an existing configuration object.
518 * @param cfg configuration to duplicate
519 * @return duplicate configuration
521 struct GNUNET_CONFIGURATION_Handle *
522 GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg)
524 struct GNUNET_CONFIGURATION_Handle *ret;
526 ret = GNUNET_CONFIGURATION_create ();
527 GNUNET_CONFIGURATION_iterate (cfg, ©_entry, ret);
536 * @param section FIXME
537 * @return matching entry, NULL if not found
539 static struct ConfigSection *
540 findSection (const struct GNUNET_CONFIGURATION_Handle *cfg,
543 struct ConfigSection *pos;
546 while ((pos != NULL) && (0 != strcasecmp (section, pos->name)))
553 * Find an entry from a configuration.
555 * @param cfg handle to the configuration
556 * @param section section the option is in
557 * @param key the option
558 * @return matching entry, NULL if not found
560 static struct ConfigEntry *
561 findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section,
564 struct ConfigSection *sec;
565 struct ConfigEntry *pos;
567 sec = findSection (cfg, section);
571 while ((pos != NULL) && (0 != strcasecmp (key, pos->key)))
578 * A callback function, compares entries from two configurations
579 * (default against a new configuration) and write the diffs in a
580 * diff-configuration object (the callback object).
582 * @param cls the diff configuration (struct DiffHandle*)
583 * @param section section for the value (of the default conf.)
584 * @param option option name of the value (of the default conf.)
585 * @param value value to copy (of the default conf.)
588 compareEntries (void *cls, const char *section, const char *option,
591 struct DiffHandle *dh = cls;
592 struct ConfigEntry *entNew;
594 entNew = findEntry (dh->cfgDefault, section, option);
595 if ((entNew != NULL) && (strcmp (entNew->val, value) == 0))
597 GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff, section, option, value);
602 * Write only configuration entries that have been changed to configuration file
603 * @param cfgDefault default configuration
604 * @param cfgNew new configuration
605 * @param filename where to write the configuration diff between default and new
606 * @return GNUNET_OK on success, GNUNET_SYSERR on error
609 GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
611 const struct GNUNET_CONFIGURATION_Handle
612 *cfgNew, const char *filename)
615 struct DiffHandle diffHandle;
617 diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
618 diffHandle.cfgDefault = cfgDefault;
619 GNUNET_CONFIGURATION_iterate (cfgNew, compareEntries, &diffHandle);
620 ret = GNUNET_CONFIGURATION_write (diffHandle.cfgDiff, filename);
621 GNUNET_CONFIGURATION_destroy (diffHandle.cfgDiff);
627 * Set a configuration value that should be a string.
629 * @param cfg configuration to update
630 * @param section section of interest
631 * @param option option of interest
632 * @param value value to set
635 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle
636 *cfg, const char *section,
637 const char *option, const char *value)
639 struct ConfigSection *sec;
640 struct ConfigEntry *e;
642 e = findEntry (cfg, section, option);
645 GNUNET_free_non_null (e->val);
646 e->val = GNUNET_strdup (value);
649 sec = findSection (cfg, section);
652 sec = GNUNET_malloc (sizeof (struct ConfigSection));
653 sec->name = GNUNET_strdup (section);
654 sec->next = cfg->sections;
657 e = GNUNET_malloc (sizeof (struct ConfigEntry));
658 e->key = GNUNET_strdup (option);
659 e->val = GNUNET_strdup (value);
660 e->next = sec->entries;
666 * Set a configuration value that should be a number.
668 * @param cfg configuration to update
669 * @param section section of interest
670 * @param option option of interest
671 * @param number value to set
674 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle
675 *cfg, const char *section,
677 unsigned long long number)
681 GNUNET_snprintf (s, 64, "%llu", number);
682 GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s);
687 * Get a configuration value that should be a number.
689 * @param cfg configuration to inspect
690 * @param section section of interest
691 * @param option option of interest
692 * @param number where to store the numeric value of the option
693 * @return GNUNET_OK on success, GNUNET_SYSERR on error
696 GNUNET_CONFIGURATION_get_value_number (const struct
697 GNUNET_CONFIGURATION_Handle *cfg,
700 unsigned long long *number)
702 struct ConfigEntry *e;
704 e = findEntry (cfg, section, option);
706 return GNUNET_SYSERR;
707 if (1 != SSCANF (e->val, "%llu", number))
708 return GNUNET_SYSERR;
714 * Get a configuration value that should be a relative time.
716 * @param cfg configuration to inspect
717 * @param section section of interest
718 * @param option option of interest
719 * @param time set to the time value stored in the configuration
720 * @return GNUNET_OK on success, GNUNET_SYSERR on error
723 GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
724 *cfg, const char *section,
726 struct GNUNET_TIME_Relative *time)
728 struct ConfigEntry *e;
729 unsigned long long num;
731 e = findEntry (cfg, section, option);
733 return GNUNET_SYSERR;
734 if ((0 == strcasecmp (e->val, "infinity")) ||
735 (0 == strcasecmp (e->val, "forever")))
737 *time = GNUNET_TIME_UNIT_FOREVER_REL;
740 if (1 != SSCANF (e->val, "%llu", &num))
741 return GNUNET_SYSERR;
742 time->rel_value = (uint64_t) num;
748 * Get a configuration value that should be a string.
750 * @param cfg configuration to inspect
751 * @param section section of interest
752 * @param option option of interest
753 * @param value will be set to a freshly allocated configuration
754 * value, or NULL if option is not specified
755 * @return GNUNET_OK on success, GNUNET_SYSERR on error
758 GNUNET_CONFIGURATION_get_value_string (const struct
759 GNUNET_CONFIGURATION_Handle *cfg,
761 const char *option, char **value)
763 struct ConfigEntry *e;
765 e = findEntry (cfg, section, option);
766 if ((e == NULL) || (e->val == NULL))
769 return GNUNET_SYSERR;
771 *value = GNUNET_strdup (e->val);
777 * Get a configuration value that should be in a set of
780 * @param cfg configuration to inspect
781 * @param section section of interest
782 * @param option option of interest
783 * @param choices NULL-terminated list of legal values
784 * @param value will be set to an entry in the legal list,
785 * or NULL if option is not specified and no default given
786 * @return GNUNET_OK on success, GNUNET_SYSERR on error
789 GNUNET_CONFIGURATION_get_value_choice (const struct
790 GNUNET_CONFIGURATION_Handle *cfg,
793 const char **choices,
796 struct ConfigEntry *e;
799 e = findEntry (cfg, section, option);
801 return GNUNET_SYSERR;
803 while (choices[i] != NULL)
805 if (0 == strcasecmp (choices[i], e->val))
809 if (choices[i] == NULL)
811 LOG (GNUNET_ERROR_TYPE_ERROR,
812 _("Configuration value '%s' for '%s'"
813 " in section '%s' is not in set of legal choices\n"), e->val,
815 return GNUNET_SYSERR;
823 * Test if we have a value for a particular option
824 * @param cfg configuration to inspect
825 * @param section section of interest
826 * @param option option of interest
827 * @return GNUNET_YES if so, GNUNET_NO if not.
830 GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle
831 *cfg, const char *section,
834 struct ConfigEntry *e;
836 if ((NULL == (e = findEntry (cfg, section, option))) || (e->val == NULL))
843 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
844 * where either in the "PATHS" section or the environtment
845 * "FOO" is set to "DIRECTORY".
847 * @param cfg configuration to use for path expansion
848 * @param orig string to $-expand (will be freed!)
849 * @return $-expanded string
852 GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle
864 while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0'))
876 GNUNET_CONFIGURATION_get_value_filename (cfg, "PATHS", &orig[1],
879 if (NULL == (env = getenv (&orig[1])))
881 orig[i] = DIR_SEPARATOR;
884 prefix = GNUNET_strdup (env);
886 result = GNUNET_malloc (strlen (prefix) + strlen (post) + 2);
887 strcpy (result, prefix);
888 if ((strlen (prefix) == 0) ||
889 ((prefix[strlen (prefix) - 1] != DIR_SEPARATOR) && (strlen (post) > 0)))
890 strcat (result, DIR_SEPARATOR_STR);
891 strcat (result, post);
892 GNUNET_free (prefix);
899 * Get a configuration value that should be a string.
901 * @param cfg configuration to inspect
902 * @param section section of interest
903 * @param option option of interest
904 * @param value will be set to a freshly allocated configuration
905 * value, or NULL if option is not specified
906 * @return GNUNET_OK on success, GNUNET_SYSERR on error
909 GNUNET_CONFIGURATION_get_value_filename (const struct
910 GNUNET_CONFIGURATION_Handle *cfg,
912 const char *option, char **value)
917 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp))
920 return GNUNET_SYSERR;
922 tmp = GNUNET_CONFIGURATION_expand_dollar (cfg, tmp);
923 *value = GNUNET_STRINGS_filename_expand (tmp);
926 return GNUNET_SYSERR;
932 * Get a configuration value that should be in a set of
933 * "GNUNET_YES" or "GNUNET_NO".
935 * @param cfg configuration to inspect
936 * @param section section of interest
937 * @param option option of interest
938 * @return GNUNET_YES, GNUNET_NO or GNUNET_SYSERR
941 GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
942 *cfg, const char *section,
945 static const char *yesno[] = { "YES", "NO", NULL };
950 GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
951 if (ret == GNUNET_SYSERR)
960 * Iterate over the set of filenames stored in a configuration value.
962 * @param cfg configuration to inspect
963 * @param section section of interest
964 * @param option option of interest
965 * @param cb function to call on each filename
966 * @param cb_cls closure for cb
967 * @return number of filenames iterated over, -1 on error
970 GNUNET_CONFIGURATION_iterate_value_filenames (const struct
971 GNUNET_CONFIGURATION_Handle
972 *cfg, const char *section,
974 GNUNET_FileNameCallback cb,
984 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list))
986 GNUNET_assert (list != NULL);
991 while (pos[0] == ' ')
993 if (strlen (pos) == 0)
996 while ((end[0] != ' ') && (end[0] != '\0'))
1004 memmove (end, &end[1], strlen (&end[1]) + 1);
1006 /* illegal, but just keep it */
1009 /* illegal, but just ignore that there was a '/' */
1017 if (strlen (pos) > 0)
1020 if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos)))
1022 ret = GNUNET_SYSERR;
1038 * @param value FIXME
1042 escape_name (const char *value)
1048 escaped = GNUNET_malloc (strlen (value) * 2 + 1);
1049 memset (escaped, 0, strlen (value) * 2 + 1);
1052 while (rpos[0] != '\0')
1075 * @param cls string we compare with (const char*)
1076 * @param fn filename we are currently looking at
1077 * @return GNUNET_OK if the names do not match, GNUNET_SYSERR if they do
1080 test_match (void *cls, const char *fn)
1082 const char *of = cls;
1084 return (0 == strcmp (of, fn)) ? GNUNET_SYSERR : GNUNET_OK;
1089 * Append a filename to a configuration value that
1090 * represents a list of filenames
1092 * @param cfg configuration to update
1093 * @param section section of interest
1094 * @param option option of interest
1095 * @param value filename to append
1096 * @return GNUNET_OK on success,
1097 * GNUNET_NO if the filename already in the list
1098 * GNUNET_SYSERR on error
1101 GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
1102 *cfg, const char *section,
1110 if (GNUNET_SYSERR ==
1111 GNUNET_CONFIGURATION_iterate_value_filenames (cfg, section, option,
1114 return GNUNET_NO; /* already exists */
1116 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
1117 old = GNUNET_strdup ("");
1118 escaped = escape_name (value);
1119 nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2);
1121 if (strlen (old) > 0)
1123 strcat (nw, escaped);
1124 GNUNET_CONFIGURATION_set_value_string (cfg, section, option, nw);
1127 GNUNET_free (escaped);
1133 * Remove a filename from a configuration value that
1134 * represents a list of filenames
1136 * @param cfg configuration to update
1137 * @param section section of interest
1138 * @param option option of interest
1139 * @param value filename to remove
1140 * @return GNUNET_OK on success,
1141 * GNUNET_NO if the filename is not in the list,
1142 * GNUNET_SYSERR on error
1145 GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle
1146 *cfg, const char *section,
1157 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list))
1159 match = escape_name (value);
1163 while (pos[0] == ' ')
1165 if (strlen (pos) == 0)
1168 while ((end[0] != ' ') && (end[0] != '\0'))
1179 /* illegal, but just keep it */
1182 /* illegal, but just ignore that there was a '/' */
1190 if (0 == strcmp (pos, match))
1193 memmove (pos, &end[1], strlen (&end[1]) + 1);
1201 GNUNET_CONFIGURATION_set_value_string (cfg, section, option, list);
1203 GNUNET_free (match);
1212 GNUNET_free (match);
1218 * Load configuration (starts with defaults, then loads
1219 * system-specific configuration).
1221 * @param cfg configuration to update
1222 * @param filename name of the configuration file, NULL to load defaults
1223 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1226 GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
1227 const char *filename)
1232 ipath = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
1234 return GNUNET_SYSERR;
1236 GNUNET_asprintf (&baseconfig, "%s%s%s", ipath, DIR_SEPARATOR_STR,
1238 GNUNET_free (ipath);
1239 if ((GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, baseconfig)) ||
1240 (!((filename == NULL) ||
1241 (GNUNET_OK == GNUNET_CONFIGURATION_parse (cfg, filename)))))
1243 GNUNET_free (baseconfig);
1244 return (filename == NULL) ? GNUNET_OK : GNUNET_SYSERR;
1246 GNUNET_free (baseconfig);
1248 GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) &&
1250 GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG",
1253 GNUNET_CONFIGURATION_have_value (cfg, "TESTING", "WEAKRANDOM")) &&
1255 GNUNET_CONFIGURATION_get_value_yesno (cfg, "TESTING", "WEAKRANDOM")))
1256 GNUNET_CRYPTO_random_disable_entropy_gathering ();
1262 /* end of configuration.c */