diff options
Diffstat (limited to 'src/util/configuration.c')
-rw-r--r-- | src/util/configuration.c | 125 |
1 files changed, 86 insertions, 39 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c index b7ca377a9..45aec7981 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c | |||
@@ -23,6 +23,7 @@ | |||
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include "gnunet_common.h" | ||
26 | #include "platform.h" | 27 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_configuration_lib.h" | 29 | #include "gnunet_configuration_lib.h" |
@@ -374,7 +375,7 @@ struct CollectFilesContext | |||
374 | * #GNUNET_NO to stop iteration with no error, | 375 | * #GNUNET_NO to stop iteration with no error, |
375 | * #GNUNET_SYSERR to abort iteration with error! | 376 | * #GNUNET_SYSERR to abort iteration with error! |
376 | */ | 377 | */ |
377 | static int | 378 | static enum GNUNET_GenericReturnValue |
378 | collect_files_cb (void *cls, | 379 | collect_files_cb (void *cls, |
379 | const char *filename) | 380 | const char *filename) |
380 | { | 381 | { |
@@ -782,8 +783,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
782 | if (NULL != cfg->restrict_section) | 783 | if (NULL != cfg->restrict_section) |
783 | { | 784 | { |
784 | LOG (GNUNET_ERROR_TYPE_WARNING, | 785 | LOG (GNUNET_ERROR_TYPE_WARNING, |
785 | _ ( | 786 | "Illegal directive in line %u (parsing restricted section %s)\n", |
786 | "Illegal directive in line %u (parsing restricted section %s)\n"), | ||
787 | nr, | 787 | nr, |
788 | cfg->restrict_section); | 788 | cfg->restrict_section); |
789 | ret = GNUNET_SYSERR; | 789 | ret = GNUNET_SYSERR; |
@@ -793,7 +793,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
793 | if (NULL == end) | 793 | if (NULL == end) |
794 | { | 794 | { |
795 | LOG (GNUNET_ERROR_TYPE_WARNING, | 795 | LOG (GNUNET_ERROR_TYPE_WARNING, |
796 | _ ("Bad directive in line %u\n"), | 796 | "Bad directive in line %u\n", |
797 | nr); | 797 | nr); |
798 | ret = GNUNET_SYSERR; | 798 | ret = GNUNET_SYSERR; |
799 | break; | 799 | break; |
@@ -849,7 +849,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
849 | if (NULL == secname_end) | 849 | if (NULL == secname_end) |
850 | { | 850 | { |
851 | LOG (GNUNET_ERROR_TYPE_WARNING, | 851 | LOG (GNUNET_ERROR_TYPE_WARNING, |
852 | _ ("Bad inline-secret directive in line %u\n"), | 852 | "Bad inline-secret directive in line %u\n", |
853 | nr); | 853 | nr); |
854 | ret = GNUNET_SYSERR; | 854 | ret = GNUNET_SYSERR; |
855 | break; | 855 | break; |
@@ -871,7 +871,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
871 | else | 871 | else |
872 | { | 872 | { |
873 | LOG (GNUNET_ERROR_TYPE_WARNING, | 873 | LOG (GNUNET_ERROR_TYPE_WARNING, |
874 | _ ("Unknown or malformed directive '%s' in line %u\n"), | 874 | "Unknown or malformed directive '%s' in line %u\n", |
875 | directive, | 875 | directive, |
876 | nr); | 876 | nr); |
877 | ret = GNUNET_SYSERR; | 877 | ret = GNUNET_SYSERR; |
@@ -901,8 +901,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
901 | if (NULL == section) | 901 | if (NULL == section) |
902 | { | 902 | { |
903 | LOG (GNUNET_ERROR_TYPE_WARNING, | 903 | LOG (GNUNET_ERROR_TYPE_WARNING, |
904 | _ ( | 904 | "Syntax error while deserializing in line %u (option without section)\n", |
905 | "Syntax error while deserializing in line %u (option without section)\n"), | ||
906 | nr); | 905 | nr); |
907 | ret = GNUNET_SYSERR; | 906 | ret = GNUNET_SYSERR; |
908 | break; | 907 | break; |
@@ -952,7 +951,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
952 | } | 951 | } |
953 | /* parse error */ | 952 | /* parse error */ |
954 | LOG (GNUNET_ERROR_TYPE_WARNING, | 953 | LOG (GNUNET_ERROR_TYPE_WARNING, |
955 | _ ("Syntax error while deserializing in line %u\n"), | 954 | "Syntax error while deserializing in line %u\n", |
956 | nr); | 955 | nr); |
957 | ret = GNUNET_SYSERR; | 956 | ret = GNUNET_SYSERR; |
958 | break; | 957 | break; |
@@ -1033,7 +1032,10 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1033 | 1032 | ||
1034 | dirty = cfg->dirty; /* back up value! */ | 1033 | dirty = cfg->dirty; /* back up value! */ |
1035 | if (GNUNET_SYSERR == | 1034 | if (GNUNET_SYSERR == |
1036 | GNUNET_DISK_file_size (fn, &fs64, GNUNET_YES, GNUNET_YES)) | 1035 | GNUNET_DISK_file_size (fn, |
1036 | &fs64, | ||
1037 | GNUNET_YES, | ||
1038 | GNUNET_YES)) | ||
1037 | { | 1039 | { |
1038 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1040 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1039 | "Error while determining the file size of `%s'\n", | 1041 | "Error while determining the file size of `%s'\n", |
@@ -1052,12 +1054,16 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1052 | sret = GNUNET_DISK_fn_read (fn, mem, fs); | 1054 | sret = GNUNET_DISK_fn_read (fn, mem, fs); |
1053 | if ((sret < 0) || (fs != (size_t) sret)) | 1055 | if ((sret < 0) || (fs != (size_t) sret)) |
1054 | { | 1056 | { |
1055 | LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Error while reading file `%s'\n"), fn); | 1057 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1058 | "Error while reading file `%s'\n", | ||
1059 | fn); | ||
1056 | GNUNET_free (fn); | 1060 | GNUNET_free (fn); |
1057 | GNUNET_free (mem); | 1061 | GNUNET_free (mem); |
1058 | return GNUNET_SYSERR; | 1062 | return GNUNET_SYSERR; |
1059 | } | 1063 | } |
1060 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Deserializing contents of file `%s'\n", fn); | 1064 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1065 | "Deserializing contents of file `%s'\n", | ||
1066 | fn); | ||
1061 | ret = GNUNET_CONFIGURATION_deserialize (cfg, | 1067 | ret = GNUNET_CONFIGURATION_deserialize (cfg, |
1062 | mem, | 1068 | mem, |
1063 | fs, | 1069 | fs, |
@@ -1512,7 +1518,10 @@ copy_entry (void *cls, | |||
1512 | { | 1518 | { |
1513 | struct GNUNET_CONFIGURATION_Handle *dst = cls; | 1519 | struct GNUNET_CONFIGURATION_Handle *dst = cls; |
1514 | 1520 | ||
1515 | GNUNET_CONFIGURATION_set_value_string (dst, section, option, value); | 1521 | GNUNET_CONFIGURATION_set_value_string (dst, |
1522 | section, | ||
1523 | option, | ||
1524 | value); | ||
1516 | } | 1525 | } |
1517 | 1526 | ||
1518 | 1527 | ||
@@ -1550,7 +1559,10 @@ compare_entries (void *cls, | |||
1550 | if ((NULL != entNew) && (NULL != entNew->val) && | 1559 | if ((NULL != entNew) && (NULL != entNew->val) && |
1551 | (0 == strcmp (entNew->val, value))) | 1560 | (0 == strcmp (entNew->val, value))) |
1552 | return; | 1561 | return; |
1553 | GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff, section, option, value); | 1562 | GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff, |
1563 | section, | ||
1564 | option, | ||
1565 | value); | ||
1554 | } | 1566 | } |
1555 | 1567 | ||
1556 | 1568 | ||
@@ -1634,8 +1646,14 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1634 | { | 1646 | { |
1635 | char s[64]; | 1647 | char s[64]; |
1636 | 1648 | ||
1637 | GNUNET_snprintf (s, 64, "%llu", number); | 1649 | GNUNET_snprintf (s, |
1638 | GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s); | 1650 | 64, |
1651 | "%llu", | ||
1652 | number); | ||
1653 | GNUNET_CONFIGURATION_set_value_string (cfg, | ||
1654 | section, | ||
1655 | option, | ||
1656 | s); | ||
1639 | } | 1657 | } |
1640 | 1658 | ||
1641 | 1659 | ||
@@ -1862,15 +1880,17 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1862 | if (depth > 128) | 1880 | if (depth > 128) |
1863 | { | 1881 | { |
1864 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1882 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1865 | _ ( | 1883 | "Recursive expansion suspected, aborting $-expansion for term `%s'\n", |
1866 | "Recursive expansion suspected, aborting $-expansion for term `%s'\n"), | ||
1867 | orig); | 1884 | orig); |
1868 | return orig; | 1885 | return orig; |
1869 | } | 1886 | } |
1870 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to $-expand %s\n", orig); | 1887 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1888 | "Asked to $-expand %s\n", | ||
1889 | orig); | ||
1871 | if ('$' != orig[0]) | 1890 | if ('$' != orig[0]) |
1872 | { | 1891 | { |
1873 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Doesn't start with $ - not expanding\n"); | 1892 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1893 | "Doesn't start with $ - not expanding\n"); | ||
1874 | return orig; | 1894 | return orig; |
1875 | } | 1895 | } |
1876 | erased_char = 0; | 1896 | erased_char = 0; |
@@ -1895,8 +1915,7 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1895 | 1915 | ||
1896 | case '\0': | 1916 | case '\0': |
1897 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1917 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1898 | _ ("Missing closing `%s' in option `%s'\n"), | 1918 | "Missing closing `}' in option `%s'\n", |
1899 | "}", | ||
1900 | orig); | 1919 | orig); |
1901 | return orig; | 1920 | return orig; |
1902 | 1921 | ||
@@ -1925,8 +1944,10 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1925 | start = &orig[1]; | 1944 | start = &orig[1]; |
1926 | def = NULL; | 1945 | def = NULL; |
1927 | i = 0; | 1946 | i = 0; |
1928 | while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0') && | 1947 | while ( (orig[i] != '/') && |
1929 | (orig[i] != ' ')) | 1948 | (orig[i] != '\\') && |
1949 | (orig[i] != '\0') && | ||
1950 | (orig[i] != ' ') ) | ||
1930 | i++; | 1951 | i++; |
1931 | if (orig[i] == '\0') | 1952 | if (orig[i] == '\0') |
1932 | { | 1953 | { |
@@ -1946,12 +1967,17 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1946 | post, | 1967 | post, |
1947 | def); | 1968 | def); |
1948 | if (GNUNET_OK != | 1969 | if (GNUNET_OK != |
1949 | GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", start, &prefix)) | 1970 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1971 | "PATHS", | ||
1972 | start, | ||
1973 | &prefix)) | ||
1950 | { | 1974 | { |
1951 | if (NULL == (env = getenv (start))) | 1975 | if (NULL == (env = getenv (start))) |
1952 | { | 1976 | { |
1953 | /* try default */ | 1977 | /* try default */ |
1954 | def = expand_dollar (cfg, def, depth + 1); | 1978 | def = expand_dollar (cfg, |
1979 | def, | ||
1980 | depth + 1); | ||
1955 | env = def; | 1981 | env = def; |
1956 | } | 1982 | } |
1957 | if (NULL == env) | 1983 | if (NULL == env) |
@@ -1960,8 +1986,7 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1960 | if (erased_pos) | 1986 | if (erased_pos) |
1961 | *erased_pos = erased_char; | 1987 | *erased_pos = erased_char; |
1962 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1988 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1963 | _ ( | 1989 | "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n", |
1964 | "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n"), | ||
1965 | start, | 1990 | start, |
1966 | orig); | 1991 | orig); |
1967 | GNUNET_free (start); | 1992 | GNUNET_free (start); |
@@ -1969,7 +1994,8 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1969 | } | 1994 | } |
1970 | prefix = GNUNET_strdup (env); | 1995 | prefix = GNUNET_strdup (env); |
1971 | } | 1996 | } |
1972 | prefix = GNUNET_CONFIGURATION_expand_dollar (cfg, prefix); | 1997 | prefix = GNUNET_CONFIGURATION_expand_dollar (cfg, |
1998 | prefix); | ||
1973 | if ((erased_pos) && ('}' != erased_char)) | 1999 | if ((erased_pos) && ('}' != erased_char)) |
1974 | { | 2000 | { |
1975 | len = strlen (prefix) + 1; | 2001 | len = strlen (prefix) + 1; |
@@ -2206,7 +2232,10 @@ GNUNET_CONFIGURATION_append_value_filename ( | |||
2206 | if (strlen (old) > 0) | 2232 | if (strlen (old) > 0) |
2207 | strcat (nw, " "); | 2233 | strcat (nw, " "); |
2208 | strcat (nw, escaped); | 2234 | strcat (nw, escaped); |
2209 | GNUNET_CONFIGURATION_set_value_string (cfg, section, option, nw); | 2235 | GNUNET_CONFIGURATION_set_value_string (cfg, |
2236 | section, | ||
2237 | option, | ||
2238 | nw); | ||
2210 | GNUNET_free (old); | 2239 | GNUNET_free (old); |
2211 | GNUNET_free (nw); | 2240 | GNUNET_free (nw); |
2212 | GNUNET_free (escaped); | 2241 | GNUNET_free (escaped); |
@@ -2228,7 +2257,10 @@ GNUNET_CONFIGURATION_remove_value_filename ( | |||
2228 | char old; | 2257 | char old; |
2229 | 2258 | ||
2230 | if (GNUNET_OK != | 2259 | if (GNUNET_OK != |
2231 | GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list)) | 2260 | GNUNET_CONFIGURATION_get_value_string (cfg, |
2261 | section, | ||
2262 | option, | ||
2263 | &list)) | ||
2232 | return GNUNET_NO; | 2264 | return GNUNET_NO; |
2233 | match = escape_name (value); | 2265 | match = escape_name (value); |
2234 | pos = list; | 2266 | pos = list; |
@@ -2266,7 +2298,9 @@ GNUNET_CONFIGURATION_remove_value_filename ( | |||
2266 | if (0 == strcmp (pos, match)) | 2298 | if (0 == strcmp (pos, match)) |
2267 | { | 2299 | { |
2268 | if (old != '\0') | 2300 | if (old != '\0') |
2269 | memmove (pos, &end[1], strlen (&end[1]) + 1); | 2301 | memmove (pos, |
2302 | &end[1], | ||
2303 | strlen (&end[1]) + 1); | ||
2270 | else | 2304 | else |
2271 | { | 2305 | { |
2272 | if (pos != list) | 2306 | if (pos != list) |
@@ -2274,7 +2308,10 @@ GNUNET_CONFIGURATION_remove_value_filename ( | |||
2274 | else | 2308 | else |
2275 | pos[0] = '\0'; | 2309 | pos[0] = '\0'; |
2276 | } | 2310 | } |
2277 | GNUNET_CONFIGURATION_set_value_string (cfg, section, option, list); | 2311 | GNUNET_CONFIGURATION_set_value_string (cfg, |
2312 | section, | ||
2313 | option, | ||
2314 | list); | ||
2278 | GNUNET_free (list); | 2315 | GNUNET_free (list); |
2279 | GNUNET_free (match); | 2316 | GNUNET_free (match); |
2280 | return GNUNET_OK; | 2317 | return GNUNET_OK; |
@@ -2455,7 +2492,7 @@ GNUNET_CONFIGURATION_default (void) | |||
2455 | * @param filename name of the configuration file, NULL to load defaults | 2492 | * @param filename name of the configuration file, NULL to load defaults |
2456 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 2493 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
2457 | */ | 2494 | */ |
2458 | int | 2495 | enum GNUNET_GenericReturnValue |
2459 | GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | 2496 | GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, |
2460 | const char *filename) | 2497 | const char *filename) |
2461 | { | 2498 | { |
@@ -2499,8 +2536,12 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
2499 | char *dname = GNUNET_STRINGS_filename_expand (baseconfig); | 2536 | char *dname = GNUNET_STRINGS_filename_expand (baseconfig); |
2500 | GNUNET_free (baseconfig); | 2537 | GNUNET_free (baseconfig); |
2501 | 2538 | ||
2502 | if ((GNUNET_YES == GNUNET_DISK_directory_test (dname, GNUNET_YES)) && | 2539 | if ((GNUNET_YES == |
2503 | (GNUNET_SYSERR == GNUNET_CONFIGURATION_load_from (cfg, dname))) | 2540 | GNUNET_DISK_directory_test (dname, |
2541 | GNUNET_YES)) && | ||
2542 | (GNUNET_SYSERR == | ||
2543 | GNUNET_CONFIGURATION_load_from (cfg, | ||
2544 | dname))) | ||
2504 | { | 2545 | { |
2505 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2546 | LOG (GNUNET_ERROR_TYPE_WARNING, |
2506 | "Failed to load base configuration from '%s'\n", | 2547 | "Failed to load base configuration from '%s'\n", |
@@ -2510,7 +2551,9 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
2510 | } | 2551 | } |
2511 | GNUNET_free (dname); | 2552 | GNUNET_free (dname); |
2512 | if ((NULL != filename) && | 2553 | if ((NULL != filename) && |
2513 | (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, filename))) | 2554 | (GNUNET_OK != |
2555 | GNUNET_CONFIGURATION_parse (cfg, | ||
2556 | filename))) | ||
2514 | { | 2557 | { |
2515 | /* specified configuration not found */ | 2558 | /* specified configuration not found */ |
2516 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2559 | LOG (GNUNET_ERROR_TYPE_WARNING, |
@@ -2519,9 +2562,13 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
2519 | return GNUNET_SYSERR; | 2562 | return GNUNET_SYSERR; |
2520 | } | 2563 | } |
2521 | if (((GNUNET_YES != | 2564 | if (((GNUNET_YES != |
2522 | GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) && | 2565 | GNUNET_CONFIGURATION_have_value (cfg, |
2566 | "PATHS", | ||
2567 | "DEFAULTCONFIG"))) && | ||
2523 | (filename != NULL)) | 2568 | (filename != NULL)) |
2524 | GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", | 2569 | GNUNET_CONFIGURATION_set_value_string (cfg, |
2570 | "PATHS", | ||
2571 | "DEFAULTCONFIG", | ||
2525 | filename); | 2572 | filename); |
2526 | return GNUNET_OK; | 2573 | return GNUNET_OK; |
2527 | } | 2574 | } |