From: Aki Tuomi Date: Mon, 3 Feb 2025 12:10:39 +0000 (+0200) Subject: lib-ssl-iostream: Change ssl_iostream_context_cache_get() to return 1 on new context X-Git-Tag: 2.4.1~222 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=65bc1c9d29b0bbb733d3eed734cc121aa38db42a;p=thirdparty%2Fdovecot%2Fcore.git lib-ssl-iostream: Change ssl_iostream_context_cache_get() to return 1 on new context This allows differentiating when a new context was actually created. --- diff --git a/src/lib-ssl-iostream/iostream-ssl-context-cache.c b/src/lib-ssl-iostream/iostream-ssl-context-cache.c index 033cc76972..85d4b1bef2 100644 --- a/src/lib-ssl-iostream/iostream-ssl-context-cache.c +++ b/src/lib-ssl-iostream/iostream-ssl-context-cache.c @@ -97,7 +97,7 @@ ssl_iostream_context_cache_get(const struct ssl_iostream_settings *set, ssl_iostream_context_ref(ctx); *ctx_r = ctx; - return 0; + return 1; } int ssl_iostream_client_context_cache_get(const struct ssl_iostream_settings *set, @@ -105,12 +105,13 @@ int ssl_iostream_client_context_cache_get(const struct ssl_iostream_settings *se const char **error_r) { const char *error; - if (ssl_iostream_context_cache_get(set, FALSE, ctx_r, &error) < 0) { + int ret; + if ((ret = ssl_iostream_context_cache_get(set, FALSE, ctx_r, &error)) < 0) { *error_r = t_strdup_printf( "Couldn't initialize SSL client context: %s", error); return -1; } - return 0; + return ret; } int ssl_iostream_server_context_cache_get(const struct ssl_iostream_settings *set, @@ -118,12 +119,13 @@ int ssl_iostream_server_context_cache_get(const struct ssl_iostream_settings *se const char **error_r) { const char *error; - if (ssl_iostream_context_cache_get(set, TRUE, ctx_r, &error) < 0) { + int ret; + if ((ret = ssl_iostream_context_cache_get(set, TRUE, ctx_r, &error)) < 0) { *error_r = t_strdup_printf( "Couldn't initialize SSL server context: %s", error); return -1; } - return 0; + return ret; } void ssl_iostream_context_cache_free(void) diff --git a/src/lib-ssl-iostream/iostream-ssl.h b/src/lib-ssl-iostream/iostream-ssl.h index 379a0bc9a7..3327f89b1a 100644 --- a/src/lib-ssl-iostream/iostream-ssl.h +++ b/src/lib-ssl-iostream/iostream-ssl.h @@ -267,7 +267,11 @@ void ssl_iostream_context_unref(struct ssl_iostream_context **ctx); /* Persistent cache of ssl_iostream_contexts. The context is permanently stored until ssl_iostream_context_cache_free() is called. The returned context - must be unreferenced by the caller. */ + must be unreferenced by the caller. + + Returns 1 if new context was created, 0 if existing was re-used, and + -1 on error. +*/ int ssl_iostream_client_context_cache_get(const struct ssl_iostream_settings *set, struct ssl_iostream_context **ctx_r, const char **error_r);