From: Christian Grothoff Date: Tue, 10 Nov 2009 08:34:13 +0000 (+0000) Subject: code clean up, rolling back mods to test_configuration X-Git-Tag: initial-import-from-subversion-38251~23125 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=c81ee0c9dd540678c332608443ade794437d926f;p=oweals%2Fgnunet.git code clean up, rolling back mods to test_configuration --- diff --git a/src/util/configuration.c b/src/util/configuration.c index 250f9d3d5..bdcc231e1 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c @@ -98,14 +98,15 @@ struct GNUNET_CONFIGURATION_Handle }; + /** * Used for diffing a configuration object against * the default one */ -struct GNUNNET_CONFIGURATION_Diff_Handle +struct DiffHandle { - struct GNUNET_CONFIGURATION_Handle *cfgNew; - struct GNUNET_CONFIGURATION_Handle *cfgDiff; + const struct GNUNET_CONFIGURATION_Handle *cfgDefault; + const struct GNUNET_CONFIGURATION_Handle *cfgDiff; }; @@ -473,88 +474,29 @@ findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, /** - * A callback function, compares entries from two configurations (default against a new configuration) - * and write the diffs in a diff-configuration object (the callback object). - * @param cls the diff configuration (ConfigurationDiffHandle*) + * A callback function, compares entries from two configurations + * (default against a new configuration) and write the diffs in a + * diff-configuration object (the callback object). + * + * @param cls the diff configuration (struct DiffHandle*) * @param section section for the value (of the default conf.) * @param option option name of the value (of the default conf.) * @param value value to copy (of the default conf.) */ -void +static void compareEntries (void *cls, const char *section, const char *option, const char *value) { - struct ConfigSection *secNew; + struct DiffHandle *dh = cls; struct ConfigEntry *entNew; - struct GNUNNET_CONFIGURATION_Diff_Handle *cfgDiff = - (struct GNUNNET_CONFIGURATION_Diff_Handle *) cls; - - secNew = findSection (cfgDiff->cfgNew, section); - entNew = findEntry (cfgDiff->cfgNew, section, option); - if (secNew && strcmp (entNew->val, value) != 0) - { - /* Value in the new configuration has been changed */ - /* Add the changed value to the diff configuration object */ - struct ConfigEntry *diffEntry = NULL; - struct ConfigSection *diffSection = NULL; - - diffSection = cfgDiff->cfgDiff->sections; - if (diffSection == NULL) - { - /* First section */ - diffSection = GNUNET_malloc (sizeof (struct ConfigSection)); - memcpy (diffSection, secNew, sizeof (struct ConfigSection)); - cfgDiff->cfgDiff->sections = diffSection; - diffSection->entries = NULL; - diffSection->next = NULL; - } - else - { - while ((strcmp (diffSection->name, secNew->name) != 0) - && (diffSection->next != NULL)) - { - diffSection = diffSection->next; - } - if (strcmp (diffSection->name, secNew->name) != 0) - { - /* Section not found in diffs configuration */ - diffSection->next = - GNUNET_malloc (sizeof (struct ConfigSection)); - memcpy (diffSection->next, secNew, - sizeof (struct ConfigSection)); - diffSection->next->entries = NULL; - diffSection->next->next = NULL; - } - else - { - diffEntry = diffSection->entries; - } - } - - if (diffEntry == NULL) - { - /* First Entry */ - diffEntry = GNUNET_malloc (sizeof (struct ConfigEntry)); - memcpy (diffEntry, entNew, sizeof (struct ConfigEntry)); - if (diffSection->next == NULL) - /* The first Entry of the first Section */ - diffSection->entries = diffEntry; - else - /* The first entry of the non-first Section */ - diffSection->next->entries = diffEntry; - diffEntry->next = NULL; - } - else - { - while (diffEntry->next != NULL) - { - diffEntry = diffEntry->next; - } - diffEntry->next = GNUNET_malloc (sizeof (struct ConfigEntry)); - memcpy (diffEntry->next, entNew, sizeof (struct ConfigEntry)); - diffEntry->next->next = NULL; - } - } + + entNew = findEntry (dh->cfgDefault, section, option); + if ( (entNew != NULL) && + (strcmp (entNew->val, value) == 0) ) + return; + GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff, + option, + value); } @@ -566,21 +508,18 @@ compareEntries (void *cls, * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_CONFIGURATION_write_diffs (struct GNUNET_CONFIGURATION_Handle +GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle *cfgDefault, - struct GNUNET_CONFIGURATION_Handle *cfgNew, + const struct GNUNET_CONFIGURATION_Handle *cfgNew, const char *filename) { 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); + struct DiffHandle diffHandle; + diffHandle.cfgDiff = GNUNET_CONFIGURATION_create (); + diffHandle.cfgDefault = cfgDefault; + GNUNET_CONFIGURATION_iterate (cfgNew, compareEntries, &diffHandle); ret = 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 3cd076f0f..4c7f69a14 100644 --- a/src/util/test_configuration.c +++ b/src/util/test_configuration.c @@ -173,84 +173,62 @@ testConfigFilenames () int main (int argc, char *argv[]) { -// int failureCount = 0; -// char *c; + 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 (); + GNUNET_log_setup ("test_configuration", "WARNING", NULL); + cfg = GNUNET_CONFIGURATION_create (); + GNUNET_assert (cfg != NULL); if (GNUNET_OK != - GNUNET_CONFIGURATION_parse (cfgDefault, - "src/util/test_configuration_data.conf")) + GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf")) { fprintf (stderr, "Failed to parse configuration file\n"); - GNUNET_CONFIGURATION_destroy (cfgDefault); + GNUNET_CONFIGURATION_destroy (cfg); return 1; } - if (GNUNET_OK != - GNUNET_CONFIGURATION_parse (cfgNew, - "/Users/soufi/Desktop/test_configuration_data.conf")) + failureCount += testConfig (); + failureCount += 2 * testConfigFilenames (); + + if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf")) { - fprintf (stderr, "Failed to parse configuration file\n"); - GNUNET_CONFIGURATION_destroy (cfgNew); + 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")); - GNUNET_CONFIGURATION_write_diffs (cfgDefault, cfgNew, "/tmp/safey.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; + } return 0; }