int allow_inline)
{
char *line;
+ char *line_orig;
size_t line_size;
char *pos;
unsigned int nr;
section = GNUNET_strdup ("");
nr = 0;
r_bytes = 0;
+ line_orig = NULL;
while (r_bytes < size)
{
+ GNUNET_free_non_null (line_orig);
/* fgets-like behaviour on buffer */
to_read = size - r_bytes;
pos = memchr (&mem[r_bytes], '\n', to_read);
if (NULL == pos)
{
- line = GNUNET_strndup (&mem[r_bytes], line_size = to_read);
+ line_orig = GNUNET_strndup (&mem[r_bytes], line_size = to_read);
r_bytes += line_size;
}
else
{
- line = GNUNET_strndup (&mem[r_bytes], line_size = (pos - &mem[r_bytes]));
+ line_orig = GNUNET_strndup (&mem[r_bytes], line_size = (pos - &mem[r_bytes]));
r_bytes += line_size + 1;
}
+ line = line_orig;
/* increment line number */
nr++;
- /* ignore comments */
- if ( ('#' == line[0]) || ('%' == line[0]) )
- continue;
/* tabs and '\r' are whitespace */
emptyline = GNUNET_YES;
for (i = 0; i < line_size; i++)
for (i = line_size - 1; (i >= 1) && (isspace ((unsigned char) line[i]));i--)
line[i] = '\0';
+ /* remove leading whitespace */
+ for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++);
+
+ /* ignore comments */
+ if ( ('#' == line[0]) || ('%' == line[0]) )
+ continue;
+
/* handle special "@INLINE@" directive */
if (0 == strncasecmp (line,
"@INLINE@ ",
}
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 */
ret = GNUNET_SYSERR;
break;
}
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished deserializing config\n", tag);
+ 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;
* @param value value to copy (of the default conf.)
*/
static void
-compareEntries (void *cls, const char *section, const char *option,
- const char *value)
+compare_entries (void *cls, const char *section, const char *option,
+ const char *value)
{
struct DiffHandle *dh = cls;
struct ConfigEntry *entNew;
}
+/**
+ * Compute configuration with only entries that have been changed
+ *
+ * @param cfgDefault original configuration
+ * @param cfgNew new configuration
+ * @return configuration with only the differences, never NULL
+ */
+struct GNUNET_CONFIGURATION_Handle *
+GNUNET_CONFIGURATION_get_diff (const struct GNUNET_CONFIGURATION_Handle
+ *cfgDefault,
+ const struct GNUNET_CONFIGURATION_Handle
+ *cfgNew)
+{
+ struct DiffHandle diffHandle;
+
+ diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
+ diffHandle.cfgDefault = cfgDefault;
+ GNUNET_CONFIGURATION_iterate (cfgNew, &compare_entries, &diffHandle);
+ return diffHandle.cfgDiff;
+}
+
+
/**
* Write only configuration entries that have been changed to configuration file
* @param cfgDefault default configuration
*cfgNew, const char *filename)
{
int ret;
- struct DiffHandle diffHandle;
+ struct GNUNET_CONFIGURATION_Handle *diff;
- diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
- diffHandle.cfgDefault = cfgDefault;
- GNUNET_CONFIGURATION_iterate (cfgNew, compareEntries, &diffHandle);
- ret = GNUNET_CONFIGURATION_write (diffHandle.cfgDiff, filename);
- GNUNET_CONFIGURATION_destroy (diffHandle.cfgDiff);
+ diff = GNUNET_CONFIGURATION_get_diff (cfgDefault, cfgNew);
+ ret = GNUNET_CONFIGURATION_write (diff, filename);
+ GNUNET_CONFIGURATION_destroy (diff);
return ret;
}
(filename != NULL))
GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG",
filename);
- if ((GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (cfg, "TESTING", "WEAKRANDOM")) &&
- (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (cfg, "TESTING", "WEAKRANDOM")))
- GNUNET_CRYPTO_random_disable_entropy_gathering ();
return GNUNET_OK;
}