+ if ( ('[' == line[0]) && (']' == line[line_size - 1]) )
+ {
+ /* [value] */
+ line[line_size - 1] = '\0';
+ value = &line[1];
+ GNUNET_free (section);
+ section = GNUNET_strdup (value);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Config section `%s'\n",
+ section);
+ continue;
+ }
+ if (NULL != (eq = strchr (line, '=')))
+ {
+ /* tag = value */
+ tag = GNUNET_strndup (line, eq - line);
+ /* remove tailing whitespace */
+ for (i = strlen (tag) - 1; (i >= 1) && (isspace ((unsigned char) tag[i]));i--)
+ tag[i] = '\0';
+
+ /* Strip whitespace */
+ value = eq + 1;
+ while (isspace ((unsigned char) value[0]))
+ value++;
+ for (i = strlen (value) - 1; (i >= 1) && (isspace ((unsigned char) value[i]));i--)
+ value[i] = '\0';
+
+ /* remove quotes */
+ i = 0;
+ if ( ('"' == value[0]) &&
+ ('"' == value[strlen (value) - 1]) )
+ {
+ value[strlen (value) - 1] = '\0';
+ value++;
+ }
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Config value %s=\"%s\"\n", tag, value);
+ GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, &value[i]);
+ GNUNET_free (tag);
+ continue;
+ }
+ /* parse error */
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("Syntax error while deserializing in line %u\n"),
+ nr);
+ ret = GNUNET_SYSERR;
+ break;
+ }
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished deserializing config\n");
+ GNUNET_free_non_null (line_orig);
+ GNUNET_free (section);
+ GNUNET_assert ( (GNUNET_OK != ret) || (r_bytes == size) );
+ return ret;
+}
+
+
+/**
+ * Parse a configuration file, add all of the options in the
+ * file to the configuration environment.
+ *
+ * @param cfg configuration to update
+ * @param filename name of the configuration file
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
+ */
+int
+GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *filename)
+{
+ uint64_t fs64;
+ size_t fs;
+ char *fn;
+ char *mem;
+ int dirty;
+ int ret;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Asked to parse config file `%s'\n",
+ filename);
+ fn = GNUNET_STRINGS_filename_expand (filename);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Config file name expanded to `%s'\n",
+ fn);
+ if (NULL == fn)
+ return GNUNET_SYSERR;
+ dirty = cfg->dirty; /* back up value! */
+ if (GNUNET_SYSERR ==
+ GNUNET_DISK_file_size (fn, &fs64, GNUNET_YES, GNUNET_YES))
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Error while determining the file size of %s\n", fn);
+ GNUNET_free (fn);
+ return GNUNET_SYSERR;
+ }
+ if (fs64 > SIZE_MAX)
+ {
+ GNUNET_break (0); /* File size is more than the heap size */
+ GNUNET_free (fn);
+ return GNUNET_SYSERR;
+ }
+ fs = fs64;
+ mem = GNUNET_malloc (fs);
+ if (fs != GNUNET_DISK_fn_read (fn, mem, fs))
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Error while reading file %s\n",
+ fn);
+ GNUNET_free (fn);
+ GNUNET_free (mem);
+ return GNUNET_SYSERR;
+ }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Deserializing contents of file `%s'\n",
+ fn);
+ GNUNET_free (fn);
+ ret = GNUNET_CONFIGURATION_deserialize (cfg, mem, fs, GNUNET_YES);
+ GNUNET_free (mem);