From: Timo Sirainen Date: Mon, 30 Oct 2017 14:54:34 +0000 (+0200) Subject: lib-ssl-iostream: Add ssl_iostream_settings_init_from() X-Git-Tag: 2.3.0.rc1~542 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cfa1edd025234945720dfd2834710a8bbb24d906;p=thirdparty%2Fdovecot%2Fcore.git lib-ssl-iostream: Add ssl_iostream_settings_init_from() This allows duplicating settings to an already existing struct without having to allocate it. --- diff --git a/src/lib-ssl-iostream/iostream-ssl.c b/src/lib-ssl-iostream/iostream-ssl.c index ceaec061fa..66027565a9 100644 --- a/src/lib-ssl-iostream/iostream-ssl.c +++ b/src/lib-ssl-iostream/iostream-ssl.c @@ -215,15 +215,21 @@ const char *ssl_iostream_get_last_error(struct ssl_iostream *ssl_io) return ssl_vfuncs->get_last_error(ssl_io); } -struct ssl_iostream_settings * -ssl_iostream_settings_dup(pool_t pool, - const struct ssl_iostream_settings *old_set) +struct ssl_iostream_settings *ssl_iostream_settings_dup(pool_t pool, + const struct ssl_iostream_settings *old_set) { struct ssl_iostream_settings *new_set; new_set = p_new(pool, struct ssl_iostream_settings, 1); - memcpy(new_set, old_set, sizeof(*new_set)); + ssl_iostream_settings_init_from(pool, new_set, old_set); + return new_set; +} +void ssl_iostream_settings_init_from(pool_t pool, + struct ssl_iostream_settings *new_set, + const struct ssl_iostream_settings *old_set) +{ + memcpy(new_set, old_set, sizeof(*new_set)); new_set->protocols = p_strdup(pool, old_set->protocols); new_set->cipher_list = p_strdup(pool, old_set->cipher_list); new_set->curve_list = p_strdup(pool, old_set->curve_list); @@ -239,6 +245,4 @@ ssl_iostream_settings_dup(pool_t pool, new_set->dh = p_strdup(pool, old_set->dh); new_set->cert_username_field = p_strdup(pool, old_set->cert_username_field); new_set->crypto_device = p_strdup(pool, old_set->crypto_device); - - return new_set; } diff --git a/src/lib-ssl-iostream/iostream-ssl.h b/src/lib-ssl-iostream/iostream-ssl.h index bdc9dfea14..4de49ba197 100644 --- a/src/lib-ssl-iostream/iostream-ssl.h +++ b/src/lib-ssl-iostream/iostream-ssl.h @@ -91,7 +91,11 @@ 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_deinit(struct ssl_iostream_context **ctx); + struct ssl_iostream_settings *ssl_iostream_settings_dup(pool_t pool, const struct ssl_iostream_settings *old_set); +void ssl_iostream_settings_init_from(pool_t pool, + struct ssl_iostream_settings *new_set, + const struct ssl_iostream_settings *old_set); #endif