[vlc-commits] tls: make session independent of credentials

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 19:03:32 2015 +0200| [dc1b41f114fd5a1ab853767589c20f5c7a264e4a] | committer: Rémi Denis-Courmont

tls: make session independent of credentials

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

 include/vlc_tls.h   |    8 ++++++--
 src/network/httpd.c |    8 +++++---
 src/network/tls.c   |   12 ++----------
 3 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/include/vlc_tls.h b/include/vlc_tls.h
index 8b1fb76..d243f35 100644
--- a/include/vlc_tls.h
+++ b/include/vlc_tls.h
@@ -73,8 +73,6 @@ VLC_API vlc_tls_t *vlc_tls_ClientSessionCreate (vlc_tls_creds_t *, int fd,
 
 vlc_tls_t *vlc_tls_SessionCreate (vlc_tls_creds_t *, int fd, const char *host,
                                   const char *const *alpn);
-int vlc_tls_SessionHandshake (vlc_tls_t *, const char *host, const char *serv,
-                              char ** /*restrict*/ alp);
 VLC_API void vlc_tls_SessionDelete (vlc_tls_t *);
 
 VLC_API int vlc_tls_Read(vlc_tls_t *, void *buf, size_t len, bool waitall);
@@ -119,6 +117,12 @@ VLC_API vlc_tls_creds_t *vlc_tls_ClientCreate (vlc_object_t *);
 vlc_tls_creds_t *vlc_tls_ServerCreate (vlc_object_t *,
                                        const char *cert, const char *key);
 
+static inline int vlc_tls_SessionHandshake (vlc_tls_creds_t *crd,
+                                            vlc_tls_t *tls)
+{
+    return crd->handshake (tls, NULL, NULL, NULL);
+}
+
 /**
  * Releases TLS credentials.
  *
diff --git a/src/network/httpd.c b/src/network/httpd.c
index 97d1cc1..ce2f46b 100644
--- a/src/network/httpd.c
+++ b/src/network/httpd.c
@@ -1665,9 +1665,9 @@ static void httpd_ClientSend(httpd_client_t *cl)
     }
 }
 
-static void httpd_ClientTlsHandshake(httpd_client_t *cl)
+static void httpd_ClientTlsHandshake(httpd_host_t *host, httpd_client_t *cl)
 {
-    switch (vlc_tls_SessionHandshake(cl->p_tls, NULL, NULL, NULL))
+    switch (vlc_tls_SessionHandshake(host->p_tls, cl->p_tls))
     {
         case -1: cl->i_state = HTTPD_CLIENT_DEAD;       break;
         case 0:  cl->i_state = HTTPD_CLIENT_RECEIVING;  break;
@@ -2021,7 +2021,9 @@ static void httpdLoop(httpd_host_t *host)
             case HTTPD_CLIENT_RECEIVING: httpd_ClientRecv(cl); break;
             case HTTPD_CLIENT_SENDING:   httpd_ClientSend(cl); break;
             case HTTPD_CLIENT_TLS_HS_IN:
-            case HTTPD_CLIENT_TLS_HS_OUT: httpd_ClientTlsHandshake(cl); break;
+            case HTTPD_CLIENT_TLS_HS_OUT:
+                httpd_ClientTlsHandshake(host, cl);
+                break;
         }
     }
 
diff --git a/src/network/tls.c b/src/network/tls.c
index 2e7b4ff..571bb03 100644
--- a/src/network/tls.c
+++ b/src/network/tls.c
@@ -131,7 +131,7 @@ void vlc_tls_Delete (vlc_tls_creds_t *crd)
 vlc_tls_t *vlc_tls_SessionCreate (vlc_tls_creds_t *crd, int fd,
                                   const char *host, const char *const *alpn)
 {
-    vlc_tls_t *session = vlc_custom_create (crd, sizeof (*session),
+    vlc_tls_t *session = vlc_custom_create (crd->p_parent, sizeof (*session),
                                             "tls session");
     int val = crd->open (crd, session, fd, host, alpn);
     if (val != VLC_SUCCESS)
@@ -143,14 +143,6 @@ vlc_tls_t *vlc_tls_SessionCreate (vlc_tls_creds_t *crd, int fd,
     return session;
 }
 
-int vlc_tls_SessionHandshake (vlc_tls_t *session, const char *host,
-                              const char *service, char **restrict alp)
-{
-    vlc_tls_creds_t *crd = (vlc_tls_creds_t *)(session->p_parent);
-
-    return crd->handshake (session, host, service, alp);
-}
-
 void vlc_tls_SessionDelete (vlc_tls_t *session)
 {
     session->close (session);
@@ -186,7 +178,7 @@ vlc_tls_t *vlc_tls_ClientSessionCreate (vlc_tls_creds_t *crd, int fd,
     ufd[0].fd = fd;
 
     vlc_cleanup_push (cleanup_tls, session);
-    while ((val = vlc_tls_SessionHandshake (session, host, service, alp)) != 0)
+    while ((val = crd->handshake (session, host, service, alp)) != 0)
     {
         if (val < 0)
         {



More information about the vlc-commits mailing list