gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r9445 - gnunet/src/util


From: gnunet
Subject: [GNUnet-SVN] r9445 - gnunet/src/util
Date: Tue, 10 Nov 2009 01:34:13 -0700

Author: grothoff
Date: 2009-11-10 01:34:13 -0700 (Tue, 10 Nov 2009)
New Revision: 9445

Modified:
   gnunet/src/util/configuration.c
   gnunet/src/util/test_configuration.c
Log:
code clean up, rolling back mods to test_configuration

Modified: gnunet/src/util/configuration.c
===================================================================
--- gnunet/src/util/configuration.c     2009-11-10 08:16:49 UTC (rev 9444)
+++ gnunet/src/util/configuration.c     2009-11-10 08:34:13 UTC (rev 9445)
@@ -98,14 +98,15 @@
 
 };
 
+
 /**
  * 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 @@
 
 
 /**
- * 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 @@
  * @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;
 }

Modified: gnunet/src/util/test_configuration.c
===================================================================
--- gnunet/src/util/test_configuration.c        2009-11-10 08:16:49 UTC (rev 
9444)
+++ gnunet/src/util/test_configuration.c        2009-11-10 08:34:13 UTC (rev 
9445)
@@ -173,84 +173,62 @@
 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;
 }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]