vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Sat Aug 23 01:15:23 2014 +0300| [2200a4579e5f9f7b9a1ebd22e892fe95d6862b87] | committer: Rémi Denis-Courmont
gnutls: move handshake callback to credentials (alongside open/close) > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2200a4579e5f9f7b9a1ebd22e892fe95d6862b87 --- include/vlc_tls.h | 4 ++-- modules/misc/gnutls.c | 27 ++++++++++++--------------- src/network/tls.c | 14 ++++++++------ 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/include/vlc_tls.h b/include/vlc_tls.h index 4af2efc..b143544 100644 --- a/include/vlc_tls.h +++ b/include/vlc_tls.h @@ -42,7 +42,6 @@ struct vlc_tls vlc_tls_sys_t *sys; struct virtual_socket_t sock; - int (*handshake) (vlc_tls_t *, const char *host, const char *service); }; VLC_API vlc_tls_t *vlc_tls_ClientSessionCreate (vlc_tls_creds_t *, int fd, @@ -66,7 +65,8 @@ struct vlc_tls_creds vlc_tls_creds_sys_t *sys; int (*open) (vlc_tls_creds_t *, vlc_tls_t *, int fd, const char *host); - void (*close) (vlc_tls_creds_t *, vlc_tls_t *); + int (*handshake) (vlc_tls_t *, const char *host, const char *service); + void (*close) (vlc_tls_t *); }; VLC_API vlc_tls_creds_t *vlc_tls_ClientCreate (vlc_object_t *); diff --git a/modules/misc/gnutls.c b/modules/misc/gnutls.c index c14eb83..a435907 100644 --- a/modules/misc/gnutls.c +++ b/modules/misc/gnutls.c @@ -423,7 +423,7 @@ struct vlc_tls_creds_sys * Terminates TLS session and releases session data. * You still have to close the socket yourself. */ -static void gnutls_SessionClose (vlc_tls_creds_t *crd, vlc_tls_t *session) +static void gnutls_SessionClose (vlc_tls_t *session) { vlc_tls_sys_t *sys = session->sys; @@ -432,7 +432,6 @@ static void gnutls_SessionClose (vlc_tls_creds_t *crd, vlc_tls_t *session) gnutls_deinit (sys->session); free (sys); - (void) crd; } @@ -447,10 +446,6 @@ static int gnutls_SessionOpen (vlc_tls_creds_t *crd, vlc_tls_t *session, session->sock.p_sys = session; session->sock.pf_send = gnutls_Send; session->sock.pf_recv = gnutls_Recv; - if (type == GNUTLS_SERVER) - session->handshake = gnutls_ContinueHandshake; - else - session->handshake = gnutls_HandshakeAndValidate; sys->handshaked = false; int val = gnutls_init (&sys->session, type); @@ -479,7 +474,7 @@ static int gnutls_SessionOpen (vlc_tls_creds_t *crd, vlc_tls_t *session, return VLC_SUCCESS; error: - gnutls_SessionClose (crd, session); + gnutls_SessionClose (session); return VLC_EGENERIC; } @@ -528,10 +523,6 @@ static int OpenServer (vlc_tls_creds_t *crd, const char *cert, const char *key) if (unlikely(sys == NULL)) goto error; - crd->sys = sys; - crd->open = gnutls_ServerSessionOpen; - crd->close = gnutls_SessionClose; - /* Sets server's credentials */ val = gnutls_certificate_allocate_credentials (&sys->x509_cred); if (val != 0) @@ -600,6 +591,11 @@ static int OpenServer (vlc_tls_creds_t *crd, const char *cert, const char *key) gnutls_strerror (val)); } + crd->sys = sys; + crd->open = gnutls_ServerSessionOpen; + crd->handshake = gnutls_ContinueHandshake; + crd->close = gnutls_SessionClose; + return VLC_SUCCESS; error: @@ -635,10 +631,6 @@ static int OpenClient (vlc_tls_creds_t *crd) if (unlikely(sys == NULL)) goto error; - crd->sys = sys; - crd->open = gnutls_ClientSessionOpen; - crd->close = gnutls_SessionClose; - int val = gnutls_certificate_allocate_credentials (&sys->x509_cred); if (val != 0) { @@ -657,6 +649,11 @@ static int OpenClient (vlc_tls_creds_t *crd) gnutls_certificate_set_verify_flags (sys->x509_cred, GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT); + crd->sys = sys; + crd->open = gnutls_ClientSessionOpen; + crd->handshake = gnutls_HandshakeAndValidate; + crd->close = gnutls_SessionClose; + return VLC_SUCCESS; error: free (sys); diff --git a/src/network/tls.c b/src/network/tls.c index fde45dc..ca9dec4 100644 --- a/src/network/tls.c +++ b/src/network/tls.c @@ -157,18 +157,20 @@ vlc_tls_t *vlc_tls_SessionCreate (vlc_tls_creds_t *crd, int fd, return NULL; } -void vlc_tls_SessionDelete (vlc_tls_t *session) +int vlc_tls_SessionHandshake (vlc_tls_t *session, const char *host, + const char *service) { vlc_tls_creds_t *crd = (vlc_tls_creds_t *)(session->p_parent); - crd->close (crd, session); - vlc_object_release (session); + return crd->handshake (session, host, service); } -int vlc_tls_SessionHandshake (vlc_tls_t *session, const char *host, - const char *service) +void vlc_tls_SessionDelete (vlc_tls_t *session) { - return session->handshake (session, host, service); + vlc_tls_creds_t *crd = (vlc_tls_creds_t *)(session->p_parent); + + crd->close (session); + vlc_object_release (session); } /** _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
