aboutsummaryrefslogtreecommitdiff
path: root/src/util/configuration.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-12-12 21:44:22 +0000
committerChristian Grothoff <christian@grothoff.org>2012-12-12 21:44:22 +0000
commit997b729e8cbd05f51bac7dcd795ca7b35aa5e551 (patch)
tree9f884f259b3916eeea3bef9b662db50160077413 /src/util/configuration.c
parent530b55e3cf376821a4e28cfdd86f82e151c6f28f (diff)
downloadgnunet-997b729e8cbd05f51bac7dcd795ca7b35aa5e551.tar.gz
gnunet-997b729e8cbd05f51bac7dcd795ca7b35aa5e551.zip
adding function to compute configuration differences in memory
Diffstat (limited to 'src/util/configuration.c')
-rw-r--r--src/util/configuration.c36
1 files changed, 28 insertions, 8 deletions
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