diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-07-17 20:13:36 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-07-17 20:13:36 +0200 |
commit | 70de6f2ad13366473f90ab5a405a5c231931e749 (patch) | |
tree | c3ea37a1375b80843f80e69001953948589e0f26 /src | |
parent | 33830e71f8e80334e0c8cf5527b1f2b20804485e (diff) | |
download | gnunet-70de6f2ad13366473f90ab5a405a5c231931e749.tar.gz gnunet-70de6f2ad13366473f90ab5a405a5c231931e749.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/util/configuration.c | 64 |
1 files changed, 48 insertions, 16 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c index 3294d11f4..d0090ae53 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2006, 2007, 2008, 2009, 2013, 2020 GNUnet e.V. | 3 | Copyright (C) 2006, 2007, 2008, 2009, 2013, 2020, 2021 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -260,13 +260,14 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
260 | pos = memchr (&mem[r_bytes], '\n', to_read); | 260 | pos = memchr (&mem[r_bytes], '\n', to_read); |
261 | if (NULL == pos) | 261 | if (NULL == pos) |
262 | { | 262 | { |
263 | line_orig = GNUNET_strndup (&mem[r_bytes], line_size = to_read); | 263 | line_orig = GNUNET_strndup (&mem[r_bytes], |
264 | line_size = to_read); | ||
264 | r_bytes += line_size; | 265 | r_bytes += line_size; |
265 | } | 266 | } |
266 | else | 267 | else |
267 | { | 268 | { |
268 | line_orig = | 269 | line_orig = GNUNET_strndup (&mem[r_bytes], |
269 | GNUNET_strndup (&mem[r_bytes], line_size = (pos - &mem[r_bytes])); | 270 | line_size = (pos - &mem[r_bytes])); |
270 | r_bytes += line_size + 1; | 271 | r_bytes += line_size + 1; |
271 | } | 272 | } |
272 | line = line_orig; | 273 | line = line_orig; |
@@ -288,7 +289,8 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
288 | continue; | 289 | continue; |
289 | 290 | ||
290 | /* remove tailing whitespace */ | 291 | /* remove tailing whitespace */ |
291 | for (i = line_size - 1; (i >= 1) && (isspace ((unsigned char) line[i])); | 292 | for (i = line_size - 1; |
293 | (i >= 1) && (isspace ((unsigned char) line[i])); | ||
292 | i--) | 294 | i--) |
293 | line[i] = '\0'; | 295 | line[i] = '\0'; |
294 | 296 | ||
@@ -297,26 +299,46 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
297 | ; | 299 | ; |
298 | 300 | ||
299 | /* ignore comments */ | 301 | /* ignore comments */ |
300 | if (('#' == line[0]) || ('%' == line[0])) | 302 | if ( ('#' == line[0]) || |
303 | ('%' == line[0]) ) | ||
301 | continue; | 304 | continue; |
302 | 305 | ||
303 | /* handle special "@INLINE@" directive */ | 306 | /* handle special "@INLINE@" directive */ |
304 | if (0 == strncasecmp (line, "@INLINE@ ", strlen ("@INLINE@ "))) | 307 | if (0 == strncasecmp (line, |
308 | "@INLINE@ ", | ||
309 | strlen ("@INLINE@ "))) | ||
305 | { | 310 | { |
306 | /* @INLINE@ value */ | 311 | /* @INLINE@ value */ |
307 | value = &line[strlen ("@INLINE@ ")]; | 312 | value = &line[strlen ("@INLINE@ ")]; |
308 | if (NULL != basedir) | 313 | if (NULL != basedir) |
309 | { | 314 | { |
310 | char *fn; | 315 | if ('/' == *value) |
311 | 316 | { | |
312 | GNUNET_asprintf (&fn, "%s/%s", basedir, value); | 317 | if (GNUNET_OK != |
313 | if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, fn)) | 318 | GNUNET_CONFIGURATION_parse (cfg, |
319 | value)) | ||
320 | { | ||
321 | ret = GNUNET_SYSERR; /* failed to parse included config */ | ||
322 | break; | ||
323 | } | ||
324 | } | ||
325 | else | ||
314 | { | 326 | { |
327 | char *fn; | ||
328 | |||
329 | GNUNET_asprintf (&fn, "%s/%s", | ||
330 | basedir, | ||
331 | value); | ||
332 | if (GNUNET_OK != | ||
333 | GNUNET_CONFIGURATION_parse (cfg, | ||
334 | fn)) | ||
335 | { | ||
336 | GNUNET_free (fn); | ||
337 | ret = GNUNET_SYSERR; /* failed to parse included config */ | ||
338 | break; | ||
339 | } | ||
315 | GNUNET_free (fn); | 340 | GNUNET_free (fn); |
316 | ret = GNUNET_SYSERR; /* failed to parse included config */ | ||
317 | break; | ||
318 | } | 341 | } |
319 | GNUNET_free (fn); | ||
320 | } | 342 | } |
321 | else | 343 | else |
322 | { | 344 | { |
@@ -374,7 +396,8 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
374 | } | 396 | } |
375 | GNUNET_free (line_orig); | 397 | GNUNET_free (line_orig); |
376 | GNUNET_free (section); | 398 | GNUNET_free (section); |
377 | GNUNET_assert ((GNUNET_OK != ret) || (r_bytes == size)); | 399 | GNUNET_assert ( (GNUNET_OK != ret) || |
400 | (r_bytes == size) ); | ||
378 | return ret; | 401 | return ret; |
379 | } | 402 | } |
380 | 403 | ||
@@ -426,7 +449,16 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
426 | endsep = strrchr (fn, (int) '/'); | 449 | endsep = strrchr (fn, (int) '/'); |
427 | if (NULL != endsep) | 450 | if (NULL != endsep) |
428 | *endsep = '\0'; | 451 | *endsep = '\0'; |
429 | ret = GNUNET_CONFIGURATION_deserialize (cfg, mem, fs, fn); | 452 | ret = GNUNET_CONFIGURATION_deserialize (cfg, |
453 | mem, | ||
454 | fs, | ||
455 | fn); | ||
456 | if (GNUNET_OK != ret) | ||
457 | { | ||
458 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
459 | _ ("Failed to parse configuration file `%s'\n"), | ||
460 | fn); | ||
461 | } | ||
430 | GNUNET_free (fn); | 462 | GNUNET_free (fn); |
431 | GNUNET_free (mem); | 463 | GNUNET_free (mem); |
432 | /* restore dirty flag - anything we set in the meantime | 464 | /* restore dirty flag - anything we set in the meantime |