aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_configuration_lib.h10
-rw-r--r--src/util/configuration.c65
2 files changed, 60 insertions, 15 deletions
diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h
index 87aa8eacc..3cdd54c8f 100644
--- a/src/include/gnunet_configuration_lib.h
+++ b/src/include/gnunet_configuration_lib.h
@@ -174,6 +174,16 @@ void GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Ha
174 GNUNET_CONFIGURATION_Section_Iterator iter, 174 GNUNET_CONFIGURATION_Section_Iterator iter,
175 void *iter_cls); 175 void *iter_cls);
176 176
177
178/**
179 * Remove the given section and all options in it.
180 *
181 * @param cfg configuration to inspect
182 * @param section name of the section to remove
183 */
184void GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
185 const char *section);
186
177/** 187/**
178 * Get a configuration value that should be a number. 188 * Get a configuration value that should be a number.
179 * 189 *
diff --git a/src/util/configuration.c b/src/util/configuration.c
index 10f2d7575..4aa5fed5a 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -132,21 +132,9 @@ void
132GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg) 132GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
133{ 133{
134 struct ConfigSection *sec; 134 struct ConfigSection *sec;
135 struct ConfigEntry *ent;
136 135
137 while (NULL != (sec = cfg->sections)) 136 while (NULL != (sec = cfg->sections))
138 { 137 GNUNET_CONFIGURATION_remove_section (cfg, sec->name);
139 cfg->sections = sec->next;
140 while (NULL != (ent = sec->entries))
141 {
142 sec->entries = ent->next;
143 GNUNET_free (ent->key);
144 GNUNET_free_non_null (ent->val);
145 GNUNET_free (ent);
146 }
147 GNUNET_free (sec->name);
148 GNUNET_free (sec);
149 }
150 GNUNET_free (cfg); 138 GNUNET_free (cfg);
151} 139}
152 140
@@ -414,9 +402,56 @@ GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle
414 void *iter_cls) 402 void *iter_cls)
415{ 403{
416 struct ConfigSection *spos; 404 struct ConfigSection *spos;
405 struct ConfigSection *next;
417 406
418 for (spos = cfg->sections; spos != NULL; spos = spos->next) 407 next = cfg->sections;
419 iter (iter_cls, spos->name); 408 while (next != NULL)
409 {
410 spos = next;
411 next = spos->next;
412 iter (iter_cls, spos->name);
413 }
414}
415
416/**
417 * Remove the given section and all options in it.
418 *
419 * @param cfg configuration to inspect
420 * @param section name of the section to remove
421 */
422void GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
423 const char *section)
424{
425 struct ConfigSection *spos;
426 struct ConfigSection *prev;
427 struct ConfigEntry *ent;
428
429 prev = NULL;
430 spos = cfg->sections;
431 while (spos != NULL)
432 {
433 if (0 == strcmp (section,
434 spos->name))
435 {
436 if (prev == NULL)
437 cfg->sections = spos->next;
438 else
439 prev->next = spos->next;
440 while (NULL != (ent = spos->entries))
441 {
442 spos->entries = ent->next;
443 GNUNET_free (ent->key);
444 GNUNET_free_non_null (ent->val);
445 GNUNET_free (ent);
446 cfg->dirty = GNUNET_YES;
447 }
448 GNUNET_free (spos->name);
449 GNUNET_free (spos);
450 return;
451 }
452 prev = spos;
453 spos = spos->next;
454 }
420} 455}
421 456
422 457