};
+/**
+ * Used for diffing a configuration object against
+ * the default one
+ */
+struct GNUNNET_CONFIGURATION_Diff_Handle{
+ struct GNUNET_CONFIGURATION_Handle* cfgNew;
+ struct GNUNET_CONFIGURATION_Handle* cfgDiff;
+};
+
+
/**
* Create a GNUNET_CONFIGURATION_Handle.
{
struct ConfigSection *secNew;
struct ConfigEntry *entNew;
- GNUNNET_CONFIGURATION_Diff_Handle* cfgDiff = (GNUNNET_CONFIGURATION_Diff_Handle*)cls;
+ struct GNUNNET_CONFIGURATION_Diff_Handle* cfgDiff = (struct GNUNNET_CONFIGURATION_Diff_Handle*)cls;
secNew = findSection(cfgDiff->cfgNew, section);
entNew = findEntry(cfgDiff->cfgNew, section, option);
const char* filename
)
{
- GNUNNET_CONFIGURATION_Diff_Handle *diffHandle =
- GNUNET_malloc(sizeof(GNUNNET_CONFIGURATION_Diff_Handle));
- diffHandle->cfgDiff = GNUNET_CONFIGURATION_create();
- diffHandle->cfgDiff->sections = NULL;
- diffHandle->cfgNew = cfgNew;
- GNUNET_CONFIGURATION_iterate(cfgDefault, compareEntries, diffHandle);
+ int ret;
+ struct GNUNNET_CONFIGURATION_Diff_Handle diffHandle;
+ diffHandle.cfgDiff = GNUNET_CONFIGURATION_create();
+ diffHandle.cfgDiff->sections = NULL;
+ diffHandle.cfgNew = cfgNew;
+ GNUNET_CONFIGURATION_iterate(cfgDefault, compareEntries, &diffHandle);
+
+ ret = GNUNET_CONFIGURATION_write(diffHandle.cfgDiff, filename);
- return GNUNET_CONFIGURATION_write(diffHandle->cfgDiff, filename);
+ /* Housekeeping */
+ GNUNET_CONFIGURATION_destroy(diffHandle.cfgDiff);
+ return ret;
}
int
main (int argc, char *argv[])
{
- int failureCount = 0;
- char *c;
-
- GNUNET_log_setup ("test_configuration", "WARNING", NULL);
- cfg = GNUNET_CONFIGURATION_create ();
- GNUNET_assert (cfg != NULL);
+// int failureCount = 0;
+// char *c;
+
+// GNUNET_log_setup ("test_configuration", "WARNING", NULL);
+// cfg = GNUNET_CONFIGURATION_create ();
+// GNUNET_assert (cfg != NULL);
+// if (GNUNET_OK !=
+// GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf"))
+// {
+// fprintf (stderr, "Failed to parse configuration file\n");
+// GNUNET_CONFIGURATION_destroy (cfg);
+// return 1;
+// }
+// failureCount += testConfig ();
+// failureCount += 2 * testConfigFilenames ();
+//
+// if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf"))
+// {
+// fprintf (stderr, "Failed to write configuration file\n");
+// GNUNET_CONFIGURATION_destroy (cfg);
+// return 1;
+// }
+// GNUNET_CONFIGURATION_destroy (cfg);
+// GNUNET_assert (0 == UNLINK ("/tmp/gnunet-test.conf"));
+//
+// cfg = GNUNET_CONFIGURATION_create ();
+// if (GNUNET_OK !=
+// GNUNET_CONFIGURATION_load (cfg, "test_configuration_data.conf"))
+// {
+// GNUNET_break (0);
+// GNUNET_CONFIGURATION_destroy (cfg);
+// return 1;
+// }
+// if ((GNUNET_OK !=
+// GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "WEAKRANDOM",
+// &c))
+// || (0 != strcmp (c, "YES")))
+// {
+// GNUNET_CONFIGURATION_destroy (cfg);
+// return 1;
+// }
+// GNUNET_free (c);
+// if ((GNUNET_OK !=
+// GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME",
+// &c))
+// || (0 != strcmp (c, "/var/lib/gnunet/")))
+// {
+// GNUNET_CONFIGURATION_destroy (cfg);
+// return 1;
+// }
+// GNUNET_free (c);
+// GNUNET_CONFIGURATION_destroy (cfg);
+// if (failureCount != 0)
+// {
+// fprintf (stderr, "Test failed: %u\n", failureCount);
+// return 1;
+// }
+//
+ struct GNUNET_CONFIGURATION_Handle* cfgDefault = GNUNET_CONFIGURATION_create ();
+ struct GNUNET_CONFIGURATION_Handle* cfgNew = GNUNET_CONFIGURATION_create();
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf"))
- {
- fprintf (stderr, "Failed to parse configuration file\n");
- GNUNET_CONFIGURATION_destroy (cfg);
- return 1;
- }
- failureCount += testConfig ();
- failureCount += 2 * testConfigFilenames ();
-
- if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf"))
- {
- fprintf (stderr, "Failed to write configuration file\n");
- GNUNET_CONFIGURATION_destroy (cfg);
- return 1;
- }
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_assert (0 == UNLINK ("/tmp/gnunet-test.conf"));
-
- cfg = GNUNET_CONFIGURATION_create ();
+ GNUNET_CONFIGURATION_parse (cfgDefault, "src/util/test_configuration_data.conf"))
+ {
+ fprintf (stderr, "Failed to parse configuration file\n");
+ GNUNET_CONFIGURATION_destroy (cfgDefault);
+ return 1;
+ }
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_load (cfg, "test_configuration_data.conf"))
- {
- GNUNET_break (0);
- GNUNET_CONFIGURATION_destroy (cfg);
- return 1;
- }
- if ((GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "WEAKRANDOM",
- &c))
- || (0 != strcmp (c, "YES")))
- {
- GNUNET_CONFIGURATION_destroy (cfg);
- return 1;
- }
- GNUNET_free (c);
- if ((GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME",
- &c))
- || (0 != strcmp (c, "/var/lib/gnunet/")))
- {
- GNUNET_CONFIGURATION_destroy (cfg);
- return 1;
- }
- GNUNET_free (c);
- GNUNET_CONFIGURATION_destroy (cfg);
- if (failureCount != 0)
- {
- fprintf (stderr, "Test failed: %u\n", failureCount);
- return 1;
- }
+ GNUNET_CONFIGURATION_parse (cfgNew, "/Users/soufi/Desktop/test_configuration_data.conf"))
+ {
+ fprintf (stderr, "Failed to parse configuration file\n");
+ GNUNET_CONFIGURATION_destroy (cfgNew);
+ return 1;
+ }
+
+ GNUNET_CONFIGURATION_write_diffs(cfgDefault, cfgNew, "/tmp/safey.conf");
return 0;
}