aboutsummaryrefslogtreecommitdiff
path: root/src/util/configuration.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-11-10 08:34:13 +0000
committerChristian Grothoff <christian@grothoff.org>2009-11-10 08:34:13 +0000
commitc81ee0c9dd540678c332608443ade794437d926f (patch)
tree84ca67363c5653936dc042f6715f04ab904faf0e /src/util/configuration.c
parent660c6da4fcbca6bd2cb15599dfe3c6d53b890c7f (diff)
downloadgnunet-c81ee0c9dd540678c332608443ade794437d926f.tar.gz
gnunet-c81ee0c9dd540678c332608443ade794437d926f.zip
code clean up, rolling back mods to test_configuration
Diffstat (limited to 'src/util/configuration.c')
-rw-r--r--src/util/configuration.c111
1 files changed, 25 insertions, 86 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c
index 250f9d3d5..bdcc231e1 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -98,14 +98,15 @@ struct GNUNET_CONFIGURATION_Handle
98 98
99}; 99};
100 100
101
101/** 102/**
102 * Used for diffing a configuration object against 103 * Used for diffing a configuration object against
103 * the default one 104 * the default one
104 */ 105 */
105struct GNUNNET_CONFIGURATION_Diff_Handle 106struct DiffHandle
106{ 107{
107 struct GNUNET_CONFIGURATION_Handle *cfgNew; 108 const struct GNUNET_CONFIGURATION_Handle *cfgDefault;
108 struct GNUNET_CONFIGURATION_Handle *cfgDiff; 109 const struct GNUNET_CONFIGURATION_Handle *cfgDiff;
109}; 110};
110 111
111 112
@@ -473,88 +474,29 @@ findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg,
473 474
474 475
475/** 476/**
476 * A callback function, compares entries from two configurations (default against a new configuration) 477 * A callback function, compares entries from two configurations
477 * and write the diffs in a diff-configuration object (the callback object). 478 * (default against a new configuration) and write the diffs in a
478 * @param cls the diff configuration (ConfigurationDiffHandle*) 479 * diff-configuration object (the callback object).
480 *
481 * @param cls the diff configuration (struct DiffHandle*)
479 * @param section section for the value (of the default conf.) 482 * @param section section for the value (of the default conf.)
480 * @param option option name of the value (of the default conf.) 483 * @param option option name of the value (of the default conf.)
481 * @param value value to copy (of the default conf.) 484 * @param value value to copy (of the default conf.)
482 */ 485 */
483void 486static void
484compareEntries (void *cls, 487compareEntries (void *cls,
485 const char *section, const char *option, const char *value) 488 const char *section, const char *option, const char *value)
486{ 489{
487 struct ConfigSection *secNew; 490 struct DiffHandle *dh = cls;
488 struct ConfigEntry *entNew; 491 struct ConfigEntry *entNew;
489 struct GNUNNET_CONFIGURATION_Diff_Handle *cfgDiff = 492
490 (struct GNUNNET_CONFIGURATION_Diff_Handle *) cls; 493 entNew = findEntry (dh->cfgDefault, section, option);
491 494 if ( (entNew != NULL) &&
492 secNew = findSection (cfgDiff->cfgNew, section); 495 (strcmp (entNew->val, value) == 0) )
493 entNew = findEntry (cfgDiff->cfgNew, section, option); 496 return;
494 if (secNew && strcmp (entNew->val, value) != 0) 497 GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff,
495 { 498 option,
496 /* Value in the new configuration has been changed */ 499 value);
497 /* Add the changed value to the diff configuration object */
498 struct ConfigEntry *diffEntry = NULL;
499 struct ConfigSection *diffSection = NULL;
500
501 diffSection = cfgDiff->cfgDiff->sections;
502 if (diffSection == NULL)
503 {
504 /* First section */
505 diffSection = GNUNET_malloc (sizeof (struct ConfigSection));
506 memcpy (diffSection, secNew, sizeof (struct ConfigSection));
507 cfgDiff->cfgDiff->sections = diffSection;
508 diffSection->entries = NULL;
509 diffSection->next = NULL;
510 }
511 else
512 {
513 while ((strcmp (diffSection->name, secNew->name) != 0)
514 && (diffSection->next != NULL))
515 {
516 diffSection = diffSection->next;
517 }
518 if (strcmp (diffSection->name, secNew->name) != 0)
519 {
520 /* Section not found in diffs configuration */
521 diffSection->next =
522 GNUNET_malloc (sizeof (struct ConfigSection));
523 memcpy (diffSection->next, secNew,
524 sizeof (struct ConfigSection));
525 diffSection->next->entries = NULL;
526 diffSection->next->next = NULL;
527 }
528 else
529 {
530 diffEntry = diffSection->entries;
531 }
532 }
533
534 if (diffEntry == NULL)
535 {
536 /* First Entry */
537 diffEntry = GNUNET_malloc (sizeof (struct ConfigEntry));
538 memcpy (diffEntry, entNew, sizeof (struct ConfigEntry));
539 if (diffSection->next == NULL)
540 /* The first Entry of the first Section */
541 diffSection->entries = diffEntry;
542 else
543 /* The first entry of the non-first Section */
544 diffSection->next->entries = diffEntry;
545 diffEntry->next = NULL;
546 }
547 else
548 {
549 while (diffEntry->next != NULL)
550 {
551 diffEntry = diffEntry->next;
552 }
553 diffEntry->next = GNUNET_malloc (sizeof (struct ConfigEntry));
554 memcpy (diffEntry->next, entNew, sizeof (struct ConfigEntry));
555 diffEntry->next->next = NULL;
556 }
557 }
558} 500}
559 501
560 502
@@ -566,21 +508,18 @@ compareEntries (void *cls,
566 * @return GNUNET_OK on success, GNUNET_SYSERR on error 508 * @return GNUNET_OK on success, GNUNET_SYSERR on error
567 */ 509 */
568int 510int
569GNUNET_CONFIGURATION_write_diffs (struct GNUNET_CONFIGURATION_Handle 511GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
570 *cfgDefault, 512 *cfgDefault,
571 struct GNUNET_CONFIGURATION_Handle *cfgNew, 513 const struct GNUNET_CONFIGURATION_Handle *cfgNew,
572 const char *filename) 514 const char *filename)
573{ 515{
574 int ret; 516 int ret;
575 struct GNUNNET_CONFIGURATION_Diff_Handle diffHandle; 517 struct DiffHandle diffHandle;
576 diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
577 diffHandle.cfgDiff->sections = NULL;
578 diffHandle.cfgNew = cfgNew;
579 GNUNET_CONFIGURATION_iterate (cfgDefault, compareEntries, &diffHandle);
580 518
519 diffHandle.cfgDiff = GNUNET_CONFIGURATION_create ();
520 diffHandle.cfgDefault = cfgDefault;
521 GNUNET_CONFIGURATION_iterate (cfgNew, compareEntries, &diffHandle);
581 ret = GNUNET_CONFIGURATION_write (diffHandle.cfgDiff, filename); 522 ret = GNUNET_CONFIGURATION_write (diffHandle.cfgDiff, filename);
582
583 /* Housekeeping */
584 GNUNET_CONFIGURATION_destroy (diffHandle.cfgDiff); 523 GNUNET_CONFIGURATION_destroy (diffHandle.cfgDiff);
585 return ret; 524 return ret;
586} 525}