Make tls_new accept xmpp_conn_t

This commit is contained in:
Alexander Krotov
2017-06-23 02:59:05 +03:00
parent f776b34d8c
commit c9ddc2b7ef
6 changed files with 16 additions and 16 deletions

View File

@@ -564,7 +564,7 @@ static void _auth(xmpp_conn_t * const conn)
}
if (conn->tls_support) {
tls_t *tls = tls_new(conn->ctx, conn->sock);
tls_t *tls = tls_new(conn);
/* If we couldn't init tls, it isn't there, so go on */
if (!tls) {

View File

@@ -874,7 +874,7 @@ int conn_tls_start(xmpp_conn_t * const conn)
conn->tls = NULL;
rc = XMPP_EINVOP;
} else {
conn->tls = tls_new(conn->ctx, conn->sock);
conn->tls = tls_new(conn);
rc = conn->tls == NULL ? XMPP_EMEM : 0;
}

View File

@@ -24,7 +24,7 @@ typedef struct _tls tls_t;
void tls_initialize(void);
void tls_shutdown(void);
tls_t *tls_new(xmpp_ctx_t *ctx, sock_t sock);
tls_t *tls_new(xmpp_conn_t *conn);
void tls_free(tls_t *tls);
int tls_set_credentials(tls_t *tls, const char *cafilename);

View File

@@ -33,7 +33,7 @@ void tls_shutdown(void)
return;
}
tls_t *tls_new(xmpp_ctx_t *ctx, sock_t sock)
tls_t *tls_new(xmpp_conn_t *conn)
{
/* always fail */
return NULL;

View File

@@ -46,13 +46,13 @@ void tls_shutdown(void)
gnutls_global_deinit();
}
tls_t *tls_new(xmpp_ctx_t *ctx, sock_t sock)
tls_t *tls_new(xmpp_conn_t *conn)
{
tls_t *tls = xmpp_alloc(ctx, sizeof(tls_t));
tls_t *tls = xmpp_alloc(conn->ctx, sizeof(tls_t));
if (tls) {
tls->ctx = ctx;
tls->sock = sock;
tls->ctx = conn->ctx;
tls->sock = conn->sock;
gnutls_init(&tls->session, GNUTLS_CLIENT);
gnutls_certificate_allocate_credentials(&tls->cred);
@@ -61,7 +61,7 @@ tls_t *tls_new(xmpp_ctx_t *ctx, sock_t sock)
gnutls_set_default_priority(tls->session);
/* fixme: this may require setting a callback on win32? */
gnutls_transport_set_int(tls->session, sock);
gnutls_transport_set_int(tls->session, conn->sock);
}
return tls;

View File

@@ -63,16 +63,16 @@ int tls_error(tls_t *tls)
return tls->lasterror;
}
tls_t *tls_new(xmpp_ctx_t *ctx, sock_t sock)
tls_t *tls_new(xmpp_conn_t *conn)
{
tls_t *tls = xmpp_alloc(ctx, sizeof(*tls));
tls_t *tls = xmpp_alloc(conn->ctx, sizeof(*tls));
if (tls) {
int ret;
memset(tls, 0, sizeof(*tls));
tls->ctx = ctx;
tls->sock = sock;
tls->ctx = conn->ctx;
tls->sock = conn->sock;
tls->ssl_ctx = SSL_CTX_new(SSLv23_client_method());
if (tls->ssl_ctx == NULL)
goto err;
@@ -92,7 +92,7 @@ tls_t *tls_new(xmpp_ctx_t *ctx, sock_t sock)
if (tls->ssl == NULL)
goto err_free_ctx;
ret = SSL_set_fd(tls->ssl, sock);
ret = SSL_set_fd(tls->ssl, conn->sock);
if (ret <= 0)
goto err_free_ssl;
}
@@ -104,8 +104,8 @@ err_free_ssl:
err_free_ctx:
SSL_CTX_free(tls->ssl_ctx);
err:
xmpp_free(ctx, tls);
_tls_log_error(ctx);
xmpp_free(conn->ctx, tls);
_tls_log_error(conn->ctx);
return NULL;
}