[vlc-commits] tls: move close callback from credentials to session

Rémi Denis-Courmont git at videolan.org
Wed Dec 16 21:31:18 CET 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Dec 16 18:55:47 2015 +0200| [4b2909cad5c5d36ec3b4f6f24992467faa1365b3] | committer: Rémi Denis-Courmont

tls: move close callback from credentials to session

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4b2909cad5c5d36ec3b4f6f24992467faa1365b3
---

 include/vlc_tls.h              |    2 +-
 modules/misc/gnutls.c          |   29 +++++++++++++++--------------
 modules/misc/securetransport.c |    3 +--
 src/network/tls.c              |    4 +---
 4 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/include/vlc_tls.h b/include/vlc_tls.h
index a39aee6..8b1fb76 100644
--- a/include/vlc_tls.h
+++ b/include/vlc_tls.h
@@ -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 *);
 };
 
 /**
diff --git a/modules/misc/gnutls.c b/modules/misc/gnutls.c
index 5330bf3..e1804ac 100644
--- a/modules/misc/gnutls.c
+++ b/modules/misc/gnutls.c
@@ -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;
 
diff --git a/modules/misc/securetransport.c b/modules/misc/securetransport.c
index bc9bff2..b84a7f4 100644
--- a/modules/misc/securetransport.c
+++ b/modules/misc/securetransport.c
@@ -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)
diff --git a/src/network/tls.c b/src/network/tls.c
index 7b7bfa5..2e7b4ff 100644
--- a/src/network/tls.c
+++ b/src/network/tls.c
@@ -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);
 }
 



More information about the vlc-commits mailing list