Commit 4b2909ca authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

tls: move close callback from credentials to session

parent d3c0569c
......@@ -45,6 +45,7 @@ struct vlc_tls
ssize_t (*recv)(struct vlc_tls *, void *, size_t);
ssize_t (*send)(struct vlc_tls *, const void *, size_t);
void (*close)(vlc_tls_t *);
};
/**
......@@ -95,7 +96,6 @@ struct vlc_tls_creds
const char *const *alpn);
int (*handshake) (vlc_tls_t *, const char *host, const char *service,
char ** /*restrict*/ alp);
void (*close) (vlc_tls_t *);
};
/**
......
......@@ -183,6 +183,20 @@ static ssize_t gnutls_Recv (vlc_tls_t *tls, void *buf, size_t length)
return (val < 0) ? gnutls_Error (tls, val) : val;
}
/**
* Terminates a TLS session.
*
* This terminates a TLS session and releases session data.
* The underlying socket must be closed separately.
*/
static void gnutls_Close (vlc_tls_t *tls)
{
gnutls_session_t session = tls->sys;
gnutls_bye (session, GNUTLS_SHUT_RDWR);
gnutls_deinit (session);
}
static int gnutls_SessionOpen (vlc_tls_t *tls, int type,
gnutls_certificate_credentials_t x509, int fd,
const char *const *alpn)
......@@ -251,6 +265,7 @@ static int gnutls_SessionOpen (vlc_tls_t *tls, int type,
tls->sys = session;
tls->send = gnutls_Send;
tls->recv = gnutls_Recv;
tls->close = gnutls_Close;
return VLC_SUCCESS;
error:
......@@ -317,18 +332,6 @@ done:
return 0;
}
/**
* Terminates TLS session and releases session data.
* You still have to close the socket yourself.
*/
static void gnutls_SessionClose (vlc_tls_t *tls)
{
gnutls_session_t session = tls->sys;
gnutls_bye (session, GNUTLS_SHUT_RDWR);
gnutls_deinit (session);
}
static int gnutls_ClientSessionOpen (vlc_tls_creds_t *crd, vlc_tls_t *tls,
int fd, const char *hostname,
const char *const *alpn)
......@@ -504,7 +507,6 @@ static int OpenClient (vlc_tls_creds_t *crd)
crd->sys = x509;
crd->open = gnutls_ClientSessionOpen;
crd->handshake = gnutls_ClientHandshake;
crd->close = gnutls_SessionClose;
return VLC_SUCCESS;
}
......@@ -638,7 +640,6 @@ static int OpenServer (vlc_tls_creds_t *crd, const char *cert, const char *key)
crd->sys = sys;
crd->open = gnutls_ServerSessionOpen;
crd->handshake = gnutls_ServerHandshake;
crd->close = gnutls_SessionClose;
return VLC_SUCCESS;
......
......@@ -542,6 +542,7 @@ static int st_SessionOpenCommon (vlc_tls_creds_t *crd, vlc_tls_t *session,
session->sys = sys;
session->send = st_Send;
session->recv = st_Recv;
session->close = st_SessionClose;
crd->handshake = st_Handshake;
SSLContextRef p_context = NULL;
......@@ -635,7 +636,6 @@ static int OpenClient (vlc_tls_creds_t *crd) {
crd->sys = sys;
crd->open = st_ClientSessionOpen;
crd->close = st_SessionClose;
return VLC_SUCCESS;
}
......@@ -792,7 +792,6 @@ static int OpenServer (vlc_tls_creds_t *crd, const char *cert, const char *key)
crd->sys = sys;
crd->open = st_ServerSessionOpen;
crd->close = st_SessionClose;
out:
if (policy)
......
......@@ -153,9 +153,7 @@ int vlc_tls_SessionHandshake (vlc_tls_t *session, const char *host,
void vlc_tls_SessionDelete (vlc_tls_t *session)
{
vlc_tls_creds_t *crd = (vlc_tls_creds_t *)(session->p_parent);
crd->close (session);
session->close (session);
vlc_object_release (session);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment