]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
config: Keep unique section names in setting keys.
authorTimo Sirainen <tss@iki.fi>
Tue, 9 Mar 2010 14:46:41 +0000 (16:46 +0200)
committerTimo Sirainen <tss@iki.fi>
Tue, 9 Mar 2010 14:46:41 +0000 (16:46 +0200)
--HG--
branch : HEAD

src/config/config-request.c

index 29f0c15b8a93e49ef3358d9c9fc4ca5a99d20715..1a0ff915e11bdbd1f7aa3f44b774efc9c920bbce 100644 (file)
@@ -161,6 +161,30 @@ bool config_export_type(string_t *str, const void *value,
        return TRUE;
 }
 
+static void
+setting_export_section_name(string_t *str, const struct setting_define *def,
+                           const void *set, unsigned int idx)
+{
+       const char *const *name;
+       size_t name_offset;
+
+       if (def->type != SET_DEFLIST_UNIQUE) {
+               /* not unique, use the index */
+               str_printfa(str, "%u", idx);
+               return;
+       }
+       name_offset = def->list_info->type_offset;
+       i_assert(name_offset != (size_t)-1);
+
+       name = CONST_PTR_OFFSET(set, name_offset);
+       if (*name == NULL || **name == '\0') {
+               /* no name, this one isn't unique. use the index. */
+               str_printfa(str, "%u", idx);
+       } else {
+               str_append(str, settings_section_escape(*name));
+       }
+}
+
 static void
 settings_export(struct config_export_context *ctx,
                const struct setting_parser_info *info,
@@ -235,7 +259,7 @@ settings_export(struct config_export_context *ctx,
                        for (i = 0; i < count; i++) {
                                if (i > 0)
                                        str_append_c(ctx->value, ' ');
-                               str_printfa(ctx->value, "%u", i);
+                               setting_export_section_name(ctx->value, def, children[i], i);
                        }
                        change_children = array_get(change_val, &count2);
                        i_assert(count == count2);
@@ -299,7 +323,7 @@ settings_export(struct config_export_context *ctx,
                for (i = 0; i < count; i++) {
                        str_append(ctx->prefix, def->key);
                        str_append_c(ctx->prefix, SETTINGS_SEPARATOR);
-                       str_printfa(ctx->prefix, "%u", i);
+                       setting_export_section_name(ctx->prefix, def, children[i], i);
                        str_append_c(ctx->prefix, SETTINGS_SEPARATOR);
                        settings_export(ctx, def->list_info,
                                        def->type == SET_DEFLIST_UNIQUE,