]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-ssl-iostream: Change ssl_iostream_context_cache_get() to return 1 on new context
authorAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 3 Feb 2025 12:10:39 +0000 (14:10 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:39:01 +0000 (12:39 +0200)
This allows differentiating when a new context was actually created.

src/lib-ssl-iostream/iostream-ssl-context-cache.c
src/lib-ssl-iostream/iostream-ssl.h

index 033cc769726494ddebd8e073289000a2c5444380..85d4b1bef295de02a2f33eb93d8e583eba0092d1 100644 (file)
@@ -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)
index 379a0bc9a731c6fa42856483ce3f1facc4ba15a1..3327f89b1a14b2cdae2069b949baa4aab208c013 100644 (file)
@@ -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);