- doc
[oweals/gnunet.git] / src / util / configuration.c
index 28cf1f2dccec7859d224905ec8d7d4e0ccbe59a7..72fe0e7d02de532364bfe63dc660d8acf7c45f5c 100644 (file)
@@ -234,7 +234,6 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
        if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, value))
        {
          ret = GNUNET_SYSERR;    /* failed to parse included config */
-         GNUNET_free_non_null (line_orig);
          break;
        }
       }
@@ -243,7 +242,6 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
        LOG (GNUNET_ERROR_TYPE_DEBUG,
             "Ignoring parsing @INLINE@ configurations, not allowed!\n");
        ret = GNUNET_SYSERR;
-       GNUNET_free_non_null (line_orig);
        break;
       }
       continue;
@@ -293,8 +291,6 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
         _("Syntax error while deserializing in line %u\n"), 
         nr);
     ret = GNUNET_SYSERR;
-    GNUNET_free_non_null (line_orig);
-    line_orig = NULL;
     break;
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished deserializing config\n");
@@ -740,8 +736,8 @@ findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section,
  * @param value value to copy (of the default conf.)
  */
 static void
-compareEntries (void *cls, const char *section, const char *option,
-                const char *value)
+compare_entries (void *cls, const char *section, const char *option,
+                const char *value)
 {
   struct DiffHandle *dh = cls;
   struct ConfigEntry *entNew;
@@ -753,6 +749,28 @@ compareEntries (void *cls, const char *section, const char *option,
 }
 
 
+/**
+ * Compute configuration with only entries that have been changed
+ *
+ * @param cfgDefault original configuration
+ * @param cfgNew new configuration
+ * @return configuration with only the differences, never NULL
+ */
+struct GNUNET_CONFIGURATION_Handle *
+GNUNET_CONFIGURATION_get_diff (const struct GNUNET_CONFIGURATION_Handle
+                              *cfgDefault,
+                              const struct GNUNET_CONFIGURATION_Handle
+                              *cfgNew)
+{
+  struct DiffHandle diffHandle;
+
+  diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
+  diffHandle.cfgDefault = cfgDefault;
+  GNUNET_CONFIGURATION_iterate (cfgNew, &compare_entries, &diffHandle);
+  return diffHandle.cfgDiff;
+}
+
+
 /**
  * Write only configuration entries that have been changed to configuration file
  * @param cfgDefault default configuration
@@ -767,13 +785,11 @@ GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
                                   *cfgNew, const char *filename)
 {
   int ret;
-  struct DiffHandle diffHandle;
+  struct GNUNET_CONFIGURATION_Handle *diff;
 
-  diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
-  diffHandle.cfgDefault = cfgDefault;
-  GNUNET_CONFIGURATION_iterate (cfgNew, compareEntries, &diffHandle);
-  ret = GNUNET_CONFIGURATION_write (diffHandle.cfgDiff, filename);
-  GNUNET_CONFIGURATION_destroy (diffHandle.cfgDiff);
+  diff = GNUNET_CONFIGURATION_get_diff (cfgDefault, cfgNew);
+  ret = GNUNET_CONFIGURATION_write (diff, filename);
+  GNUNET_CONFIGURATION_destroy (diff);
   return ret;
 }