aboutsummaryrefslogtreecommitdiff
path: root/src/util/configuration.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/configuration.c')
-rw-r--r--src/util/configuration.c109
1 files changed, 47 insertions, 62 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c
index b3b9d5ea8..534949652 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -241,8 +241,7 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
241 { 241 {
242 /* parse error */ 242 /* parse error */
243 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 243 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
244 _ 244 _("Syntax error in configuration file `%s' at line %u.\n"),
245 ("Syntax error in configuration file `%s' at line %u.\n"),
246 filename, nr); 245 filename, nr);
247 ret = GNUNET_SYSERR; 246 ret = GNUNET_SYSERR;
248 break; 247 break;
@@ -499,8 +498,8 @@ GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
499 * @param value value to copy 498 * @param value value to copy
500 */ 499 */
501static void 500static void
502copy_entry (void *cls, 501copy_entry (void *cls, const char *section, const char *option,
503 const char *section, const char *option, const char *value) 502 const char *value)
504{ 503{
505 struct GNUNET_CONFIGURATION_Handle *dst = cls; 504 struct GNUNET_CONFIGURATION_Handle *dst = cls;
506 505
@@ -553,8 +552,8 @@ findSection (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
553 * @return matching entry, NULL if not found 552 * @return matching entry, NULL if not found
554 */ 553 */
555static struct ConfigEntry * 554static struct ConfigEntry *
556findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, 555findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section,
557 const char *section, const char *key) 556 const char *key)
558{ 557{
559 struct ConfigSection *sec; 558 struct ConfigSection *sec;
560 struct ConfigEntry *pos; 559 struct ConfigEntry *pos;
@@ -580,8 +579,8 @@ findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg,
580 * @param value value to copy (of the default conf.) 579 * @param value value to copy (of the default conf.)
581 */ 580 */
582static void 581static void
583compareEntries (void *cls, 582compareEntries (void *cls, const char *section, const char *option,
584 const char *section, const char *option, const char *value) 583 const char *value)
585{ 584{
586 struct DiffHandle *dh = cls; 585 struct DiffHandle *dh = cls;
587 struct ConfigEntry *entNew; 586 struct ConfigEntry *entNew;
@@ -627,10 +626,9 @@ GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
627 * @param value value to set 626 * @param value value to set
628 */ 627 */
629void 628void
630GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle 629GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
631 *cfg, 630 const char *section, const char *option,
632 const char *section, 631 const char *value)
633 const char *option, const char *value)
634{ 632{
635 struct ConfigSection *sec; 633 struct ConfigSection *sec;
636 struct ConfigEntry *e; 634 struct ConfigEntry *e;
@@ -667,9 +665,8 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle
667 * @param number value to set 665 * @param number value to set
668 */ 666 */
669void 667void
670GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle 668GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
671 *cfg, const char *section, 669 const char *section, const char *option,
672 const char *option,
673 unsigned long long number) 670 unsigned long long number)
674{ 671{
675 char s[64]; 672 char s[64];
@@ -689,9 +686,8 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle
689 * @return GNUNET_OK on success, GNUNET_SYSERR on error 686 * @return GNUNET_OK on success, GNUNET_SYSERR on error
690 */ 687 */
691int 688int
692GNUNET_CONFIGURATION_get_value_number (const struct 689GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
693 GNUNET_CONFIGURATION_Handle *cfg, 690 *cfg, const char *section,
694 const char *section,
695 const char *option, 691 const char *option,
696 unsigned long long *number) 692 unsigned long long *number)
697{ 693{
@@ -751,9 +747,8 @@ GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
751 * @return GNUNET_OK on success, GNUNET_SYSERR on error 747 * @return GNUNET_OK on success, GNUNET_SYSERR on error
752 */ 748 */
753int 749int
754GNUNET_CONFIGURATION_get_value_string (const struct 750GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
755 GNUNET_CONFIGURATION_Handle *cfg, 751 *cfg, const char *section,
756 const char *section,
757 const char *option, char **value) 752 const char *option, char **value)
758{ 753{
759 struct ConfigEntry *e; 754 struct ConfigEntry *e;
@@ -782,11 +777,10 @@ GNUNET_CONFIGURATION_get_value_string (const struct
782 * @return GNUNET_OK on success, GNUNET_SYSERR on error 777 * @return GNUNET_OK on success, GNUNET_SYSERR on error
783 */ 778 */
784int 779int
785GNUNET_CONFIGURATION_get_value_choice (const struct 780GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle
786 GNUNET_CONFIGURATION_Handle *cfg, 781 *cfg, const char *section,
787 const char *section, 782 const char *option, const char **choices,
788 const char *option, 783 const char **value)
789 const char **choices, const char **value)
790{ 784{
791 struct ConfigEntry *e; 785 struct ConfigEntry *e;
792 int i; 786 int i;
@@ -805,8 +799,8 @@ GNUNET_CONFIGURATION_get_value_choice (const struct
805 { 799 {
806 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 800 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
807 _("Configuration value '%s' for '%s'" 801 _("Configuration value '%s' for '%s'"
808 " in section '%s' is not in set of legal choices\n"), 802 " in section '%s' is not in set of legal choices\n"), e->val,
809 e->val, option, section); 803 option, section);
810 return GNUNET_SYSERR; 804 return GNUNET_SYSERR;
811 } 805 }
812 *value = choices[i]; 806 *value = choices[i];
@@ -822,8 +816,8 @@ GNUNET_CONFIGURATION_get_value_choice (const struct
822 * @return GNUNET_YES if so, GNUNET_NO if not. 816 * @return GNUNET_YES if so, GNUNET_NO if not.
823 */ 817 */
824int 818int
825GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle 819GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
826 *cfg, const char *section, const char *option) 820 const char *section, const char *option)
827{ 821{
828 struct ConfigEntry *e; 822 struct ConfigEntry *e;
829 823
@@ -866,9 +860,8 @@ GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle
866 orig[i] = '\0'; 860 orig[i] = '\0';
867 post = &orig[i + 1]; 861 post = &orig[i + 1];
868 } 862 }
869 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, 863 if (GNUNET_OK !=
870 "PATHS", 864 GNUNET_CONFIGURATION_get_value_filename (cfg, "PATHS", &orig[1], &prefix))
871 &orig[1], &prefix))
872 { 865 {
873 if (NULL == (env = getenv (&orig[1]))) 866 if (NULL == (env = getenv (&orig[1])))
874 { 867 {
@@ -940,8 +933,8 @@ GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
940 const char *val; 933 const char *val;
941 int ret; 934 int ret;
942 935
943 ret = GNUNET_CONFIGURATION_get_value_choice (cfg, 936 ret =
944 section, option, yesno, &val); 937 GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
945 if (ret == GNUNET_SYSERR) 938 if (ret == GNUNET_SYSERR)
946 return ret; 939 return ret;
947 if (val == yesno[0]) 940 if (val == yesno[0])
@@ -962,8 +955,8 @@ GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
962 */ 955 */
963int 956int
964GNUNET_CONFIGURATION_iterate_value_filenames (const struct 957GNUNET_CONFIGURATION_iterate_value_filenames (const struct
965 GNUNET_CONFIGURATION_Handle 958 GNUNET_CONFIGURATION_Handle *cfg,
966 *cfg, const char *section, 959 const char *section,
967 const char *option, 960 const char *option,
968 GNUNET_FileNameCallback cb, 961 GNUNET_FileNameCallback cb,
969 void *cb_cls) 962 void *cb_cls)
@@ -1093,8 +1086,7 @@ test_match (void *cls, const char *fn)
1093 */ 1086 */
1094int 1087int
1095GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle 1088GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
1096 *cfg, 1089 *cfg, const char *section,
1097 const char *section,
1098 const char *option, 1090 const char *option,
1099 const char *value) 1091 const char *value)
1100{ 1092{
@@ -1102,12 +1094,10 @@ GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
1102 char *old; 1094 char *old;
1103 char *nw; 1095 char *nw;
1104 1096
1105 if (GNUNET_SYSERR 1097 if (GNUNET_SYSERR ==
1106 == GNUNET_CONFIGURATION_iterate_value_filenames (cfg, 1098 GNUNET_CONFIGURATION_iterate_value_filenames (cfg, section, option,
1107 section, 1099 &test_match,
1108 option, 1100 (void *) value))
1109 &test_match,
1110 (void *) value))
1111 return GNUNET_NO; /* already exists */ 1101 return GNUNET_NO; /* already exists */
1112 if (GNUNET_OK != 1102 if (GNUNET_OK !=
1113 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old)) 1103 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
@@ -1140,8 +1130,7 @@ GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
1140 */ 1130 */
1141int 1131int
1142GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle 1132GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle
1143 *cfg, 1133 *cfg, const char *section,
1144 const char *section,
1145 const char *option, 1134 const char *option,
1146 const char *value) 1135 const char *value)
1147{ 1136{
@@ -1231,11 +1220,10 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
1231 if (ipath == NULL) 1220 if (ipath == NULL)
1232 return GNUNET_SYSERR; 1221 return GNUNET_SYSERR;
1233 baseconfig = NULL; 1222 baseconfig = NULL;
1234 GNUNET_asprintf (&baseconfig, 1223 GNUNET_asprintf (&baseconfig, "%s%s%s", ipath, DIR_SEPARATOR_STR,
1235 "%s%s%s", ipath, DIR_SEPARATOR_STR, "defaults.conf"); 1224 "defaults.conf");
1236 GNUNET_free (ipath); 1225 GNUNET_free (ipath);
1237 if ((GNUNET_OK != 1226 if ((GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, baseconfig)) ||
1238 GNUNET_CONFIGURATION_parse (cfg, baseconfig)) ||
1239 (!((filename == NULL) || 1227 (!((filename == NULL) ||
1240 (GNUNET_OK == GNUNET_CONFIGURATION_parse (cfg, filename))))) 1228 (GNUNET_OK == GNUNET_CONFIGURATION_parse (cfg, filename)))))
1241 { 1229 {
@@ -1243,18 +1231,15 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
1243 return (filename == NULL) ? GNUNET_OK : GNUNET_SYSERR; 1231 return (filename == NULL) ? GNUNET_OK : GNUNET_SYSERR;
1244 } 1232 }
1245 GNUNET_free (baseconfig); 1233 GNUNET_free (baseconfig);
1246 if (((GNUNET_YES != GNUNET_CONFIGURATION_have_value (cfg, 1234 if (((GNUNET_YES !=
1247 "PATHS", 1235 GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) &&
1248 "DEFAULTCONFIG"))) &&
1249 (filename != NULL)) 1236 (filename != NULL))
1250 GNUNET_CONFIGURATION_set_value_string (cfg, 1237 GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG",
1251 "PATHS", "DEFAULTCONFIG", filename); 1238 filename);
1252 if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, 1239 if ((GNUNET_YES ==
1253 "TESTING", 1240 GNUNET_CONFIGURATION_have_value (cfg, "TESTING", "WEAKRANDOM")) &&
1254 "WEAKRANDOM")) && 1241 (GNUNET_YES ==
1255 (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, 1242 GNUNET_CONFIGURATION_get_value_yesno (cfg, "TESTING", "WEAKRANDOM")))
1256 "TESTING",
1257 "WEAKRANDOM")))
1258 GNUNET_CRYPTO_random_disable_entropy_gathering (); 1243 GNUNET_CRYPTO_random_disable_entropy_gathering ();
1259 return GNUNET_OK; 1244 return GNUNET_OK;
1260} 1245}