diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-01-02 13:47:16 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-01-02 13:47:16 +0100 |
commit | eab08cec9f81ba5652cae3862aca5472840c957a (patch) | |
tree | 45b5845f7d7737dc28273a376e5c23123586766b /src | |
parent | 0d4337da23548f4779d44c1416f51f087261141e (diff) | |
download | gnunet-eab08cec9f81ba5652cae3862aca5472840c957a.tar.gz gnunet-eab08cec9f81ba5652cae3862aca5472840c957a.zip |
do not output synthetic paths
Diffstat (limited to 'src')
-rw-r--r-- | src/util/configuration.c | 69 |
1 files changed, 59 insertions, 10 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c index 23e6ced98..bda643b83 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c | |||
@@ -443,12 +443,45 @@ GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
443 | } | 443 | } |
444 | 444 | ||
445 | 445 | ||
446 | /** | ||
447 | * Should we skip this configuration entry when serializing? | ||
448 | * | ||
449 | * @param sec section name | ||
450 | * @param key key | ||
451 | * @return true if we should skip it | ||
452 | */ | ||
453 | static bool | ||
454 | do_skip (const char *sec, | ||
455 | const char *key) | ||
456 | { | ||
457 | if (0 != strcasecmp ("PATHS", | ||
458 | sec)) | ||
459 | return false; | ||
460 | return ( (0 == strcasecmp ("DATADIR", | ||
461 | key)) || | ||
462 | (0 == strcasecmp ("LIBDIR", | ||
463 | key)) || | ||
464 | (0 == strcasecmp ("BINDIR", | ||
465 | key)) || | ||
466 | (0 == strcasecmp ("PREFIX", | ||
467 | key)) || | ||
468 | (0 == strcasecmp ("LOCALEDIR", | ||
469 | key)) || | ||
470 | (0 == strcasecmp ("ICONDIR", | ||
471 | key)) || | ||
472 | (0 == strcasecmp ("DOCDIR", | ||
473 | key)) || | ||
474 | (0 == strcasecmp ("DEFAULTCONFIG", | ||
475 | key)) || | ||
476 | (0 == strcasecmp ("LIBEXECDIR", | ||
477 | key)) ); | ||
478 | } | ||
479 | |||
480 | |||
446 | char * | 481 | char * |
447 | GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, | 482 | GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, |
448 | size_t *size) | 483 | size_t *size) |
449 | { | 484 | { |
450 | struct ConfigSection *sec; | ||
451 | struct ConfigEntry *ent; | ||
452 | char *mem; | 485 | char *mem; |
453 | char *cbuf; | 486 | char *cbuf; |
454 | char *val; | 487 | char *val; |
@@ -458,12 +491,19 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
458 | 491 | ||
459 | /* Pass1 : calculate the buffer size required */ | 492 | /* Pass1 : calculate the buffer size required */ |
460 | m_size = 0; | 493 | m_size = 0; |
461 | for (sec = cfg->sections; NULL != sec; sec = sec->next) | 494 | for (struct ConfigSection *sec = cfg->sections; |
495 | NULL != sec; | ||
496 | sec = sec->next) | ||
462 | { | 497 | { |
463 | /* For each section we need to add 3 characters: {'[',']','\n'} */ | 498 | /* For each section we need to add 3 characters: {'[',']','\n'} */ |
464 | m_size += strlen (sec->name) + 3; | 499 | m_size += strlen (sec->name) + 3; |
465 | for (ent = sec->entries; NULL != ent; ent = ent->next) | 500 | for (struct ConfigEntry *ent = sec->entries; |
501 | NULL != ent; | ||
502 | ent = ent->next) | ||
466 | { | 503 | { |
504 | if (do_skip (sec->name, | ||
505 | ent->key)) | ||
506 | continue; | ||
467 | if (NULL != ent->val) | 507 | if (NULL != ent->val) |
468 | { | 508 | { |
469 | /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */ | 509 | /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */ |
@@ -484,20 +524,30 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
484 | 524 | ||
485 | /* Pass2: Allocate memory and write the configuration to it */ | 525 | /* Pass2: Allocate memory and write the configuration to it */ |
486 | mem = GNUNET_malloc (m_size); | 526 | mem = GNUNET_malloc (m_size); |
487 | sec = cfg->sections; | ||
488 | c_size = 0; | 527 | c_size = 0; |
489 | *size = c_size; | 528 | *size = c_size; |
490 | while (NULL != sec) | 529 | for (struct ConfigSection *sec = cfg->sections; |
530 | NULL != sec; | ||
531 | sec = sec->next) | ||
491 | { | 532 | { |
492 | int len; | 533 | int len; |
493 | 534 | ||
494 | len = GNUNET_asprintf (&cbuf, "[%s]\n", sec->name); | 535 | len = GNUNET_asprintf (&cbuf, |
536 | "[%s]\n", | ||
537 | sec->name); | ||
495 | GNUNET_assert (0 < len); | 538 | GNUNET_assert (0 < len); |
496 | GNUNET_memcpy (mem + c_size, cbuf, len); | 539 | GNUNET_memcpy (mem + c_size, |
540 | cbuf, | ||
541 | len); | ||
497 | c_size += len; | 542 | c_size += len; |
498 | GNUNET_free (cbuf); | 543 | GNUNET_free (cbuf); |
499 | for (ent = sec->entries; NULL != ent; ent = ent->next) | 544 | for (struct ConfigEntry *ent = sec->entries; |
545 | NULL != ent; | ||
546 | ent = ent->next) | ||
500 | { | 547 | { |
548 | if (do_skip (sec->name, | ||
549 | ent->key)) | ||
550 | continue; | ||
501 | if (NULL != ent->val) | 551 | if (NULL != ent->val) |
502 | { | 552 | { |
503 | val = GNUNET_malloc (strlen (ent->val) * 2 + 1); | 553 | val = GNUNET_malloc (strlen (ent->val) * 2 + 1); |
@@ -517,7 +567,6 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
517 | } | 567 | } |
518 | GNUNET_memcpy (mem + c_size, "\n", 1); | 568 | GNUNET_memcpy (mem + c_size, "\n", 1); |
519 | c_size++; | 569 | c_size++; |
520 | sec = sec->next; | ||
521 | } | 570 | } |
522 | GNUNET_assert (c_size == m_size); | 571 | GNUNET_assert (c_size == m_size); |
523 | *size = c_size; | 572 | *size = c_size; |