gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r9442 - gnunet/src/util
Date: Tue, 10 Nov 2009 01:06:12 -0700

Author: safey
Date: 2009-11-10 01:06:11 -0700 (Tue, 10 Nov 2009)
New Revision: 9442

Modified:
   gnunet/src/util/configuration.c
   gnunet/src/util/test_configuration.c
Log:


Modified: gnunet/src/util/configuration.c
===================================================================
--- gnunet/src/util/configuration.c     2009-11-10 07:59:10 UTC (rev 9441)
+++ gnunet/src/util/configuration.c     2009-11-10 08:06:11 UTC (rev 9442)
@@ -98,7 +98,17 @@
 
 };
 
+/**
+ * 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 @@
 {
        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 @@
        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);
        
-       return GNUNET_CONFIGURATION_write(diffHandle->cfgDiff, filename);
+       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 07:59:10 UTC (rev 
9441)
+++ gnunet/src/util/test_configuration.c        2009-11-10 08:06:11 UTC (rev 
9442)
@@ -173,62 +173,81 @@
 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);
+//  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;
 }





reply via email to

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