summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_configuration_lib.h16
-rw-r--r--src/util/configuration.c36
2 files changed, 44 insertions, 8 deletions
diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h
index 77d6d5552..0c87a537d 100644
--- a/src/include/gnunet_configuration_lib.h
+++ b/src/include/gnunet_configuration_lib.h
@@ -154,6 +154,7 @@ int
154GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, 154GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
155 const char *filename); 155 const char *filename);
156 156
157
157/** 158/**
158 * Write only configuration entries that have been changed to configuration file 159 * Write only configuration entries that have been changed to configuration file
159 * @param cfgDefault default configuration 160 * @param cfgDefault default configuration
@@ -167,6 +168,21 @@ GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
167 const struct GNUNET_CONFIGURATION_Handle 168 const struct GNUNET_CONFIGURATION_Handle
168 *cfgNew, const char *filename); 169 *cfgNew, const char *filename);
169 170
171
172/**
173 * Compute configuration with only entries that have been changed
174 *
175 * @param cfgDefault original configuration
176 * @param cfgNew new configuration
177 * @return configuration with only the differences, never NULL
178 */
179struct GNUNET_CONFIGURATION_Handle *
180GNUNET_CONFIGURATION_get_diff (const struct GNUNET_CONFIGURATION_Handle
181 *cfgDefault,
182 const struct GNUNET_CONFIGURATION_Handle
183 *cfgNew);
184
185
170/** 186/**
171 * Test if there are configuration options that were 187 * Test if there are configuration options that were
172 * changed since the last save. 188 * changed since the last save.
diff --git a/src/util/configuration.c b/src/util/configuration.c
index f07f61a94..72fe0e7d0 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -736,8 +736,8 @@ findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section,
736 * @param value value to copy (of the default conf.) 736 * @param value value to copy (of the default conf.)
737 */ 737 */
738static void 738static void
739compareEntries (void *cls, const char *section, const char *option, 739compare_entries (void *cls, const char *section, const char *option,
740 const char *value) 740 const char *value)
741{ 741{
742 struct DiffHandle *dh = cls; 742 struct DiffHandle *dh = cls;
743 struct ConfigEntry *entNew; 743 struct ConfigEntry *entNew;
@@ -750,6 +750,28 @@ compareEntries (void *cls, const char *section, const char *option,
750 750
751 751
752/** 752/**
753 * Compute configuration with only entries that have been changed
754 *
755 * @param cfgDefault original configuration
756 * @param cfgNew new configuration
757 * @return configuration with only the differences, never NULL
758 */
759struct GNUNET_CONFIGURATION_Handle *
760GNUNET_CONFIGURATION_get_diff (const struct GNUNET_CONFIGURATION_Handle
761 *cfgDefault,
762 const struct GNUNET_CONFIGURATION_Handle
763 *cfgNew)
764{
765 struct DiffHandle diffHandle;
766
767 diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
768 diffHandle.cfgDefault = cfgDefault;
769 GNUNET_CONFIGURATION_iterate (cfgNew, &compare_entries, &diffHandle);
770 return diffHandle.cfgDiff;
771}
772
773
774/**
753 * Write only configuration entries that have been changed to configuration file 775 * Write only configuration entries that have been changed to configuration file
754 * @param cfgDefault default configuration 776 * @param cfgDefault default configuration
755 * @param cfgNew new configuration 777 * @param cfgNew new configuration
@@ -763,13 +785,11 @@ GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
763 *cfgNew, const char *filename) 785 *cfgNew, const char *filename)
764{ 786{
765 int ret; 787 int ret;
766 struct DiffHandle diffHandle; 788 struct GNUNET_CONFIGURATION_Handle *diff;
767 789
768 diffHandle.cfgDiff = GNUNET_CONFIGURATION_create (); 790 diff = GNUNET_CONFIGURATION_get_diff (cfgDefault, cfgNew);
769 diffHandle.cfgDefault = cfgDefault; 791 ret = GNUNET_CONFIGURATION_write (diff, filename);
770 GNUNET_CONFIGURATION_iterate (cfgNew, compareEntries, &diffHandle); 792 GNUNET_CONFIGURATION_destroy (diff);
771 ret = GNUNET_CONFIGURATION_write (diffHandle.cfgDiff, filename);
772 GNUNET_CONFIGURATION_destroy (diffHandle.cfgDiff);
773 return ret; 793 return ret;
774} 794}
775 795