diff options
author | Tobias Brunner <tobias@strongswan.org> | 2014-04-29 16:04:43 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2014-05-15 11:28:09 +0200 |
commit | 8b43c9ba349d7370eb82e8340f48a7045d9c5c5e (patch) | |
tree | eea176620dc0eca21843024830ee897f5c7bcc51 /src/libstrongswan/settings | |
parent | 5ac20cbb8713cea802aa2764704201ae84a0d2d8 (diff) | |
download | strongswan-8b43c9ba349d7370eb82e8340f48a7045d9c5c5e.tar.bz2 strongswan-8b43c9ba349d7370eb82e8340f48a7045d9c5c5e.tar.xz |
settings: Adopt the new order of sections and settings when replacing configs
Diffstat (limited to 'src/libstrongswan/settings')
-rw-r--r-- | src/libstrongswan/settings/settings_types.c | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/src/libstrongswan/settings/settings_types.c b/src/libstrongswan/settings/settings_types.c index 253d06808..125676237 100644 --- a/src/libstrongswan/settings/settings_types.c +++ b/src/libstrongswan/settings/settings_types.c @@ -199,10 +199,13 @@ void settings_section_extend(section_t *base, section_t *extension, enumerator_t *enumerator; section_t *section; kv_t *kv; + array_t *sections = NULL, *kvs = NULL; int idx; if (purge) - { /* remove sections and settings in base not found in extension */ + { /* remove sections and settings in base not found in extension, the + * others are removed too (from the _order list) so they can be inserted + * in the order found in extension */ enumerator = array_create_enumerator(base->sections_order); while (enumerator->enumerate(enumerator, (void**)§ion)) { @@ -212,32 +215,49 @@ void settings_section_extend(section_t *base, section_t *extension, idx = array_bsearch(base->sections, section->name, settings_section_find, NULL); if (section_purge(section, contents)) - { + { /* only remove them if we can purge them */ array_remove(base->sections, idx, NULL); array_remove_at(base->sections_order, enumerator); settings_section_destroy(section, contents); } } + else + { + array_remove_at(base->sections_order, enumerator); + array_insert_create(§ions, ARRAY_TAIL, section); + array_sort(sections, settings_section_sort, NULL); + } } enumerator->destroy(enumerator); - enumerator = array_create_enumerator(base->kv_order); - while (enumerator->enumerate(enumerator, (void**)&kv)) + while (array_remove(base->kv_order, 0, &kv)) { if (array_bsearch(extension->kv, kv->key, settings_kv_find, NULL) == -1) { idx = array_bsearch(base->kv, kv->key, settings_kv_find, NULL); array_remove(base->kv, idx, NULL); - array_remove_at(base->kv_order, enumerator); settings_kv_destroy(kv, contents); } + else + { + array_insert_create(&kvs, ARRAY_TAIL, kv); + array_sort(kvs, settings_kv_sort, NULL); + } } - enumerator->destroy(enumerator); } while (array_remove(extension->sections_order, 0, §ion)) { + idx = array_bsearch(sections, section->name, + settings_section_find, NULL); + if (idx != -1) + { + section_t *existing; + + array_remove(sections, idx, &existing); + array_insert(base->sections_order, ARRAY_TAIL, existing); + } idx = array_bsearch(extension->sections, section->name, settings_section_find, NULL); array_remove(extension->sections, idx, NULL); @@ -246,10 +266,20 @@ void settings_section_extend(section_t *base, section_t *extension, while (array_remove(extension->kv_order, 0, &kv)) { + idx = array_bsearch(kvs, kv->key, settings_kv_find, NULL); + if (idx != -1) + { + kv_t *existing; + + array_remove(kvs, idx, &existing); + array_insert(base->kv_order, ARRAY_TAIL, existing); + } idx = array_bsearch(extension->kv, kv->key, settings_kv_find, NULL); array_remove(extension->kv, idx, NULL); settings_kv_add(base, kv, contents); } + array_destroy(sections); + array_destroy(kvs); } /* |