SSL_CTX_set_mode(ssl_ctx, SSL_MODE_ENABLE_PARTIAL_WRITE);
ctx = i_new(struct ssl_iostream_context, 1);
+ ctx->refcount = 1;
ctx->ssl_ctx = ssl_ctx;
ctx->client_ctx = TRUE;
if (ssl_iostream_context_init_common(ctx, &set_copy, error_r) < 0) {
}
ctx = i_new(struct ssl_iostream_context, 1);
+ ctx->refcount = 1;
ctx->ssl_ctx = ssl_ctx;
if (ssl_iostream_context_init_common(ctx, set, error_r) < 0) {
ssl_iostream_context_unref(&ctx);
return 0;
}
-void openssl_iostream_context_deinit(struct ssl_iostream_context *ctx)
+void openssl_iostream_context_ref(struct ssl_iostream_context *ctx)
{
+ i_assert(ctx->refcount > 0);
+ ctx->refcount++;
+}
+
+void openssl_iostream_context_unref(struct ssl_iostream_context *ctx)
+{
+ i_assert(ctx->refcount > 0);
+ if (--ctx->refcount > 0)
+ return;
+
SSL_CTX_free(ctx->ssl_ctx);
pool_unref(&ctx->pool);
i_free(ctx);
static const struct iostream_ssl_vfuncs ssl_vfuncs = {
.context_init_client = openssl_iostream_context_init_client,
.context_init_server = openssl_iostream_context_init_server,
- .context_deinit = openssl_iostream_context_deinit,
+ .context_ref = openssl_iostream_context_ref,
+ .context_unref = openssl_iostream_context_unref,
.create = openssl_iostream_create,
.unref = openssl_iostream_unref,
};
struct ssl_iostream_context {
+ int refcount;
SSL_CTX *ssl_ctx;
pool_t pool;
int openssl_iostream_context_init_server(const struct ssl_iostream_settings *set,
struct ssl_iostream_context **ctx_r,
const char **error_r);
-void openssl_iostream_context_deinit(struct ssl_iostream_context *ctx);
+void openssl_iostream_context_ref(struct ssl_iostream_context *ctx);
+void openssl_iostream_context_unref(struct ssl_iostream_context *ctx);
void openssl_iostream_global_deinit(void);
int openssl_iostream_load_key(const struct ssl_iostream_cert *set,
int (*context_init_server)(const struct ssl_iostream_settings *set,
struct ssl_iostream_context **ctx_r,
const char **error_r);
- void (*context_deinit)(struct ssl_iostream_context *ctx);
+ void (*context_ref)(struct ssl_iostream_context *ctx);
+ void (*context_unref)(struct ssl_iostream_context *ctx);
int (*create)(struct ssl_iostream_context *ctx, const char *host,
const struct ssl_iostream_settings *set,
return ssl_vfuncs->context_init_server(set, ctx_r, error_r);
}
+void ssl_iostream_context_ref(struct ssl_iostream_context *ctx)
+{
+ ssl_vfuncs->context_ref(ctx);
+}
+
void ssl_iostream_context_unref(struct ssl_iostream_context **_ctx)
{
struct ssl_iostream_context *ctx = *_ctx;
*_ctx = NULL;
- ssl_vfuncs->context_deinit(ctx);
+ ssl_vfuncs->context_unref(ctx);
}
int io_stream_create_ssl_client(struct ssl_iostream_context *ctx, const char *host,
int ssl_iostream_context_init_server(const struct ssl_iostream_settings *set,
struct ssl_iostream_context **ctx_r,
const char **error_r);
+void ssl_iostream_context_ref(struct ssl_iostream_context *ctx);
void ssl_iostream_context_unref(struct ssl_iostream_context **ctx);
/* FIXME: temporarily for backwards compatibility, remove later */
#define ssl_iostream_context_deinit(ctx) ssl_iostream_context_unref(ctx)