[vlc-commits] Merge tls_ServerSessionPrepare() and tls_SessionHandshake()
Rémi Denis-Courmont
git at videolan.org
Sat Jul 23 11:17:15 CEST 2011
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Jul 23 11:45:40 2011 +0300| [9c8d0bf2885a29aac419375d8e0dbec90e1522cc] | committer: Rémi Denis-Courmont
Merge tls_ServerSessionPrepare() and tls_SessionHandshake()
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9c8d0bf2885a29aac419375d8e0dbec90e1522cc
---
include/vlc_tls.h | 7 +++----
src/network/httpd.c | 32 ++++++++++++--------------------
src/network/tls.c | 20 ++++++++------------
3 files changed, 23 insertions(+), 36 deletions(-)
diff --git a/include/vlc_tls.h b/include/vlc_tls.h
index cff6b6f..2495470 100644
--- a/include/vlc_tls.h
+++ b/include/vlc_tls.h
@@ -67,10 +67,9 @@ void tls_ServerDelete (tls_server_t *);
int tls_ServerAddCA (tls_server_t *srv, const char *path);
int tls_ServerAddCRL (tls_server_t *srv, const char *path);
-tls_session_t *tls_ServerSessionPrepare (tls_server_t *);
-int tls_ServerSessionHandshake (tls_session_t *, int fd);
-int tls_SessionContinueHandshake (tls_session_t *);
-void tls_ServerSessionClose (tls_session_t *);
+tls_session_t *tls_ServerSessionCreate (tls_server_t *, int fd);
+int tls_ServerSessionHandshake (tls_session_t *);
+void tls_ServerSessionDelete (tls_session_t *);
VLC_API tls_session_t * tls_ClientCreate( vlc_object_t *, int, const char * );
VLC_API void tls_ClientDelete( tls_session_t * );
diff --git a/src/network/httpd.c b/src/network/httpd.c
index 29c8f84..c976c9b 100644
--- a/src/network/httpd.c
+++ b/src/network/httpd.c
@@ -1429,7 +1429,7 @@ static void httpd_ClientClean( httpd_client_t *cl )
if( cl->fd >= 0 )
{
if( cl->p_tls != NULL )
- tls_ServerSessionClose( cl->p_tls );
+ tls_ServerSessionDelete( cl->p_tls );
net_Close( cl->fd );
cl->fd = -1;
}
@@ -2015,7 +2015,7 @@ static void httpd_ClientSend( httpd_client_t *cl )
static void httpd_ClientTlsHsIn( httpd_client_t *cl )
{
- switch( tls_SessionContinueHandshake( cl->p_tls ) )
+ switch( tls_ServerSessionHandshake( cl->p_tls ) )
{
case 0:
cl->i_state = HTTPD_CLIENT_RECEIVING;
@@ -2033,7 +2033,7 @@ static void httpd_ClientTlsHsIn( httpd_client_t *cl )
static void httpd_ClientTlsHsOut( httpd_client_t *cl )
{
- switch( tls_SessionContinueHandshake( cl->p_tls ) )
+ switch( tls_ServerSessionHandshake( cl->p_tls ) )
{
case 0:
cl->i_state = HTTPD_CLIENT_RECEIVING;
@@ -2053,17 +2053,12 @@ static void httpd_ClientTlsHsOut( httpd_client_t *cl )
static void* httpd_HostThread( void *data )
{
httpd_host_t *host = data;
- tls_session_t *p_tls = NULL;
counter_t *p_total_counter = stats_CounterCreate( host, VLC_VAR_INTEGER, STATS_COUNTER );
counter_t *p_active_counter = stats_CounterCreate( host, VLC_VAR_INTEGER, STATS_COUNTER );
int evfd = vlc_object_waitpipe( VLC_OBJECT( host ) );
for( ;; )
{
- /* prepare a new TLS session */
- if( ( p_tls == NULL ) && ( host->p_tls != NULL ) )
- p_tls = tls_ServerSessionPrepare( host->p_tls );
-
struct pollfd ufd[host->nfd + host->i_client + 1];
unsigned nfd;
for( nfd = 0; nfd < host->nfd; nfd++ )
@@ -2538,16 +2533,20 @@ static void* httpd_HostThread( void *data )
setsockopt (fd, SOL_SOCKET, SO_REUSEADDR,
&(int){ 1 }, sizeof(int));
- if( p_tls != NULL )
+ tls_session_t *p_tls;
+
+ if( host->p_tls != NULL )
{
- switch( tls_ServerSessionHandshake( p_tls, fd ) )
+ p_tls = tls_ServerSessionCreate( host->p_tls, fd );
+ switch( tls_ServerSessionHandshake( p_tls ) )
{
case -1:
msg_Err( host, "Rejecting TLS connection" );
+ /* p_tls is destroyed implicitly */
net_Close( fd );
fd = -1;
p_tls = NULL;
- break;
+ continue;
case 1: /* missing input - most likely */
i_state = HTTPD_CLIENT_TLS_HS_IN;
@@ -2557,29 +2556,22 @@ static void* httpd_HostThread( void *data )
i_state = HTTPD_CLIENT_TLS_HS_OUT;
break;
}
-
- if( (p_tls == NULL) != (host->p_tls == NULL) )
- break; // wasted TLS session, cannot accept() anymore
}
+ else
+ p_tls = NULL;
stats_UpdateInteger( host, p_total_counter, 1, NULL );
stats_UpdateInteger( host, p_active_counter, 1, NULL );
cl = httpd_ClientNew( fd, p_tls, now );
- p_tls = NULL;
vlc_mutex_lock( &host->lock );
TAB_APPEND( host->i_client, host->client, cl );
vlc_mutex_unlock( &host->lock );
if( i_state != -1 )
cl->i_state = i_state; // override state for TLS
-
- if (host->p_tls != NULL)
- break; // cannot accept further without new TLS session
}
}
- if( p_tls != NULL )
- tls_ServerSessionClose( p_tls );
if( p_total_counter )
stats_CounterClean( p_total_counter );
if( p_active_counter )
diff --git a/src/network/tls.c b/src/network/tls.c
index 7cd6797..87b1421 100644
--- a/src/network/tls.c
+++ b/src/network/tls.c
@@ -115,31 +115,27 @@ int tls_ServerAddCRL (tls_server_t *srv, const char *path)
}
-tls_session_t *tls_ServerSessionPrepare (tls_server_t *srv)
+tls_session_t *tls_ServerSessionCreate (tls_server_t *srv, int fd)
{
- return srv->pf_open (srv);
+ tls_session_t *ses = srv->pf_open (srv);
+ if (ses != NULL)
+ ses->pf_set_fd (ses, fd);
+ return ses;
}
-void tls_ServerSessionClose (tls_session_t *ses)
+void tls_ServerSessionDelete (tls_session_t *ses)
{
tls_server_t *srv = (tls_server_t *)(ses->p_parent);
srv->pf_close (srv, ses);
}
-int tls_ServerSessionHandshake (tls_session_t *ses, int fd)
-{
- ses->pf_set_fd (ses, fd);
- return 2;
-}
-
-
-int tls_SessionContinueHandshake (tls_session_t *ses)
+int tls_ServerSessionHandshake (tls_session_t *ses)
{
int val = ses->pf_handshake (ses);
if (val < 0)
- tls_ServerSessionClose (ses);
+ tls_ServerSessionDelete (ses);
return val;
}
More information about the vlc-commits
mailing list