]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dict-sql: Split off struct dict_sql_map_settings from dict_sql_legacy_settings
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 13 Mar 2024 20:53:01 +0000 (22:53 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:13 +0000 (12:34 +0200)
src/lib-dict-backend/dict-sql-legacy-settings.c
src/lib-dict-backend/dict-sql-private.h
src/lib-dict-backend/dict-sql-settings.h
src/lib-dict-backend/dict-sql.c

index 8e11038ecec3590dfd9422610bcb0060fe7597f1..1b363f05307d8515ed4e4cf87bab03a8daa5fd56 100644 (file)
@@ -135,8 +135,8 @@ static const char *dict_sql_fields_map(struct setting_parser_ctx *ctx)
                }
        }
 
-       if (ctx->set->max_pattern_fields_count < count)
-               ctx->set->max_pattern_fields_count = count;
+       if (ctx->set->map_set.max_pattern_fields_count < count)
+               ctx->set->map_set.max_pattern_fields_count = count;
        ctx->cur_map.pattern = p_strdup(ctx->pool, str_c(pattern));
        return NULL;
 }
@@ -200,7 +200,7 @@ static const char *dict_sql_map_finish(struct setting_parser_ctx *ctx)
                if (strchr(ctx->cur_map.pattern, '$') != NULL)
                        return "Missing fields for pattern variables";
        }
-       array_push_back(&ctx->set->maps, &ctx->cur_map);
+       array_push_back(&ctx->set->map_set.maps, &ctx->cur_map);
        i_zero(&ctx->cur_map);
        return NULL;
 }
@@ -312,7 +312,7 @@ dict_sql_legacy_settings_read(const char *path, const char **error_r)
        ctx.pool = pool;
        ctx.set = p_new(pool, struct dict_sql_legacy_settings, 1);
        t_array_init(&ctx.cur_fields, 16);
-       p_array_init(&ctx.set->maps, pool, 8);
+       p_array_init(&ctx.set->map_set.maps, pool, 8);
 
        if (!settings_read(path, NULL, parse_setting, parse_section,
                           &ctx, error_r)) {
@@ -333,6 +333,9 @@ dict_sql_legacy_settings_read(const char *path, const char **error_r)
        cache->set = ctx.set;
 
        hash_table_insert(dict_sql_legacy_settings_cache, cache->path, cache);
+
+       ctx.set->map_set.pool = pool;
+       pool_ref(pool);
        return ctx.set;
 }
 
index 54089c9fccba580f2bc78cde71da7aa353e5d948..d1e00d6b45fee23c2bb08d9970c2709437712e36 100644 (file)
@@ -6,7 +6,7 @@ struct sql_dict {
 
        pool_t pool;
        struct sql_db *db;
-       const struct dict_sql_legacy_settings *set;
+       struct dict_sql_map_settings *set;
 };
 
 #endif
index 68758f2c629c1c2feb1c938d1a7ae06a889af4df..838071eb9d0eb8f43abc1fac3ab64f8b7cbf7e9d 100644 (file)
@@ -34,13 +34,17 @@ struct dict_sql_map {
        const enum dict_sql_type *value_types;
 };
 
-struct dict_sql_legacy_settings {
-       const char *connect;
-
+struct dict_sql_map_settings {
+       pool_t pool;
        unsigned int max_pattern_fields_count;
        ARRAY(struct dict_sql_map) maps;
 };
 
+struct dict_sql_legacy_settings {
+       const char *connect;
+       struct dict_sql_map_settings map_set;
+};
+
 struct dict_sql_legacy_settings *
 dict_sql_legacy_settings_read(const char *path, const char **error_r);
 
index 1c337840cbfd645d921d15861a63b7b1e03b35e4..b2ccbb2dcb9b90e16dd43dd0466f4550114b18df 100644 (file)
@@ -101,21 +101,25 @@ sql_dict_init_legacy(struct dict *driver, const char *uri,
                     struct dict **dict_r, const char **error_r)
 {
        struct sql_legacy_settings sql_set;
+       struct dict_sql_legacy_settings *dict_sql_set;
        struct sql_dict *dict;
        pool_t pool;
 
        pool = pool_alloconly_create("sql dict", 2048);
-       dict = p_new(pool, struct sql_dict, 1);
-       dict->pool = pool;
-       dict->dict = *driver;
-       dict->set = dict_sql_legacy_settings_read(uri, error_r);
-       if (dict->set == NULL) {
+       dict_sql_set = dict_sql_legacy_settings_read(uri, error_r);
+       if (dict_sql_set == NULL) {
                pool_unref(&pool);
                return -1;
        }
+
+       dict = p_new(pool, struct sql_dict, 1);
+       dict->pool = pool;
+       dict->dict = *driver;
+       dict->set = &dict_sql_set->map_set;
+
        i_zero(&sql_set);
        sql_set.driver = driver->name;
-       sql_set.connect_string = dict->set->connect;
+       sql_set.connect_string = dict_sql_set->connect;
        sql_set.event_parent = set->event_parent;
 
        if (sql_db_cache_new_legacy(dict_sql_db_cache, &sql_set,
@@ -132,6 +136,7 @@ static void sql_dict_deinit(struct dict *_dict)
 {
        struct sql_dict *dict = (struct sql_dict *)_dict;
 
+       pool_unref(&dict->set->pool);
        sql_unref(&dict->db);
        pool_unref(&dict->pool);
 }