diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-11 13:41:40 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-11 13:41:40 +0000 |
commit | fd6abc8eccbbf839d877062ff63cab510f3ae707 (patch) | |
tree | 718186b113fbe9b6779a072362068fdaa9df2169 /src/util/configuration.c | |
parent | 9a50e92d4a43f917b0cd1ed34d4932470cb3a3da (diff) | |
download | gnunet-fd6abc8eccbbf839d877062ff63cab510f3ae707.tar.gz gnunet-fd6abc8eccbbf839d877062ff63cab510f3ae707.zip |
-doxygen, code style, indentation fixes
Diffstat (limited to 'src/util/configuration.c')
-rw-r--r-- | src/util/configuration.c | 194 |
1 files changed, 109 insertions, 85 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c index 1e516b825..039f764ca 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c | |||
@@ -102,12 +102,12 @@ struct GNUNET_CONFIGURATION_Handle | |||
102 | */ | 102 | */ |
103 | struct DiffHandle | 103 | struct DiffHandle |
104 | { | 104 | { |
105 | const struct GNUNET_CONFIGURATION_Handle *cfgDefault; | 105 | const struct GNUNET_CONFIGURATION_Handle *cfg_default; |
106 | |||
106 | struct GNUNET_CONFIGURATION_Handle *cfgDiff; | 107 | struct GNUNET_CONFIGURATION_Handle *cfgDiff; |
107 | }; | 108 | }; |
108 | 109 | ||
109 | 110 | ||
110 | |||
111 | /** | 111 | /** |
112 | * Create a GNUNET_CONFIGURATION_Handle. | 112 | * Create a GNUNET_CONFIGURATION_Handle. |
113 | * | 113 | * |
@@ -304,7 +304,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
304 | * | 304 | * |
305 | * @param cfg configuration to update | 305 | * @param cfg configuration to update |
306 | * @param filename name of the configuration file | 306 | * @param filename name of the configuration file |
307 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 307 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
308 | */ | 308 | */ |
309 | int | 309 | int |
310 | GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | 310 | GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, |
@@ -317,9 +317,13 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
317 | int dirty; | 317 | int dirty; |
318 | int ret; | 318 | int ret; |
319 | 319 | ||
320 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to parse config file `%s'\n", filename); | 320 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
321 | "Asked to parse config file `%s'\n", | ||
322 | filename); | ||
321 | fn = GNUNET_STRINGS_filename_expand (filename); | 323 | fn = GNUNET_STRINGS_filename_expand (filename); |
322 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Config file name expanded to `%s'\n", fn); | 324 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
325 | "Config file name expanded to `%s'\n", | ||
326 | fn); | ||
323 | if (fn == NULL) | 327 | if (fn == NULL) |
324 | return GNUNET_SYSERR; | 328 | return GNUNET_SYSERR; |
325 | dirty = cfg->dirty; /* back up value! */ | 329 | dirty = cfg->dirty; /* back up value! */ |
@@ -363,7 +367,7 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
363 | * changed since the last save. | 367 | * changed since the last save. |
364 | * | 368 | * |
365 | * @param cfg configuration to inspect | 369 | * @param cfg configuration to inspect |
366 | * @return GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error (i.e. last save failed) | 370 | * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed) |
367 | */ | 371 | */ |
368 | int | 372 | int |
369 | GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg) | 373 | GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg) |
@@ -467,7 +471,7 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
467 | * | 471 | * |
468 | * @param cfg configuration to write | 472 | * @param cfg configuration to write |
469 | * @param filename where to write the configuration | 473 | * @param filename where to write the configuration |
470 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 474 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
471 | */ | 475 | */ |
472 | int | 476 | int |
473 | GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, | 477 | GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, |
@@ -511,7 +515,7 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
511 | * | 515 | * |
512 | * @param cfg configuration to inspect | 516 | * @param cfg configuration to inspect |
513 | * @param iter function to call on each option | 517 | * @param iter function to call on each option |
514 | * @param iter_cls closure for iter | 518 | * @param iter_cls closure for @a iter |
515 | */ | 519 | */ |
516 | void | 520 | void |
517 | GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | 521 | GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, |
@@ -534,7 +538,7 @@ GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
534 | * @param cfg configuration to inspect | 538 | * @param cfg configuration to inspect |
535 | * @param section the section | 539 | * @param section the section |
536 | * @param iter function to call on each option | 540 | * @param iter function to call on each option |
537 | * @param iter_cls closure for iter | 541 | * @param iter_cls closure for @a iter |
538 | */ | 542 | */ |
539 | void | 543 | void |
540 | GNUNET_CONFIGURATION_iterate_section_values (const struct | 544 | GNUNET_CONFIGURATION_iterate_section_values (const struct |
@@ -562,7 +566,7 @@ GNUNET_CONFIGURATION_iterate_section_values (const struct | |||
562 | * | 566 | * |
563 | * @param cfg configuration to inspect | 567 | * @param cfg configuration to inspect |
564 | * @param iter function to call on each section | 568 | * @param iter function to call on each section |
565 | * @param iter_cls closure for iter | 569 | * @param iter_cls closure for @a iter |
566 | */ | 570 | */ |
567 | void | 571 | void |
568 | GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle | 572 | GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle |
@@ -582,6 +586,7 @@ GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle | |||
582 | } | 586 | } |
583 | } | 587 | } |
584 | 588 | ||
589 | |||
585 | /** | 590 | /** |
586 | * Remove the given section and all options in it. | 591 | * Remove the given section and all options in it. |
587 | * | 592 | * |
@@ -628,13 +633,15 @@ GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
628 | * Copy a configuration value to the given target configuration. | 633 | * Copy a configuration value to the given target configuration. |
629 | * Overwrites existing entries. | 634 | * Overwrites existing entries. |
630 | * | 635 | * |
631 | * @param cls the destination configuration (struct GNUNET_CONFIGURATION_Handle*) | 636 | * @param cls the destination configuration (`struct GNUNET_CONFIGURATION_Handle *`) |
632 | * @param section section for the value | 637 | * @param section section for the value |
633 | * @param option option name of the value | 638 | * @param option option name of the value |
634 | * @param value value to copy | 639 | * @param value value to copy |
635 | */ | 640 | */ |
636 | static void | 641 | static void |
637 | copy_entry (void *cls, const char *section, const char *option, | 642 | copy_entry (void *cls, |
643 | const char *section, | ||
644 | const char *option, | ||
638 | const char *value) | 645 | const char *value) |
639 | { | 646 | { |
640 | struct GNUNET_CONFIGURATION_Handle *dst = cls; | 647 | struct GNUNET_CONFIGURATION_Handle *dst = cls; |
@@ -663,12 +670,13 @@ GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
663 | /** | 670 | /** |
664 | * Find a section entry from a configuration. | 671 | * Find a section entry from a configuration. |
665 | * | 672 | * |
666 | * @param cfg FIXME | 673 | * @param cfg configuration to search in |
667 | * @param section FIXME | 674 | * @param section name of the section to look for |
668 | * @return matching entry, NULL if not found | 675 | * @return matching entry, NULL if not found |
669 | */ | 676 | */ |
670 | static struct ConfigSection * | 677 | static struct ConfigSection * |
671 | findSection (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section) | 678 | find_section (const struct GNUNET_CONFIGURATION_Handle *cfg, |
679 | const char *section) | ||
672 | { | 680 | { |
673 | struct ConfigSection *pos; | 681 | struct ConfigSection *pos; |
674 | 682 | ||
@@ -688,13 +696,14 @@ findSection (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section) | |||
688 | * @return matching entry, NULL if not found | 696 | * @return matching entry, NULL if not found |
689 | */ | 697 | */ |
690 | static struct ConfigEntry * | 698 | static struct ConfigEntry * |
691 | findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, | 699 | find_entry (const struct GNUNET_CONFIGURATION_Handle *cfg, |
700 | const char *section, | ||
692 | const char *key) | 701 | const char *key) |
693 | { | 702 | { |
694 | struct ConfigSection *sec; | 703 | struct ConfigSection *sec; |
695 | struct ConfigEntry *pos; | 704 | struct ConfigEntry *pos; |
696 | 705 | ||
697 | if (NULL == (sec = findSection (cfg, section))) | 706 | if (NULL == (sec = find_section (cfg, section))) |
698 | return NULL; | 707 | return NULL; |
699 | pos = sec->entries; | 708 | pos = sec->entries; |
700 | while ((pos != NULL) && (0 != strcasecmp (key, pos->key))) | 709 | while ((pos != NULL) && (0 != strcasecmp (key, pos->key))) |
@@ -708,19 +717,21 @@ findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, | |||
708 | * (default against a new configuration) and write the diffs in a | 717 | * (default against a new configuration) and write the diffs in a |
709 | * diff-configuration object (the callback object). | 718 | * diff-configuration object (the callback object). |
710 | * | 719 | * |
711 | * @param cls the diff configuration (struct DiffHandle*) | 720 | * @param cls the diff configuration (`struct DiffHandle *`) |
712 | * @param section section for the value (of the default conf.) | 721 | * @param section section for the value (of the default conf.) |
713 | * @param option option name of the value (of the default conf.) | 722 | * @param option option name of the value (of the default conf.) |
714 | * @param value value to copy (of the default conf.) | 723 | * @param value value to copy (of the default conf.) |
715 | */ | 724 | */ |
716 | static void | 725 | static void |
717 | compare_entries (void *cls, const char *section, const char *option, | 726 | compare_entries (void *cls, |
727 | const char *section, | ||
728 | const char *option, | ||
718 | const char *value) | 729 | const char *value) |
719 | { | 730 | { |
720 | struct DiffHandle *dh = cls; | 731 | struct DiffHandle *dh = cls; |
721 | struct ConfigEntry *entNew; | 732 | struct ConfigEntry *entNew; |
722 | 733 | ||
723 | entNew = findEntry (dh->cfgDefault, section, option); | 734 | entNew = find_entry (dh->cfg_default, section, option); |
724 | if ( (NULL != entNew) && | 735 | if ( (NULL != entNew) && |
725 | (NULL != entNew->val) && | 736 | (NULL != entNew->val) && |
726 | (0 == strcmp (entNew->val, value)) ) | 737 | (0 == strcmp (entNew->val, value)) ) |
@@ -732,42 +743,41 @@ compare_entries (void *cls, const char *section, const char *option, | |||
732 | /** | 743 | /** |
733 | * Compute configuration with only entries that have been changed | 744 | * Compute configuration with only entries that have been changed |
734 | * | 745 | * |
735 | * @param cfgDefault original configuration | 746 | * @param cfg_default original configuration |
736 | * @param cfgNew new configuration | 747 | * @param cfg_new new configuration |
737 | * @return configuration with only the differences, never NULL | 748 | * @return configuration with only the differences, never NULL |
738 | */ | 749 | */ |
739 | struct GNUNET_CONFIGURATION_Handle * | 750 | struct GNUNET_CONFIGURATION_Handle * |
740 | GNUNET_CONFIGURATION_get_diff (const struct GNUNET_CONFIGURATION_Handle | 751 | GNUNET_CONFIGURATION_get_diff (const struct GNUNET_CONFIGURATION_Handle *cfg_default, |
741 | *cfgDefault, | 752 | const struct GNUNET_CONFIGURATION_Handle *cfg_new) |
742 | const struct GNUNET_CONFIGURATION_Handle | ||
743 | *cfgNew) | ||
744 | { | 753 | { |
745 | struct DiffHandle diffHandle; | 754 | struct DiffHandle diffHandle; |
746 | 755 | ||
747 | diffHandle.cfgDiff = GNUNET_CONFIGURATION_create (); | 756 | diffHandle.cfgDiff = GNUNET_CONFIGURATION_create (); |
748 | diffHandle.cfgDefault = cfgDefault; | 757 | diffHandle.cfg_default = cfg_default; |
749 | GNUNET_CONFIGURATION_iterate (cfgNew, &compare_entries, &diffHandle); | 758 | GNUNET_CONFIGURATION_iterate (cfg_new, &compare_entries, &diffHandle); |
750 | return diffHandle.cfgDiff; | 759 | return diffHandle.cfgDiff; |
751 | } | 760 | } |
752 | 761 | ||
753 | 762 | ||
754 | /** | 763 | /** |
755 | * Write only configuration entries that have been changed to configuration file | 764 | * Write only configuration entries that have been changed to configuration file |
756 | * @param cfgDefault default configuration | 765 | * |
757 | * @param cfgNew new configuration | 766 | * @param cfg_default default configuration |
767 | * @param cfg_new new configuration | ||
758 | * @param filename where to write the configuration diff between default and new | 768 | * @param filename where to write the configuration diff between default and new |
759 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 769 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
760 | */ | 770 | */ |
761 | int | 771 | int |
762 | GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle | 772 | GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle |
763 | *cfgDefault, | 773 | *cfg_default, |
764 | const struct GNUNET_CONFIGURATION_Handle | 774 | const struct GNUNET_CONFIGURATION_Handle |
765 | *cfgNew, const char *filename) | 775 | *cfg_new, const char *filename) |
766 | { | 776 | { |
767 | int ret; | 777 | int ret; |
768 | struct GNUNET_CONFIGURATION_Handle *diff; | 778 | struct GNUNET_CONFIGURATION_Handle *diff; |
769 | 779 | ||
770 | diff = GNUNET_CONFIGURATION_get_diff (cfgDefault, cfgNew); | 780 | diff = GNUNET_CONFIGURATION_get_diff (cfg_default, cfg_new); |
771 | ret = GNUNET_CONFIGURATION_write (diff, filename); | 781 | ret = GNUNET_CONFIGURATION_write (diff, filename); |
772 | GNUNET_CONFIGURATION_destroy (diff); | 782 | GNUNET_CONFIGURATION_destroy (diff); |
773 | return ret; | 783 | return ret; |
@@ -791,7 +801,7 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
791 | struct ConfigEntry *e; | 801 | struct ConfigEntry *e; |
792 | char *nv; | 802 | char *nv; |
793 | 803 | ||
794 | e = findEntry (cfg, section, option); | 804 | e = find_entry (cfg, section, option); |
795 | if (NULL != e) | 805 | if (NULL != e) |
796 | { | 806 | { |
797 | if (NULL == value) | 807 | if (NULL == value) |
@@ -807,7 +817,7 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
807 | } | 817 | } |
808 | return; | 818 | return; |
809 | } | 819 | } |
810 | sec = findSection (cfg, section); | 820 | sec = find_section (cfg, section); |
811 | if (sec == NULL) | 821 | if (sec == NULL) |
812 | { | 822 | { |
813 | sec = GNUNET_new (struct ConfigSection); | 823 | sec = GNUNET_new (struct ConfigSection); |
@@ -850,7 +860,7 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
850 | * @param section section of interest | 860 | * @param section section of interest |
851 | * @param option option of interest | 861 | * @param option option of interest |
852 | * @param number where to store the numeric value of the option | 862 | * @param number where to store the numeric value of the option |
853 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 863 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
854 | */ | 864 | */ |
855 | int | 865 | int |
856 | GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle | 866 | GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle |
@@ -860,7 +870,7 @@ GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle | |||
860 | { | 870 | { |
861 | struct ConfigEntry *e; | 871 | struct ConfigEntry *e; |
862 | 872 | ||
863 | if (NULL == (e = findEntry (cfg, section, option))) | 873 | if (NULL == (e = find_entry (cfg, section, option))) |
864 | return GNUNET_SYSERR; | 874 | return GNUNET_SYSERR; |
865 | if (NULL == e->val) | 875 | if (NULL == e->val) |
866 | return GNUNET_SYSERR; | 876 | return GNUNET_SYSERR; |
@@ -877,7 +887,7 @@ GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle | |||
877 | * @param section section of interest | 887 | * @param section section of interest |
878 | * @param option option of interest | 888 | * @param option option of interest |
879 | * @param time set to the time value stored in the configuration | 889 | * @param time set to the time value stored in the configuration |
880 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 890 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
881 | */ | 891 | */ |
882 | int | 892 | int |
883 | GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle | 893 | GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle |
@@ -887,7 +897,7 @@ GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle | |||
887 | { | 897 | { |
888 | struct ConfigEntry *e; | 898 | struct ConfigEntry *e; |
889 | 899 | ||
890 | if (NULL == (e = findEntry (cfg, section, option))) | 900 | if (NULL == (e = find_entry (cfg, section, option))) |
891 | return GNUNET_SYSERR; | 901 | return GNUNET_SYSERR; |
892 | if (NULL == e->val) | 902 | if (NULL == e->val) |
893 | return GNUNET_SYSERR; | 903 | return GNUNET_SYSERR; |
@@ -902,17 +912,17 @@ GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle | |||
902 | * @param section section of interest | 912 | * @param section section of interest |
903 | * @param option option of interest | 913 | * @param option option of interest |
904 | * @param size set to the size in bytes as stored in the configuration | 914 | * @param size set to the size in bytes as stored in the configuration |
905 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 915 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
906 | */ | 916 | */ |
907 | int | 917 | int |
908 | GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle | 918 | GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle *cfg, |
909 | *cfg, const char *section, | 919 | const char *section, |
910 | const char *option, | 920 | const char *option, |
911 | unsigned long long *size) | 921 | unsigned long long *size) |
912 | { | 922 | { |
913 | struct ConfigEntry *e; | 923 | struct ConfigEntry *e; |
914 | 924 | ||
915 | if (NULL == (e = findEntry (cfg, section, option))) | 925 | if (NULL == (e = find_entry (cfg, section, option))) |
916 | return GNUNET_SYSERR; | 926 | return GNUNET_SYSERR; |
917 | if (NULL == e->val) | 927 | if (NULL == e->val) |
918 | return GNUNET_SYSERR; | 928 | return GNUNET_SYSERR; |
@@ -928,17 +938,21 @@ GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle | |||
928 | * @param option option of interest | 938 | * @param option option of interest |
929 | * @param value will be set to a freshly allocated configuration | 939 | * @param value will be set to a freshly allocated configuration |
930 | * value, or NULL if option is not specified | 940 | * value, or NULL if option is not specified |
931 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 941 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
932 | */ | 942 | */ |
933 | int | 943 | int |
934 | GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle | 944 | GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle *cfg, |
935 | *cfg, const char *section, | 945 | const char *section, |
936 | const char *option, char **value) | 946 | const char *option, |
947 | char **value) | ||
937 | { | 948 | { |
938 | struct ConfigEntry *e; | 949 | struct ConfigEntry *e; |
939 | 950 | ||
940 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to retrieve string `%s' in section `%s'\n", option, section); | 951 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
941 | if ( (NULL == (e = findEntry (cfg, section, option))) || | 952 | "Asked to retrieve string `%s' in section `%s'\n", |
953 | option, | ||
954 | section); | ||
955 | if ( (NULL == (e = find_entry (cfg, section, option))) || | ||
942 | (NULL == e->val) ) | 956 | (NULL == e->val) ) |
943 | { | 957 | { |
944 | *value = NULL; | 958 | *value = NULL; |
@@ -959,18 +973,19 @@ GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle | |||
959 | * @param choices NULL-terminated list of legal values | 973 | * @param choices NULL-terminated list of legal values |
960 | * @param value will be set to an entry in the legal list, | 974 | * @param value will be set to an entry in the legal list, |
961 | * or NULL if option is not specified and no default given | 975 | * or NULL if option is not specified and no default given |
962 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 976 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
963 | */ | 977 | */ |
964 | int | 978 | int |
965 | GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle | 979 | GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle *cfg, |
966 | *cfg, const char *section, | 980 | const char *section, |
967 | const char *option, const char *const *choices, | 981 | const char *option, |
982 | const char *const *choices, | ||
968 | const char **value) | 983 | const char **value) |
969 | { | 984 | { |
970 | struct ConfigEntry *e; | 985 | struct ConfigEntry *e; |
971 | unsigned int i; | 986 | unsigned int i; |
972 | 987 | ||
973 | if (NULL == (e = findEntry (cfg, section, option))) | 988 | if (NULL == (e = find_entry (cfg, section, option))) |
974 | return GNUNET_SYSERR; | 989 | return GNUNET_SYSERR; |
975 | for (i = 0; NULL != choices[i]; i++) | 990 | for (i = 0; NULL != choices[i]; i++) |
976 | if (0 == strcasecmp (choices[i], e->val)) | 991 | if (0 == strcasecmp (choices[i], e->val)) |
@@ -979,7 +994,9 @@ GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle | |||
979 | { | 994 | { |
980 | LOG (GNUNET_ERROR_TYPE_ERROR, | 995 | LOG (GNUNET_ERROR_TYPE_ERROR, |
981 | _("Configuration value '%s' for '%s'" | 996 | _("Configuration value '%s' for '%s'" |
982 | " in section '%s' is not in set of legal choices\n"), e->val, option, | 997 | " in section '%s' is not in set of legal choices\n"), |
998 | e->val, | ||
999 | option, | ||
983 | section); | 1000 | section); |
984 | return GNUNET_SYSERR; | 1001 | return GNUNET_SYSERR; |
985 | } | 1002 | } |
@@ -990,6 +1007,7 @@ GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle | |||
990 | 1007 | ||
991 | /** | 1008 | /** |
992 | * Test if we have a value for a particular option | 1009 | * Test if we have a value for a particular option |
1010 | * | ||
993 | * @param cfg configuration to inspect | 1011 | * @param cfg configuration to inspect |
994 | * @param section section of interest | 1012 | * @param section section of interest |
995 | * @param option option of interest | 1013 | * @param option option of interest |
@@ -1001,7 +1019,7 @@ GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1001 | { | 1019 | { |
1002 | struct ConfigEntry *e; | 1020 | struct ConfigEntry *e; |
1003 | 1021 | ||
1004 | if ((NULL == (e = findEntry (cfg, section, option))) || (NULL == e->val)) | 1022 | if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val)) |
1005 | return GNUNET_NO; | 1023 | return GNUNET_NO; |
1006 | return GNUNET_YES; | 1024 | return GNUNET_YES; |
1007 | } | 1025 | } |
@@ -1193,21 +1211,25 @@ GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cf | |||
1193 | * @param option option of interest | 1211 | * @param option option of interest |
1194 | * @param value will be set to a freshly allocated configuration | 1212 | * @param value will be set to a freshly allocated configuration |
1195 | * value, or NULL if option is not specified | 1213 | * value, or NULL if option is not specified |
1196 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 1214 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1197 | */ | 1215 | */ |
1198 | int | 1216 | int |
1199 | GNUNET_CONFIGURATION_get_value_filename (const struct | 1217 | GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, |
1200 | GNUNET_CONFIGURATION_Handle *cfg, | ||
1201 | const char *section, | 1218 | const char *section, |
1202 | const char *option, char **value) | 1219 | const char *option, |
1220 | char **value) | ||
1203 | { | 1221 | { |
1204 | char *tmp; | 1222 | char *tmp; |
1205 | 1223 | ||
1206 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to retrieve filename `%s' in section `%s'\n", option, section); | 1224 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1225 | "Asked to retrieve filename `%s' in section `%s'\n", | ||
1226 | option, | ||
1227 | section); | ||
1207 | if (GNUNET_OK != | 1228 | if (GNUNET_OK != |
1208 | GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp)) | 1229 | GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp)) |
1209 | { | 1230 | { |
1210 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to retrieve filename\n"); | 1231 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1232 | "Failed to retrieve filename\n"); | ||
1211 | *value = NULL; | 1233 | *value = NULL; |
1212 | return GNUNET_SYSERR; | 1234 | return GNUNET_SYSERR; |
1213 | } | 1235 | } |
@@ -1225,16 +1247,16 @@ GNUNET_CONFIGURATION_get_value_filename (const struct | |||
1225 | 1247 | ||
1226 | /** | 1248 | /** |
1227 | * Get a configuration value that should be in a set of | 1249 | * Get a configuration value that should be in a set of |
1228 | * "GNUNET_YES" or "GNUNET_NO". | 1250 | * "YES" or "NO". |
1229 | * | 1251 | * |
1230 | * @param cfg configuration to inspect | 1252 | * @param cfg configuration to inspect |
1231 | * @param section section of interest | 1253 | * @param section section of interest |
1232 | * @param option option of interest | 1254 | * @param option option of interest |
1233 | * @return GNUNET_YES, GNUNET_NO or GNUNET_SYSERR | 1255 | * @return #GNUNET_YES, #GNUNET_NO or #GNUNET_SYSERR |
1234 | */ | 1256 | */ |
1235 | int | 1257 | int |
1236 | GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle | 1258 | GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle *cfg, |
1237 | *cfg, const char *section, | 1259 | const char *section, |
1238 | const char *option) | 1260 | const char *option) |
1239 | { | 1261 | { |
1240 | static const char *yesno[] = { "YES", "NO", NULL }; | 1262 | static const char *yesno[] = { "YES", "NO", NULL }; |
@@ -1258,12 +1280,11 @@ GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle | |||
1258 | * @param section section of interest | 1280 | * @param section section of interest |
1259 | * @param option option of interest | 1281 | * @param option option of interest |
1260 | * @param cb function to call on each filename | 1282 | * @param cb function to call on each filename |
1261 | * @param cb_cls closure for cb | 1283 | * @param cb_cls closure for @a cb |
1262 | * @return number of filenames iterated over, -1 on error | 1284 | * @return number of filenames iterated over, -1 on error |
1263 | */ | 1285 | */ |
1264 | int | 1286 | int |
1265 | GNUNET_CONFIGURATION_iterate_value_filenames (const struct | 1287 | GNUNET_CONFIGURATION_iterate_value_filenames (const struct GNUNET_CONFIGURATION_Handle *cfg, |
1266 | GNUNET_CONFIGURATION_Handle *cfg, | ||
1267 | const char *section, | 1288 | const char *section, |
1268 | const char *option, | 1289 | const char *option, |
1269 | GNUNET_FileNameCallback cb, | 1290 | GNUNET_FileNameCallback cb, |
@@ -1369,7 +1390,7 @@ escape_name (const char *value) | |||
1369 | * | 1390 | * |
1370 | * @param cls string we compare with (const char*) | 1391 | * @param cls string we compare with (const char*) |
1371 | * @param fn filename we are currently looking at | 1392 | * @param fn filename we are currently looking at |
1372 | * @return GNUNET_OK if the names do not match, GNUNET_SYSERR if they do | 1393 | * @return #GNUNET_OK if the names do not match, #GNUNET_SYSERR if they do |
1373 | */ | 1394 | */ |
1374 | static int | 1395 | static int |
1375 | test_match (void *cls, const char *fn) | 1396 | test_match (void *cls, const char *fn) |
@@ -1388,13 +1409,13 @@ test_match (void *cls, const char *fn) | |||
1388 | * @param section section of interest | 1409 | * @param section section of interest |
1389 | * @param option option of interest | 1410 | * @param option option of interest |
1390 | * @param value filename to append | 1411 | * @param value filename to append |
1391 | * @return GNUNET_OK on success, | 1412 | * @return #GNUNET_OK on success, |
1392 | * GNUNET_NO if the filename already in the list | 1413 | * #GNUNET_NO if the filename already in the list |
1393 | * GNUNET_SYSERR on error | 1414 | * #GNUNET_SYSERR on error |
1394 | */ | 1415 | */ |
1395 | int | 1416 | int |
1396 | GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle | 1417 | GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg, |
1397 | *cfg, const char *section, | 1418 | const char *section, |
1398 | const char *option, | 1419 | const char *option, |
1399 | const char *value) | 1420 | const char *value) |
1400 | { | 1421 | { |
@@ -1432,9 +1453,9 @@ GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle | |||
1432 | * @param section section of interest | 1453 | * @param section section of interest |
1433 | * @param option option of interest | 1454 | * @param option option of interest |
1434 | * @param value filename to remove | 1455 | * @param value filename to remove |
1435 | * @return GNUNET_OK on success, | 1456 | * @return #GNUNET_OK on success, |
1436 | * GNUNET_NO if the filename is not in the list, | 1457 | * #GNUNET_NO if the filename is not in the list, |
1437 | * GNUNET_SYSERR on error | 1458 | * #GNUNET_SYSERR on error |
1438 | */ | 1459 | */ |
1439 | int | 1460 | int |
1440 | GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle | 1461 | GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle |
@@ -1510,11 +1531,13 @@ GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle | |||
1510 | 1531 | ||
1511 | 1532 | ||
1512 | /** | 1533 | /** |
1513 | * Wrapper around GNUNET_CONFIGURATION_parse. | 1534 | * Wrapper around #GNUNET_CONFIGURATION_parse. Called on each |
1535 | * file in a directory, we trigger parsing on those files that | ||
1536 | * end with ".conf". | ||
1514 | * | 1537 | * |
1515 | * @param cls the cfg | 1538 | * @param cls the cfg |
1516 | * @param filename file to parse | 1539 | * @param filename file to parse |
1517 | * @return GNUNET_OK on success | 1540 | * @return #GNUNET_OK on success |
1518 | */ | 1541 | */ |
1519 | static int | 1542 | static int |
1520 | parse_configuration_file (void *cls, const char *filename) | 1543 | parse_configuration_file (void *cls, const char *filename) |
@@ -1527,7 +1550,9 @@ parse_configuration_file (void *cls, const char *filename) | |||
1527 | ext = strrchr (filename, '.'); | 1550 | ext = strrchr (filename, '.'); |
1528 | if ((NULL == ext) || (0 != strcmp (ext, ".conf"))) | 1551 | if ((NULL == ext) || (0 != strcmp (ext, ".conf"))) |
1529 | { | 1552 | { |
1530 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Skipping file `%s'\n", filename); | 1553 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1554 | "Skipping file `%s'\n", | ||
1555 | filename); | ||
1531 | return GNUNET_OK; | 1556 | return GNUNET_OK; |
1532 | } | 1557 | } |
1533 | 1558 | ||
@@ -1542,7 +1567,7 @@ parse_configuration_file (void *cls, const char *filename) | |||
1542 | * | 1567 | * |
1543 | * @param cfg configuration to update | 1568 | * @param cfg configuration to update |
1544 | * @param defaults_d directory with the defaults | 1569 | * @param defaults_d directory with the defaults |
1545 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 1570 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1546 | */ | 1571 | */ |
1547 | int | 1572 | int |
1548 | GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, | 1573 | GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, |
@@ -1561,7 +1586,7 @@ GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1561 | * | 1586 | * |
1562 | * @param cfg configuration to update | 1587 | * @param cfg configuration to update |
1563 | * @param filename name of the configuration file, NULL to load defaults | 1588 | * @param filename name of the configuration file, NULL to load defaults |
1564 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 1589 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1565 | */ | 1590 | */ |
1566 | int | 1591 | int |
1567 | GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | 1592 | GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, |
@@ -1598,5 +1623,4 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1598 | } | 1623 | } |
1599 | 1624 | ||
1600 | 1625 | ||
1601 | |||
1602 | /* end of configuration.c */ | 1626 | /* end of configuration.c */ |