X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Fconfiguration.c;h=978765970c80fbb69857b7da4cc21fc0849f805c;hb=46ac0cea02fe1949d76b86c7a0750f9e7854fef6;hp=10f2d757557384b8bd6a8d48db37103969d95131;hpb=e01209d5d6b3873646727662ab8dfee0189d42a6;p=oweals%2Fgnunet.git diff --git a/src/util/configuration.c b/src/util/configuration.c index 10f2d7575..978765970 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c @@ -132,21 +132,9 @@ void GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg) { struct ConfigSection *sec; - struct ConfigEntry *ent; while (NULL != (sec = cfg->sections)) - { - cfg->sections = sec->next; - while (NULL != (ent = sec->entries)) - { - sec->entries = ent->next; - GNUNET_free (ent->key); - GNUNET_free_non_null (ent->val); - GNUNET_free (ent); - } - GNUNET_free (sec->name); - GNUNET_free (sec); - } + GNUNET_CONFIGURATION_remove_section (cfg, sec->name); GNUNET_free (cfg); } @@ -414,9 +402,56 @@ GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle void *iter_cls) { struct ConfigSection *spos; + struct ConfigSection *next; - for (spos = cfg->sections; spos != NULL; spos = spos->next) - iter (iter_cls, spos->name); + next = cfg->sections; + while (next != NULL) + { + spos = next; + next = spos->next; + iter (iter_cls, spos->name); + } +} + +/** + * Remove the given section and all options in it. + * + * @param cfg configuration to inspect + * @param section name of the section to remove + */ +void GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section) +{ + struct ConfigSection *spos; + struct ConfigSection *prev; + struct ConfigEntry *ent; + + prev = NULL; + spos = cfg->sections; + while (spos != NULL) + { + if (0 == strcmp (section, + spos->name)) + { + if (prev == NULL) + cfg->sections = spos->next; + else + prev->next = spos->next; + while (NULL != (ent = spos->entries)) + { + spos->entries = ent->next; + GNUNET_free (ent->key); + GNUNET_free_non_null (ent->val); + GNUNET_free (ent); + cfg->dirty = GNUNET_YES; + } + GNUNET_free (spos->name); + GNUNET_free (spos); + return; + } + prev = spos; + spos = spos->next; + } } @@ -655,13 +690,22 @@ GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle const char *option, struct GNUNET_TIME_Relative *time) { + struct ConfigEntry *e; unsigned long long num; - int ret; - ret = GNUNET_CONFIGURATION_get_value_number (cfg, section, option, &num); - if (ret == GNUNET_OK) - time->rel_value = (uint64_t) num; - return ret; + e = findEntry (cfg, section, option); + if (e == NULL) + return GNUNET_SYSERR; + if ( (0 == strcasecmp (e->val, "infinity")) || + (0 == strcasecmp (e->val, "forever")) ) + { + *time = GNUNET_TIME_UNIT_FOREVER_REL; + return GNUNET_OK; + } + if (1 != SSCANF (e->val, "%llu", &num)) + return GNUNET_SYSERR; + time->rel_value = (uint64_t) num; + return GNUNET_OK; }