From 6f38ff688393c0aaf331a04043dddf338fa2f8fa Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 10 Jun 2019 17:27:29 +0300 Subject: [PATCH] lib-storage: Add mail_storage_service_get_global() This allows accessing the global mail storage service. Normally there is only a single service created for the process at a time, so this allows accessing it. --- src/lib-storage/mail-storage-service.c | 11 +++++++++++ src/lib-storage/mail-storage-service.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/lib-storage/mail-storage-service.c b/src/lib-storage/mail-storage-service.c index fd4dfcc9ae..658d11ac0f 100644 --- a/src/lib-storage/mail-storage-service.c +++ b/src/lib-storage/mail-storage-service.c @@ -94,6 +94,7 @@ struct mail_storage_service_user { }; struct module *mail_storage_service_modules = NULL; +static struct mail_storage_service_ctx *storage_service_global = NULL; static int mail_storage_service_var_expand(struct mail_storage_service_ctx *ctx, @@ -991,6 +992,8 @@ mail_storage_service_init(struct master_service *service, master_service_init_log(service, ctx->default_log_prefix); } dict_drivers_register_builtin(); + if (storage_service_global == NULL) + storage_service_global = ctx; return ctx; } @@ -1725,6 +1728,9 @@ void mail_storage_service_deinit(struct mail_storage_service_ctx **_ctx) } if (ctx->set_cache != NULL) master_service_settings_cache_deinit(&ctx->set_cache); + + if (storage_service_global == ctx) + storage_service_global = NULL; pool_unref(&ctx->pool); module_dir_unload(&mail_storage_service_modules); @@ -1732,6 +1738,11 @@ void mail_storage_service_deinit(struct mail_storage_service_ctx **_ctx) dict_drivers_unregister_builtin(); } +struct mail_storage_service_ctx *mail_storage_service_get_global(void) +{ + return storage_service_global; +} + void **mail_storage_service_user_get_set(struct mail_storage_service_user *user) { return master_service_settings_parser_get_others(master_service, diff --git a/src/lib-storage/mail-storage-service.h b/src/lib-storage/mail-storage-service.h index 8861d6839e..0fa430b7da 100644 --- a/src/lib-storage/mail-storage-service.h +++ b/src/lib-storage/mail-storage-service.h @@ -136,6 +136,9 @@ void mail_storage_service_all_init_mask(struct mail_storage_service_ctx *ctx, int mail_storage_service_all_next(struct mail_storage_service_ctx *ctx, const char **username_r); void mail_storage_service_deinit(struct mail_storage_service_ctx **ctx); +/* Returns the first created service context. If it gets freed, NULL is + returned until the next time mail_storage_service_init() is called. */ +struct mail_storage_service_ctx *mail_storage_service_get_global(void); /* Activate user context. Normally this is called automatically by the ioloop, but e.g. during loops at deinit where all users are being destroyed, it's -- 2.47.3