From 356b6fb8c70356d8fbdab820725124f87f2e4a14 Mon Sep 17 00:00:00 2001 From: Stephan Bosch <stephan.bosch@open-xchange.com> Date: Fri, 11 Oct 2024 20:34:37 +0200 Subject: [PATCH] lib-sieve: sieve-extensions - Use int for sieve_extension_require() status result --- .../plugins/environment/sieve-ext-environment.h | 7 ++++++- .../plugins/imap4flags/sieve-ext-imap4flags.h | 7 ++++++- .../plugins/vacation/ext-vacation-seconds.c | 11 +++++++---- src/lib-sieve/sieve-extensions.c | 14 +++++--------- src/lib-sieve/sieve-extensions.h | 6 +++--- src/plugins/imapsieve/ext-imapsieve.c | 10 ++++++---- 6 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/lib-sieve/plugins/environment/sieve-ext-environment.h b/src/lib-sieve/plugins/environment/sieve-ext-environment.h index 7ae76db3d..34b5e2edd 100644 --- a/src/lib-sieve/plugins/environment/sieve-ext-environment.h +++ b/src/lib-sieve/plugins/environment/sieve-ext-environment.h @@ -25,7 +25,12 @@ sieve_ext_environment_get_extension(struct sieve_instance *svinst) static inline const struct sieve_extension * sieve_ext_environment_require_extension(struct sieve_instance *svinst) { - return sieve_extension_require(svinst, &environment_extension, TRUE); + const struct sieve_extension *ext; + + if (sieve_extension_require(svinst, &environment_extension, TRUE, + &ext) < 0) + return NULL; + return ext; } bool sieve_ext_environment_is_active(const struct sieve_extension *env_ext, diff --git a/src/lib-sieve/plugins/imap4flags/sieve-ext-imap4flags.h b/src/lib-sieve/plugins/imap4flags/sieve-ext-imap4flags.h index 7c3078a73..fdac9bac5 100644 --- a/src/lib-sieve/plugins/imap4flags/sieve-ext-imap4flags.h +++ b/src/lib-sieve/plugins/imap4flags/sieve-ext-imap4flags.h @@ -16,7 +16,12 @@ extern const struct sieve_interpreter_extension static inline const struct sieve_extension * sieve_ext_imap4flags_require_extension(struct sieve_instance *svinst) { - return sieve_extension_require(svinst, &imap4flags_extension, TRUE); + const struct sieve_extension *ext; + + if (sieve_extension_require(svinst, &imap4flags_extension, TRUE, + &ext) < 0) + return NULL; + return ext; } void sieve_ext_imap4flags_interpreter_load( diff --git a/src/lib-sieve/plugins/vacation/ext-vacation-seconds.c b/src/lib-sieve/plugins/vacation/ext-vacation-seconds.c index 7775f3a6a..1d52fc44f 100644 --- a/src/lib-sieve/plugins/vacation/ext-vacation-seconds.c +++ b/src/lib-sieve/plugins/vacation/ext-vacation-seconds.c @@ -46,6 +46,7 @@ const struct sieve_extension_def vacation_seconds_extension = { static bool ext_vacation_seconds_load(const struct sieve_extension *ext, void **context) { + const struct sieve_extension *ext_vac; struct ext_vacation_seconds_context *extctx; if (*context != NULL) { @@ -53,11 +54,13 @@ ext_vacation_seconds_load(const struct sieve_extension *ext, void **context) *context = NULL; } - extctx = i_new(struct ext_vacation_seconds_context, 1); - /* Make sure vacation extension is registered */ - extctx->ext_vacation = sieve_extension_require( - ext->svinst, &vacation_extension, TRUE); + if (sieve_extension_require(ext->svinst, &vacation_extension, + TRUE, &ext_vac) < 0) + return FALSE; + + extctx = i_new(struct ext_vacation_seconds_context, 1); + extctx->ext_vacation = ext_vac; *context = extctx; return TRUE; diff --git a/src/lib-sieve/sieve-extensions.c b/src/lib-sieve/sieve-extensions.c index c1d553b09..58518f4f9 100644 --- a/src/lib-sieve/sieve-extensions.c +++ b/src/lib-sieve/sieve-extensions.c @@ -463,16 +463,12 @@ void sieve_extension_unregister(const struct sieve_extension *ext) } } -const struct sieve_extension * -sieve_extension_require(struct sieve_instance *svinst, - const struct sieve_extension_def *extdef, bool load) +int sieve_extension_require(struct sieve_instance *svinst, + const struct sieve_extension_def *extdef, bool load, + const struct sieve_extension **ext_r) { - const struct sieve_extension *ext; - - if (_sieve_extension_register_const(svinst, extdef, load, TRUE, - &ext) < 0) - return NULL; - return ext; + return _sieve_extension_register_const(svinst, extdef, load, TRUE, + ext_r); } bool sieve_extension_reload(const struct sieve_extension *ext) diff --git a/src/lib-sieve/sieve-extensions.h b/src/lib-sieve/sieve-extensions.h index 3d655ea76..7546b6352 100644 --- a/src/lib-sieve/sieve-extensions.h +++ b/src/lib-sieve/sieve-extensions.h @@ -130,9 +130,9 @@ sieve_extensions_get_preloaded(struct sieve_instance *svinst, int sieve_extension_register(struct sieve_instance *svinst, const struct sieve_extension_def *extdef, bool load, const struct sieve_extension **ext_r); -const struct sieve_extension * -sieve_extension_require(struct sieve_instance *svinst, - const struct sieve_extension_def *extension, bool load); +int sieve_extension_require(struct sieve_instance *svinst, + const struct sieve_extension_def *extdef, bool load, + const struct sieve_extension **ext_r); bool sieve_extension_reload(const struct sieve_extension *ext); void sieve_extension_unregister(const struct sieve_extension *ext); diff --git a/src/plugins/imapsieve/ext-imapsieve.c b/src/plugins/imapsieve/ext-imapsieve.c index ff56b5ef2..077e7b774 100644 --- a/src/plugins/imapsieve/ext-imapsieve.c +++ b/src/plugins/imapsieve/ext-imapsieve.c @@ -100,11 +100,13 @@ ext_vnd_imapsieve_load(const struct sieve_extension *ext, void **context) extctx = i_new(struct ext_vnd_imapsieve_context, 1); #ifdef __IMAPSIEVE_DUMMY - extctx->ext_imapsieve = sieve_extension_require( - ext->svinst, &imapsieve_extension_dummy, TRUE); + if (sieve_extension_require(ext->svinst, &imapsieve_extension_dummy, + TRUE, &extctx->ext_imapsieve) < 0) + return FALSE; #else - extctx->ext_imapsieve = sieve_extension_require( - ext->svinst, &imapsieve_extension, TRUE); + if (sieve_extension_require(ext->svinst, &imapsieve_extension, + TRUE, &extctx->ext_imapsieve) < 0) + return FALSE; #endif *context = extctx; -- GitLab