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.c125
1 files changed, 86 insertions, 39 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c
index b7ca377a9..6b6a1ee15 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -374,7 +374,7 @@ struct CollectFilesContext
374 * #GNUNET_NO to stop iteration with no error, 374 * #GNUNET_NO to stop iteration with no error,
375 * #GNUNET_SYSERR to abort iteration with error! 375 * #GNUNET_SYSERR to abort iteration with error!
376 */ 376 */
377static int 377static enum GNUNET_GenericReturnValue
378collect_files_cb (void *cls, 378collect_files_cb (void *cls,
379 const char *filename) 379 const char *filename)
380{ 380{
@@ -782,8 +782,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
782 if (NULL != cfg->restrict_section) 782 if (NULL != cfg->restrict_section)
783 { 783 {
784 LOG (GNUNET_ERROR_TYPE_WARNING, 784 LOG (GNUNET_ERROR_TYPE_WARNING,
785 _ ( 785 "Illegal directive in line %u (parsing restricted section %s)\n",
786 "Illegal directive in line %u (parsing restricted section %s)\n"),
787 nr, 786 nr,
788 cfg->restrict_section); 787 cfg->restrict_section);
789 ret = GNUNET_SYSERR; 788 ret = GNUNET_SYSERR;
@@ -793,7 +792,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
793 if (NULL == end) 792 if (NULL == end)
794 { 793 {
795 LOG (GNUNET_ERROR_TYPE_WARNING, 794 LOG (GNUNET_ERROR_TYPE_WARNING,
796 _ ("Bad directive in line %u\n"), 795 "Bad directive in line %u\n",
797 nr); 796 nr);
798 ret = GNUNET_SYSERR; 797 ret = GNUNET_SYSERR;
799 break; 798 break;
@@ -849,7 +848,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
849 if (NULL == secname_end) 848 if (NULL == secname_end)
850 { 849 {
851 LOG (GNUNET_ERROR_TYPE_WARNING, 850 LOG (GNUNET_ERROR_TYPE_WARNING,
852 _ ("Bad inline-secret directive in line %u\n"), 851 "Bad inline-secret directive in line %u\n",
853 nr); 852 nr);
854 ret = GNUNET_SYSERR; 853 ret = GNUNET_SYSERR;
855 break; 854 break;
@@ -871,7 +870,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
871 else 870 else
872 { 871 {
873 LOG (GNUNET_ERROR_TYPE_WARNING, 872 LOG (GNUNET_ERROR_TYPE_WARNING,
874 _ ("Unknown or malformed directive '%s' in line %u\n"), 873 "Unknown or malformed directive '%s' in line %u\n",
875 directive, 874 directive,
876 nr); 875 nr);
877 ret = GNUNET_SYSERR; 876 ret = GNUNET_SYSERR;
@@ -901,8 +900,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
901 if (NULL == section) 900 if (NULL == section)
902 { 901 {
903 LOG (GNUNET_ERROR_TYPE_WARNING, 902 LOG (GNUNET_ERROR_TYPE_WARNING,
904 _ ( 903 "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); 904 nr);
907 ret = GNUNET_SYSERR; 905 ret = GNUNET_SYSERR;
908 break; 906 break;
@@ -952,7 +950,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
952 } 950 }
953 /* parse error */ 951 /* parse error */
954 LOG (GNUNET_ERROR_TYPE_WARNING, 952 LOG (GNUNET_ERROR_TYPE_WARNING,
955 _ ("Syntax error while deserializing in line %u\n"), 953 "Syntax error while deserializing in line %u\n",
956 nr); 954 nr);
957 ret = GNUNET_SYSERR; 955 ret = GNUNET_SYSERR;
958 break; 956 break;
@@ -1033,7 +1031,10 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
1033 1031
1034 dirty = cfg->dirty; /* back up value! */ 1032 dirty = cfg->dirty; /* back up value! */
1035 if (GNUNET_SYSERR == 1033 if (GNUNET_SYSERR ==
1036 GNUNET_DISK_file_size (fn, &fs64, GNUNET_YES, GNUNET_YES)) 1034 GNUNET_DISK_file_size (fn,
1035 &fs64,
1036 GNUNET_YES,
1037 GNUNET_YES))
1037 { 1038 {
1038 LOG (GNUNET_ERROR_TYPE_WARNING, 1039 LOG (GNUNET_ERROR_TYPE_WARNING,
1039 "Error while determining the file size of `%s'\n", 1040 "Error while determining the file size of `%s'\n",
@@ -1052,12 +1053,16 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
1052 sret = GNUNET_DISK_fn_read (fn, mem, fs); 1053 sret = GNUNET_DISK_fn_read (fn, mem, fs);
1053 if ((sret < 0) || (fs != (size_t) sret)) 1054 if ((sret < 0) || (fs != (size_t) sret))
1054 { 1055 {
1055 LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Error while reading file `%s'\n"), fn); 1056 LOG (GNUNET_ERROR_TYPE_WARNING,
1057 "Error while reading file `%s'\n",
1058 fn);
1056 GNUNET_free (fn); 1059 GNUNET_free (fn);
1057 GNUNET_free (mem); 1060 GNUNET_free (mem);
1058 return GNUNET_SYSERR; 1061 return GNUNET_SYSERR;
1059 } 1062 }
1060 LOG (GNUNET_ERROR_TYPE_DEBUG, "Deserializing contents of file `%s'\n", fn); 1063 LOG (GNUNET_ERROR_TYPE_DEBUG,
1064 "Deserializing contents of file `%s'\n",
1065 fn);
1061 ret = GNUNET_CONFIGURATION_deserialize (cfg, 1066 ret = GNUNET_CONFIGURATION_deserialize (cfg,
1062 mem, 1067 mem,
1063 fs, 1068 fs,
@@ -1512,7 +1517,10 @@ copy_entry (void *cls,
1512{ 1517{
1513 struct GNUNET_CONFIGURATION_Handle *dst = cls; 1518 struct GNUNET_CONFIGURATION_Handle *dst = cls;
1514 1519
1515 GNUNET_CONFIGURATION_set_value_string (dst, section, option, value); 1520 GNUNET_CONFIGURATION_set_value_string (dst,
1521 section,
1522 option,
1523 value);
1516} 1524}
1517 1525
1518 1526
@@ -1550,7 +1558,10 @@ compare_entries (void *cls,
1550 if ((NULL != entNew) && (NULL != entNew->val) && 1558 if ((NULL != entNew) && (NULL != entNew->val) &&
1551 (0 == strcmp (entNew->val, value))) 1559 (0 == strcmp (entNew->val, value)))
1552 return; 1560 return;
1553 GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff, section, option, value); 1561 GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff,
1562 section,
1563 option,
1564 value);
1554} 1565}
1555 1566
1556 1567
@@ -1634,8 +1645,14 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
1634{ 1645{
1635 char s[64]; 1646 char s[64];
1636 1647
1637 GNUNET_snprintf (s, 64, "%llu", number); 1648 GNUNET_snprintf (s,
1638 GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s); 1649 64,
1650 "%llu",
1651 number);
1652 GNUNET_CONFIGURATION_set_value_string (cfg,
1653 section,
1654 option,
1655 s);
1639} 1656}
1640 1657
1641 1658
@@ -1862,15 +1879,17 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
1862 if (depth > 128) 1879 if (depth > 128)
1863 { 1880 {
1864 LOG (GNUNET_ERROR_TYPE_WARNING, 1881 LOG (GNUNET_ERROR_TYPE_WARNING,
1865 _ ( 1882 "Recursive expansion suspected, aborting $-expansion for term `%s'\n",
1866 "Recursive expansion suspected, aborting $-expansion for term `%s'\n"),
1867 orig); 1883 orig);
1868 return orig; 1884 return orig;
1869 } 1885 }
1870 LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to $-expand %s\n", orig); 1886 LOG (GNUNET_ERROR_TYPE_DEBUG,
1887 "Asked to $-expand %s\n",
1888 orig);
1871 if ('$' != orig[0]) 1889 if ('$' != orig[0])
1872 { 1890 {
1873 LOG (GNUNET_ERROR_TYPE_DEBUG, "Doesn't start with $ - not expanding\n"); 1891 LOG (GNUNET_ERROR_TYPE_DEBUG,
1892 "Doesn't start with $ - not expanding\n");
1874 return orig; 1893 return orig;
1875 } 1894 }
1876 erased_char = 0; 1895 erased_char = 0;
@@ -1895,8 +1914,7 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
1895 1914
1896 case '\0': 1915 case '\0':
1897 LOG (GNUNET_ERROR_TYPE_WARNING, 1916 LOG (GNUNET_ERROR_TYPE_WARNING,
1898 _ ("Missing closing `%s' in option `%s'\n"), 1917 "Missing closing `}' in option `%s'\n",
1899 "}",
1900 orig); 1918 orig);
1901 return orig; 1919 return orig;
1902 1920
@@ -1925,8 +1943,10 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
1925 start = &orig[1]; 1943 start = &orig[1];
1926 def = NULL; 1944 def = NULL;
1927 i = 0; 1945 i = 0;
1928 while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0') && 1946 while ( (orig[i] != '/') &&
1929 (orig[i] != ' ')) 1947 (orig[i] != '\\') &&
1948 (orig[i] != '\0') &&
1949 (orig[i] != ' ') )
1930 i++; 1950 i++;
1931 if (orig[i] == '\0') 1951 if (orig[i] == '\0')
1932 { 1952 {
@@ -1946,12 +1966,17 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
1946 post, 1966 post,
1947 def); 1967 def);
1948 if (GNUNET_OK != 1968 if (GNUNET_OK !=
1949 GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", start, &prefix)) 1969 GNUNET_CONFIGURATION_get_value_string (cfg,
1970 "PATHS",
1971 start,
1972 &prefix))
1950 { 1973 {
1951 if (NULL == (env = getenv (start))) 1974 if (NULL == (env = getenv (start)))
1952 { 1975 {
1953 /* try default */ 1976 /* try default */
1954 def = expand_dollar (cfg, def, depth + 1); 1977 def = expand_dollar (cfg,
1978 def,
1979 depth + 1);
1955 env = def; 1980 env = def;
1956 } 1981 }
1957 if (NULL == env) 1982 if (NULL == env)
@@ -1960,8 +1985,7 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
1960 if (erased_pos) 1985 if (erased_pos)
1961 *erased_pos = erased_char; 1986 *erased_pos = erased_char;
1962 LOG (GNUNET_ERROR_TYPE_WARNING, 1987 LOG (GNUNET_ERROR_TYPE_WARNING,
1963 _ ( 1988 "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, 1989 start,
1966 orig); 1990 orig);
1967 GNUNET_free (start); 1991 GNUNET_free (start);
@@ -1969,7 +1993,8 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
1969 } 1993 }
1970 prefix = GNUNET_strdup (env); 1994 prefix = GNUNET_strdup (env);
1971 } 1995 }
1972 prefix = GNUNET_CONFIGURATION_expand_dollar (cfg, prefix); 1996 prefix = GNUNET_CONFIGURATION_expand_dollar (cfg,
1997 prefix);
1973 if ((erased_pos) && ('}' != erased_char)) 1998 if ((erased_pos) && ('}' != erased_char))
1974 { 1999 {
1975 len = strlen (prefix) + 1; 2000 len = strlen (prefix) + 1;
@@ -2206,7 +2231,10 @@ GNUNET_CONFIGURATION_append_value_filename (
2206 if (strlen (old) > 0) 2231 if (strlen (old) > 0)
2207 strcat (nw, " "); 2232 strcat (nw, " ");
2208 strcat (nw, escaped); 2233 strcat (nw, escaped);
2209 GNUNET_CONFIGURATION_set_value_string (cfg, section, option, nw); 2234 GNUNET_CONFIGURATION_set_value_string (cfg,
2235 section,
2236 option,
2237 nw);
2210 GNUNET_free (old); 2238 GNUNET_free (old);
2211 GNUNET_free (nw); 2239 GNUNET_free (nw);
2212 GNUNET_free (escaped); 2240 GNUNET_free (escaped);
@@ -2221,6 +2249,7 @@ GNUNET_CONFIGURATION_remove_value_filename (
2221 const char *option, 2249 const char *option,
2222 const char *value) 2250 const char *value)
2223{ 2251{
2252 enum GNUNET_GenericReturnValue ret;
2224 char *list; 2253 char *list;
2225 char *pos; 2254 char *pos;
2226 char *end; 2255 char *end;
@@ -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,10 +2308,13 @@ 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 ret = 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 ret;
2281 } 2318 }
2282 if (old == '\0') 2319 if (old == '\0')
2283 break; 2320 break;
@@ -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}