diff options
Diffstat (limited to 'src/util/configuration.c')
-rw-r--r-- | src/util/configuration.c | 178 |
1 files changed, 94 insertions, 84 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c index d64ca8e83..250f9d3d5 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c | |||
@@ -102,9 +102,10 @@ struct GNUNET_CONFIGURATION_Handle | |||
102 | * Used for diffing a configuration object against | 102 | * Used for diffing a configuration object against |
103 | * the default one | 103 | * the default one |
104 | */ | 104 | */ |
105 | struct GNUNNET_CONFIGURATION_Diff_Handle{ | 105 | struct GNUNNET_CONFIGURATION_Diff_Handle |
106 | struct GNUNET_CONFIGURATION_Handle* cfgNew; | 106 | { |
107 | struct GNUNET_CONFIGURATION_Handle* cfgDiff; | 107 | struct GNUNET_CONFIGURATION_Handle *cfgNew; |
108 | struct GNUNET_CONFIGURATION_Handle *cfgDiff; | ||
108 | }; | 109 | }; |
109 | 110 | ||
110 | 111 | ||
@@ -479,71 +480,81 @@ findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
479 | * @param option option name of the value (of the default conf.) | 480 | * @param option option name of the value (of the default conf.) |
480 | * @param value value to copy (of the default conf.) | 481 | * @param value value to copy (of the default conf.) |
481 | */ | 482 | */ |
482 | void | 483 | void |
483 | compareEntries( | 484 | compareEntries (void *cls, |
484 | void *cls, | 485 | const char *section, const char *option, const char *value) |
485 | const char *section, | ||
486 | const char *option, | ||
487 | const char *value) | ||
488 | { | 486 | { |
489 | struct ConfigSection *secNew; | 487 | struct ConfigSection *secNew; |
490 | struct ConfigEntry *entNew; | 488 | struct ConfigEntry *entNew; |
491 | struct GNUNNET_CONFIGURATION_Diff_Handle* cfgDiff = (struct GNUNNET_CONFIGURATION_Diff_Handle*)cls; | 489 | struct GNUNNET_CONFIGURATION_Diff_Handle *cfgDiff = |
492 | 490 | (struct GNUNNET_CONFIGURATION_Diff_Handle *) cls; | |
493 | secNew = findSection(cfgDiff->cfgNew, section); | 491 | |
494 | entNew = findEntry(cfgDiff->cfgNew, section, option); | 492 | secNew = findSection (cfgDiff->cfgNew, section); |
495 | if (secNew && strcmp(entNew->val, value) != 0) { | 493 | entNew = findEntry (cfgDiff->cfgNew, section, option); |
496 | /* Value in the new configuration has been changed */ | 494 | if (secNew && strcmp (entNew->val, value) != 0) |
497 | /* Add the changed value to the diff configuration object */ | 495 | { |
498 | struct ConfigEntry *diffEntry = NULL; | 496 | /* Value in the new configuration has been changed */ |
499 | struct ConfigSection *diffSection = NULL; | 497 | /* Add the changed value to the diff configuration object */ |
500 | 498 | struct ConfigEntry *diffEntry = NULL; | |
501 | diffSection = cfgDiff->cfgDiff->sections; | 499 | struct ConfigSection *diffSection = NULL; |
502 | if (diffSection == NULL) { | 500 | |
503 | /* First section */ | 501 | diffSection = cfgDiff->cfgDiff->sections; |
504 | diffSection = GNUNET_malloc(sizeof(struct ConfigSection)); | 502 | if (diffSection == NULL) |
505 | memcpy(diffSection, secNew, sizeof(struct ConfigSection)); | 503 | { |
506 | cfgDiff->cfgDiff->sections = diffSection; | 504 | /* First section */ |
507 | diffSection->entries = NULL; | 505 | diffSection = GNUNET_malloc (sizeof (struct ConfigSection)); |
508 | diffSection->next = NULL; | 506 | memcpy (diffSection, secNew, sizeof (struct ConfigSection)); |
509 | } | 507 | cfgDiff->cfgDiff->sections = diffSection; |
510 | else { | 508 | diffSection->entries = NULL; |
511 | while ((strcmp(diffSection->name, secNew->name) != 0) && (diffSection->next != NULL)) { | 509 | diffSection->next = NULL; |
512 | diffSection = diffSection->next; | 510 | } |
513 | } | 511 | else |
514 | if (strcmp(diffSection->name, secNew->name) != 0) { | 512 | { |
515 | /* Section not found in diffs configuration */ | 513 | while ((strcmp (diffSection->name, secNew->name) != 0) |
516 | diffSection->next = GNUNET_malloc(sizeof(struct ConfigSection)); | 514 | && (diffSection->next != NULL)) |
517 | memcpy(diffSection->next, secNew, sizeof(struct ConfigSection)); | 515 | { |
518 | diffSection->next->entries = NULL; | 516 | diffSection = diffSection->next; |
519 | diffSection->next->next = NULL; | 517 | } |
520 | } | 518 | if (strcmp (diffSection->name, secNew->name) != 0) |
521 | else { | 519 | { |
522 | diffEntry = diffSection->entries; | 520 | /* Section not found in diffs configuration */ |
523 | } | 521 | diffSection->next = |
524 | } | 522 | GNUNET_malloc (sizeof (struct ConfigSection)); |
525 | 523 | memcpy (diffSection->next, secNew, | |
526 | if (diffEntry == NULL) { | 524 | sizeof (struct ConfigSection)); |
527 | /* First Entry */ | 525 | diffSection->next->entries = NULL; |
528 | diffEntry = GNUNET_malloc(sizeof(struct ConfigEntry)); | 526 | diffSection->next->next = NULL; |
529 | memcpy(diffEntry, entNew, sizeof(struct ConfigEntry)); | 527 | } |
530 | if (diffSection->next == NULL) | 528 | else |
531 | /* The first Entry of the first Section */ | 529 | { |
532 | diffSection->entries = diffEntry; | 530 | diffEntry = diffSection->entries; |
533 | else | 531 | } |
534 | /* The first entry of the non-first Section */ | 532 | } |
535 | diffSection->next->entries = diffEntry; | 533 | |
536 | diffEntry->next = NULL; | 534 | if (diffEntry == NULL) |
537 | } | 535 | { |
538 | else { | 536 | /* First Entry */ |
539 | while (diffEntry->next != NULL) { | 537 | diffEntry = GNUNET_malloc (sizeof (struct ConfigEntry)); |
540 | diffEntry = diffEntry->next; | 538 | memcpy (diffEntry, entNew, sizeof (struct ConfigEntry)); |
541 | } | 539 | if (diffSection->next == NULL) |
542 | diffEntry->next = GNUNET_malloc(sizeof(struct ConfigEntry)); | 540 | /* The first Entry of the first Section */ |
543 | memcpy(diffEntry->next, entNew, sizeof(struct ConfigEntry)); | 541 | diffSection->entries = diffEntry; |
544 | diffEntry->next->next = NULL; | 542 | else |
545 | } | 543 | /* The first entry of the non-first Section */ |
546 | } | 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 | } | ||
547 | } | 558 | } |
548 | 559 | ||
549 | 560 | ||
@@ -555,24 +566,23 @@ compareEntries( | |||
555 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 566 | * @return GNUNET_OK on success, GNUNET_SYSERR on error |
556 | */ | 567 | */ |
557 | int | 568 | int |
558 | GNUNET_CONFIGURATION_write_diffs( | 569 | GNUNET_CONFIGURATION_write_diffs (struct GNUNET_CONFIGURATION_Handle |
559 | struct GNUNET_CONFIGURATION_Handle *cfgDefault, | 570 | *cfgDefault, |
560 | struct GNUNET_CONFIGURATION_Handle *cfgNew, | 571 | struct GNUNET_CONFIGURATION_Handle *cfgNew, |
561 | const char* filename | 572 | const char *filename) |
562 | ) | ||
563 | { | 573 | { |
564 | int ret; | 574 | int ret; |
565 | struct GNUNNET_CONFIGURATION_Diff_Handle diffHandle; | 575 | struct GNUNNET_CONFIGURATION_Diff_Handle diffHandle; |
566 | diffHandle.cfgDiff = GNUNET_CONFIGURATION_create(); | 576 | diffHandle.cfgDiff = GNUNET_CONFIGURATION_create (); |
567 | diffHandle.cfgDiff->sections = NULL; | 577 | diffHandle.cfgDiff->sections = NULL; |
568 | diffHandle.cfgNew = cfgNew; | 578 | diffHandle.cfgNew = cfgNew; |
569 | GNUNET_CONFIGURATION_iterate(cfgDefault, compareEntries, &diffHandle); | 579 | GNUNET_CONFIGURATION_iterate (cfgDefault, compareEntries, &diffHandle); |
570 | 580 | ||
571 | ret = GNUNET_CONFIGURATION_write(diffHandle.cfgDiff, filename); | 581 | ret = GNUNET_CONFIGURATION_write (diffHandle.cfgDiff, filename); |
572 | 582 | ||
573 | /* Housekeeping */ | 583 | /* Housekeeping */ |
574 | GNUNET_CONFIGURATION_destroy(diffHandle.cfgDiff); | 584 | GNUNET_CONFIGURATION_destroy (diffHandle.cfgDiff); |
575 | return ret; | 585 | return ret; |
576 | } | 586 | } |
577 | 587 | ||
578 | 588 | ||