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] == '%'
192 for (i = 0; (i < 255 && line[i] != 0); i++)
193 if (line[i] != ' ' && line[i] != '\n' && line[i] != '\r')
197 /* remove tailing whitespace */
198 for (i = strlen (line) - 1;
199 (i >= 0) && (isspace ((unsigned char) line[i])); i--)
201 if (1 == sscanf (line, "@INLINE@ %191[^\n]", value))
204 if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, value))
205 ret = GNUNET_SYSERR; /* failed to parse included config */
207 else if (1 == sscanf (line, "[%99[^]]]", value))
210 GNUNET_free (section);
211 section = GNUNET_strdup (value);
213 else if (2 == sscanf (line, " %63[^= ] = %191[^\n]", tag, value))
217 i = strlen (value) - 1;
218 while ((i >= 0) && (isspace ((unsigned char) value[i])))
225 while ((value[i] != '\0') && (value[i] != '"'))
235 GNUNET_CONFIGURATION_set_value_string (cfg, section, tag,
238 else if (1 == sscanf (line, " %63[^= ] =[^\n]", tag))
241 GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, "");
246 LOG (GNUNET_ERROR_TYPE_WARNING,
247 _("Syntax error in configuration file `%s' at line %u.\n"),
253 GNUNET_assert (0 == fclose (fp));
254 /* restore dirty flag - anything we set in the meantime
257 GNUNET_free (section);
263 * Test if there are configuration options that were
264 * changed since the last save.
266 * @param cfg configuration to inspect
267 * @return GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error (i.e. last save failed)
270 GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg)
277 * Write configuration file.
279 * @param cfg configuration to write
280 * @param filename where to write the configuration
281 * @return GNUNET_OK on success, GNUNET_SYSERR on error
284 GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
285 const char *filename)
287 struct ConfigSection *sec;
288 struct ConfigEntry *ent;
295 fn = GNUNET_STRINGS_filename_expand (filename);
297 return GNUNET_SYSERR;
298 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn))
301 return GNUNET_SYSERR;
303 if (NULL == (fp = FOPEN (fn, "w")))
305 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn);
307 return GNUNET_SYSERR;
314 if (0 > fprintf (fp, "[%s]\n", sec->name))
322 if (ent->val != NULL)
324 val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
325 strcpy (val, ent->val);
326 while (NULL != (pos = strstr (val, "\n")))
328 memmove (&pos[2], &pos[1], strlen (&pos[1]));
332 if (0 > fprintf (fp, "%s = %s\n", ent->key, val))
344 if (0 > fprintf (fp, "\n"))
352 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", filename);
353 GNUNET_assert (0 == fclose (fp));
356 cfg->dirty = GNUNET_SYSERR; /* last write failed */
357 return GNUNET_SYSERR;
359 cfg->dirty = GNUNET_NO; /* last write succeeded */
365 * Iterate over all options in the configuration.
367 * @param cfg configuration to inspect
368 * @param iter function to call on each option
369 * @param iter_cls closure for iter
372 GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
373 GNUNET_CONFIGURATION_Iterator iter,
376 struct ConfigSection *spos;
377 struct ConfigEntry *epos;
379 spos = cfg->sections;
382 epos = spos->entries;
385 iter (iter_cls, spos->name, epos->key, epos->val);
394 * Iterate over values of a section in the configuration.
396 * @param cfg configuration to inspect
397 * @param section the section
398 * @param iter function to call on each option
399 * @param iter_cls closure for iter
402 GNUNET_CONFIGURATION_iterate_section_values (const struct
403 GNUNET_CONFIGURATION_Handle *cfg,
405 GNUNET_CONFIGURATION_Iterator
406 iter, void *iter_cls)
408 struct ConfigSection *spos;
409 struct ConfigEntry *epos;
411 spos = cfg->sections;
412 while ((spos != NULL) && (0 != strcmp (spos->name, section)))
418 epos = spos->entries;
421 iter (iter_cls, spos->name, epos->key, epos->val);
428 * Iterate over all sections in the configuration.
430 * @param cfg configuration to inspect
431 * @param iter function to call on each section
432 * @param iter_cls closure for iter
435 GNUNET_CONFIGURATION_iterate_sections (const struct
436 GNUNET_CONFIGURATION_Handle *cfg,
437 GNUNET_CONFIGURATION_Section_Iterator
438 iter, void *iter_cls)
440 struct ConfigSection *spos;
441 struct ConfigSection *next;
443 next = cfg->sections;
448 iter (iter_cls, spos->name);
453 * Remove the given section and all options in it.
455 * @param cfg configuration to inspect
456 * @param section name of the section to remove
459 GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
462 struct ConfigSection *spos;
463 struct ConfigSection *prev;
464 struct ConfigEntry *ent;
467 spos = cfg->sections;
470 if (0 == strcmp (section, spos->name))
473 cfg->sections = spos->next;
475 prev->next = spos->next;
476 while (NULL != (ent = spos->entries))
478 spos->entries = ent->next;
479 GNUNET_free (ent->key);
480 GNUNET_free_non_null (ent->val);
482 cfg->dirty = GNUNET_YES;
484 GNUNET_free (spos->name);
495 * Copy a configuration value to the given target configuration.
496 * Overwrites existing entries.
498 * @param cls the destination configuration (struct GNUNET_CONFIGURATION_Handle*)
499 * @param section section for the value
500 * @param option option name of the value
501 * @param value value to copy
504 copy_entry (void *cls, const char *section, const char *option,
507 struct GNUNET_CONFIGURATION_Handle *dst = cls;
509 GNUNET_CONFIGURATION_set_value_string (dst, section, option, value);
514 * Duplicate an existing configuration object.
516 * @param cfg configuration to duplicate
517 * @return duplicate configuration
519 struct GNUNET_CONFIGURATION_Handle *
520 GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg)
522 struct GNUNET_CONFIGURATION_Handle *ret;
524 ret = GNUNET_CONFIGURATION_create ();
525 GNUNET_CONFIGURATION_iterate (cfg, ©_entry, ret);
534 * @param section FIXME
535 * @return matching entry, NULL if not found
537 static struct ConfigSection *
538 findSection (const struct GNUNET_CONFIGURATION_Handle *cfg,
541 struct ConfigSection *pos;
544 while ((pos != NULL) && (0 != strcasecmp (section, pos->name)))
551 * Find an entry from a configuration.
553 * @param cfg handle to the configuration
554 * @param section section the option is in
555 * @param key the option
556 * @return matching entry, NULL if not found
558 static struct ConfigEntry *
559 findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section,
562 struct ConfigSection *sec;
563 struct ConfigEntry *pos;
565 sec = findSection (cfg, section);
569 while ((pos != NULL) && (0 != strcasecmp (key, pos->key)))
576 * A callback function, compares entries from two configurations
577 * (default against a new configuration) and write the diffs in a
578 * diff-configuration object (the callback object).
580 * @param cls the diff configuration (struct DiffHandle*)
581 * @param section section for the value (of the default conf.)
582 * @param option option name of the value (of the default conf.)
583 * @param value value to copy (of the default conf.)
586 compareEntries (void *cls, const char *section, const char *option,
589 struct DiffHandle *dh = cls;
590 struct ConfigEntry *entNew;
592 entNew = findEntry (dh->cfgDefault, section, option);
593 if ((entNew != NULL) && (strcmp (entNew->val, value) == 0))
595 GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff, section, option, value);
600 * Write only configuration entries that have been changed to configuration file
601 * @param cfgDefault default configuration
602 * @param cfgNew new configuration
603 * @param filename where to write the configuration diff between default and new
604 * @return GNUNET_OK on success, GNUNET_SYSERR on error
607 GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
609 const struct GNUNET_CONFIGURATION_Handle
610 *cfgNew, const char *filename)
613 struct DiffHandle diffHandle;
615 diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
616 diffHandle.cfgDefault = cfgDefault;
617 GNUNET_CONFIGURATION_iterate (cfgNew, compareEntries, &diffHandle);
618 ret = GNUNET_CONFIGURATION_write (diffHandle.cfgDiff, filename);
619 GNUNET_CONFIGURATION_destroy (diffHandle.cfgDiff);
625 * Set a configuration value that should be a string.
627 * @param cfg configuration to update
628 * @param section section of interest
629 * @param option option of interest
630 * @param value value to set
633 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle
634 *cfg, const char *section,
635 const char *option, const char *value)
637 struct ConfigSection *sec;
638 struct ConfigEntry *e;
640 e = findEntry (cfg, section, option);
643 GNUNET_free_non_null (e->val);
644 e->val = GNUNET_strdup (value);
647 sec = findSection (cfg, section);
650 sec = GNUNET_malloc (sizeof (struct ConfigSection));
651 sec->name = GNUNET_strdup (section);
652 sec->next = cfg->sections;
655 e = GNUNET_malloc (sizeof (struct ConfigEntry));
656 e->key = GNUNET_strdup (option);
657 e->val = GNUNET_strdup (value);
658 e->next = sec->entries;
664 * Set a configuration value that should be a number.
666 * @param cfg configuration to update
667 * @param section section of interest
668 * @param option option of interest
669 * @param number value to set
672 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle
673 *cfg, const char *section,
675 unsigned long long number)
679 GNUNET_snprintf (s, 64, "%llu", number);
680 GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s);
685 * Get a configuration value that should be a number.
687 * @param cfg configuration to inspect
688 * @param section section of interest
689 * @param option option of interest
690 * @param number where to store the numeric value of the option
691 * @return GNUNET_OK on success, GNUNET_SYSERR on error
694 GNUNET_CONFIGURATION_get_value_number (const struct
695 GNUNET_CONFIGURATION_Handle *cfg,
698 unsigned long long *number)
700 struct ConfigEntry *e;
702 e = findEntry (cfg, section, option);
704 return GNUNET_SYSERR;
705 if (1 != SSCANF (e->val, "%llu", number))
706 return GNUNET_SYSERR;
712 * Get a configuration value that should be a relative time.
714 * @param cfg configuration to inspect
715 * @param section section of interest
716 * @param option option of interest
717 * @param time set to the time value stored in the configuration
718 * @return GNUNET_OK on success, GNUNET_SYSERR on error
721 GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
722 *cfg, const char *section,
724 struct GNUNET_TIME_Relative *time)
726 struct ConfigEntry *e;
728 e = findEntry (cfg, section, option);
730 return GNUNET_SYSERR;
732 return GNUNET_STRINGS_fancy_time_to_relative (e->val,
738 * Get a configuration value that should be a size in bytes.
740 * @param cfg configuration to inspect
741 * @param section section of interest
742 * @param option option of interest
743 * @param size set to the size in bytes as stored in the configuration
744 * @return GNUNET_OK on success, GNUNET_SYSERR on error
747 GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle
748 *cfg, const char *section,
750 unsigned long long *size)
752 struct ConfigEntry *e;
754 e = findEntry (cfg, section, option);
756 return GNUNET_SYSERR;
757 return GNUNET_STRINGS_fancy_size_to_bytes (e->val,
763 * Get a configuration value that should be a string.
765 * @param cfg configuration to inspect
766 * @param section section of interest
767 * @param option option of interest
768 * @param value will be set to a freshly allocated configuration
769 * value, or NULL if option is not specified
770 * @return GNUNET_OK on success, GNUNET_SYSERR on error
773 GNUNET_CONFIGURATION_get_value_string (const struct
774 GNUNET_CONFIGURATION_Handle *cfg,
776 const char *option, char **value)
778 struct ConfigEntry *e;
780 e = findEntry (cfg, section, option);
781 if ((e == NULL) || (e->val == NULL))
784 return GNUNET_SYSERR;
786 *value = GNUNET_strdup (e->val);
792 * Get a configuration value that should be in a set of
795 * @param cfg configuration to inspect
796 * @param section section of interest
797 * @param option option of interest
798 * @param choices NULL-terminated list of legal values
799 * @param value will be set to an entry in the legal list,
800 * or NULL if option is not specified and no default given
801 * @return GNUNET_OK on success, GNUNET_SYSERR on error
804 GNUNET_CONFIGURATION_get_value_choice (const struct
805 GNUNET_CONFIGURATION_Handle *cfg,
808 const char **choices,
811 struct ConfigEntry *e;
814 e = findEntry (cfg, section, option);
816 return GNUNET_SYSERR;
818 while (choices[i] != NULL)
820 if (0 == strcasecmp (choices[i], e->val))
824 if (choices[i] == NULL)
826 LOG (GNUNET_ERROR_TYPE_ERROR,
827 _("Configuration value '%s' for '%s'"
828 " in section '%s' is not in set of legal choices\n"), e->val,
830 return GNUNET_SYSERR;
838 * Test if we have a value for a particular option
839 * @param cfg configuration to inspect
840 * @param section section of interest
841 * @param option option of interest
842 * @return GNUNET_YES if so, GNUNET_NO if not.
845 GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle
846 *cfg, const char *section,
849 struct ConfigEntry *e;
851 if ((NULL == (e = findEntry (cfg, section, option))) || (e->val == NULL))
858 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
859 * where either in the "PATHS" section or the environtment
860 * "FOO" is set to "DIRECTORY".
862 * @param cfg configuration to use for path expansion
863 * @param orig string to $-expand (will be freed!)
864 * @return $-expanded string
867 GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle
879 while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0'))
891 GNUNET_CONFIGURATION_get_value_filename (cfg, "PATHS", &orig[1],
894 if (NULL == (env = getenv (&orig[1])))
896 orig[i] = DIR_SEPARATOR;
899 prefix = GNUNET_strdup (env);
901 result = GNUNET_malloc (strlen (prefix) + strlen (post) + 2);
902 strcpy (result, prefix);
903 if ((strlen (prefix) == 0) ||
904 ((prefix[strlen (prefix) - 1] != DIR_SEPARATOR) && (strlen (post) > 0)))
905 strcat (result, DIR_SEPARATOR_STR);
906 strcat (result, post);
907 GNUNET_free (prefix);
914 * Get a configuration value that should be a string.
916 * @param cfg configuration to inspect
917 * @param section section of interest
918 * @param option option of interest
919 * @param value will be set to a freshly allocated configuration
920 * value, or NULL if option is not specified
921 * @return GNUNET_OK on success, GNUNET_SYSERR on error
924 GNUNET_CONFIGURATION_get_value_filename (const struct
925 GNUNET_CONFIGURATION_Handle *cfg,
927 const char *option, char **value)
932 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp))
935 return GNUNET_SYSERR;
937 tmp = GNUNET_CONFIGURATION_expand_dollar (cfg, tmp);
938 *value = GNUNET_STRINGS_filename_expand (tmp);
941 return GNUNET_SYSERR;
947 * Get a configuration value that should be in a set of
948 * "GNUNET_YES" or "GNUNET_NO".
950 * @param cfg configuration to inspect
951 * @param section section of interest
952 * @param option option of interest
953 * @return GNUNET_YES, GNUNET_NO or GNUNET_SYSERR
956 GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
957 *cfg, const char *section,
960 static const char *yesno[] = { "YES", "NO", NULL };
965 GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
966 if (ret == GNUNET_SYSERR)
975 * Iterate over the set of filenames stored in a configuration value.
977 * @param cfg configuration to inspect
978 * @param section section of interest
979 * @param option option of interest
980 * @param cb function to call on each filename
981 * @param cb_cls closure for cb
982 * @return number of filenames iterated over, -1 on error
985 GNUNET_CONFIGURATION_iterate_value_filenames (const struct
986 GNUNET_CONFIGURATION_Handle
987 *cfg, const char *section,
989 GNUNET_FileNameCallback cb,
999 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list))
1001 GNUNET_assert (list != NULL);
1006 while (pos[0] == ' ')
1008 if (strlen (pos) == 0)
1011 while ((end[0] != ' ') && (end[0] != '\0'))
1019 memmove (end, &end[1], strlen (&end[1]) + 1);
1021 /* illegal, but just keep it */
1024 /* illegal, but just ignore that there was a '/' */
1032 if (strlen (pos) > 0)
1035 if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos)))
1037 ret = GNUNET_SYSERR;
1053 * @param value FIXME
1057 escape_name (const char *value)
1063 escaped = GNUNET_malloc (strlen (value) * 2 + 1);
1064 memset (escaped, 0, strlen (value) * 2 + 1);
1067 while (rpos[0] != '\0')
1090 * @param cls string we compare with (const char*)
1091 * @param fn filename we are currently looking at
1092 * @return GNUNET_OK if the names do not match, GNUNET_SYSERR if they do
1095 test_match (void *cls, const char *fn)
1097 const char *of = cls;
1099 return (0 == strcmp (of, fn)) ? GNUNET_SYSERR : GNUNET_OK;
1104 * Append a filename to a configuration value that
1105 * represents a list of filenames
1107 * @param cfg configuration to update
1108 * @param section section of interest
1109 * @param option option of interest
1110 * @param value filename to append
1111 * @return GNUNET_OK on success,
1112 * GNUNET_NO if the filename already in the list
1113 * GNUNET_SYSERR on error
1116 GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
1117 *cfg, const char *section,
1125 if (GNUNET_SYSERR ==
1126 GNUNET_CONFIGURATION_iterate_value_filenames (cfg, section, option,
1129 return GNUNET_NO; /* already exists */
1131 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
1132 old = GNUNET_strdup ("");
1133 escaped = escape_name (value);
1134 nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2);
1136 if (strlen (old) > 0)
1138 strcat (nw, escaped);
1139 GNUNET_CONFIGURATION_set_value_string (cfg, section, option, nw);
1142 GNUNET_free (escaped);
1148 * Remove a filename from a configuration value that
1149 * represents a list of filenames
1151 * @param cfg configuration to update
1152 * @param section section of interest
1153 * @param option option of interest
1154 * @param value filename to remove
1155 * @return GNUNET_OK on success,
1156 * GNUNET_NO if the filename is not in the list,
1157 * GNUNET_SYSERR on error
1160 GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle
1161 *cfg, const char *section,
1172 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list))
1174 match = escape_name (value);
1178 while (pos[0] == ' ')
1180 if (strlen (pos) == 0)
1183 while ((end[0] != ' ') && (end[0] != '\0'))
1194 /* illegal, but just keep it */
1197 /* illegal, but just ignore that there was a '/' */
1205 if (0 == strcmp (pos, match))
1208 memmove (pos, &end[1], strlen (&end[1]) + 1);
1216 GNUNET_CONFIGURATION_set_value_string (cfg, section, option, list);
1218 GNUNET_free (match);
1227 GNUNET_free (match);
1233 * Wrapper around GNUNET_CONFIGURATION_parse.
1235 * @param cls the cfg
1236 * @param filename file to parse
1237 * @return GNUNET_OK on success
1240 parse_configuration_file (void *cls,
1241 const char *filename)
1243 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
1246 ret = GNUNET_CONFIGURATION_parse (cfg, filename);
1252 * Load configuration (starts with defaults, then loads
1253 * system-specific configuration).
1255 * @param cfg configuration to update
1256 * @param filename name of the configuration file, NULL to load defaults
1257 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1260 GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
1261 const char *filename)
1266 ipath = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
1268 return GNUNET_SYSERR;
1270 GNUNET_asprintf (&baseconfig, "%s%s", ipath,
1272 GNUNET_free (ipath);
1273 if (GNUNET_SYSERR ==
1274 GNUNET_DISK_directory_scan (baseconfig,
1275 &parse_configuration_file,
1278 GNUNET_free (baseconfig);
1279 return GNUNET_SYSERR; /* no configuration at all found */
1281 GNUNET_free (baseconfig);
1282 if ( (filename != NULL) &&
1283 (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, filename)) )
1285 /* specified configuration not found */
1286 return GNUNET_SYSERR;
1289 GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) &&
1291 GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG",
1294 GNUNET_CONFIGURATION_have_value (cfg, "TESTING", "WEAKRANDOM")) &&
1296 GNUNET_CONFIGURATION_get_value_yesno (cfg, "TESTING", "WEAKRANDOM")))
1297 GNUNET_CRYPTO_random_disable_entropy_gathering ();
1303 /* end of configuration.c */