From: Safey A.Halim Date: Tue, 10 Nov 2009 08:06:11 +0000 (+0000) Subject: (no commit message) X-Git-Tag: initial-import-from-subversion-38251~23128 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=63aea8612441c32317fbe7ffd238f14a03c614fe;p=oweals%2Fgnunet.git --- diff --git a/src/util/configuration.c b/src/util/configuration.c index e35dfacfe..d64ca8e83 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c @@ -98,6 +98,16 @@ struct GNUNET_CONFIGURATION_Handle }; +/** + * 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. @@ -478,7 +488,7 @@ compareEntries( { 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); @@ -551,14 +561,18 @@ GNUNET_CONFIGURATION_write_diffs( 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; } diff --git a/src/util/test_configuration.c b/src/util/test_configuration.c index 4c7f69a14..150b8d6b4 100644 --- a/src/util/test_configuration.c +++ b/src/util/test_configuration.c @@ -173,62 +173,81 @@ testConfigFilenames () 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; }