]> git.sesse.net Git - vlc/commitdiff
gnutls: move handshake callback to credentials (alongside open/close)
authorRémi Denis-Courmont <remi@remlab.net>
Fri, 22 Aug 2014 22:15:23 +0000 (01:15 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Fri, 22 Aug 2014 22:24:14 +0000 (01:24 +0300)
include/vlc_tls.h
modules/misc/gnutls.c
src/network/tls.c

index 4af2efce721765e367195428cd71c6412f50ee61..b143544ffe68cabf314c4c7bc915966247cb723c 100644 (file)
@@ -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 *);
index c14eb83217c8b410a0b07251f349cd2c107d6993..a43590740c133f1a26944baea27607399a6dd718 100644 (file)
@@ -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);
index fde45dc6431087a96de1d2bcbe37f778a3efb789..ca9dec469e83c48a43669165ec948496988c8161 100644 (file)
@@ -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);
 }
 
 /**