vlc | branch: master | Rémi Denis-Courmont <r...@remlab.net> | Sat Sep 29 23:00:21 2012 +0300| [52eb2b94e64261abd276c47d41326b32fbfdb546] | committer: Rémi Denis-Courmont
tls: simplify server code > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=52eb2b94e64261abd276c47d41326b32fbfdb546 --- include/vlc_tls.h | 4 +-- src/network/httpd.c | 78 +++++++++++---------------------------------------- src/network/tls.c | 7 ++--- 3 files changed, 20 insertions(+), 69 deletions(-) diff --git a/include/vlc_tls.h b/include/vlc_tls.h index d732d16..7c7720c 100644 --- a/include/vlc_tls.h +++ b/include/vlc_tls.h @@ -48,9 +48,8 @@ struct vlc_tls VLC_API vlc_tls_t *vlc_tls_ClientSessionCreate (vlc_tls_creds_t *, int fd, const char *host); vlc_tls_t *vlc_tls_ServerSessionCreate (vlc_tls_creds_t *, int fd); -int vlc_tls_ServerSessionHandshake (vlc_tls_t *); +int vlc_tls_SessionHandshake (vlc_tls_t *); VLC_API void vlc_tls_SessionDelete (vlc_tls_t *); -#define vlc_tls_ServerSessionDelete vlc_tls_SessionDelete /* NOTE: It is assumed that a->sock.p_sys = a */ # define tls_Send( a, b, c ) (((vlc_tls_t *)a)->sock.pf_send (a, b, c)) @@ -77,7 +76,6 @@ 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); VLC_API void vlc_tls_Delete (vlc_tls_creds_t *); -#define vlc_tls_ServerDelete vlc_tls_Delete int vlc_tls_ServerAddCA (vlc_tls_creds_t *srv, const char *path); int vlc_tls_ServerAddCRL (vlc_tls_creds_t *srv, const char *path); diff --git a/src/network/httpd.c b/src/network/httpd.c index 043e28b..e90dc98 100644 --- a/src/network/httpd.c +++ b/src/network/httpd.c @@ -928,7 +928,7 @@ httpd_host_t *vlc_https_HostNew( vlc_object_t *obj ) return httpd_HostCreate( obj, "http-host", "https-port", tls ); error: - vlc_tls_ServerDelete( tls ); + vlc_tls_Delete( tls ); return NULL; } @@ -987,8 +987,7 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this, vlc_mutex_unlock( &httpd.mutex ); vlc_UrlClean( &url ); - if( p_tls != NULL ) - vlc_tls_ServerDelete( p_tls ); + vlc_tls_Delete( p_tls ); return host; } @@ -1051,10 +1050,7 @@ error: } vlc_UrlClean( &url ); - - if( p_tls != NULL ) - vlc_tls_ServerDelete( p_tls ); - + vlc_tls_Delete( p_tls ); return NULL; } @@ -1100,9 +1096,7 @@ void httpd_HostDelete( httpd_host_t *host ) /* TODO */ } - if( host->p_tls != NULL) - vlc_tls_ServerDelete( host->p_tls ); - + vlc_tls_Delete( host->p_tls ); net_ListenClose( host->fds ); vlc_cond_destroy( &host->wait ); vlc_mutex_destroy( &host->lock ); @@ -1300,7 +1294,7 @@ static void httpd_ClientClean( httpd_client_t *cl ) if( cl->fd >= 0 ) { if( cl->p_tls != NULL ) - vlc_tls_ServerSessionDelete( cl->p_tls ); + vlc_tls_SessionDelete( cl->p_tls ); net_Close( cl->fd ); cl->fd = -1; } @@ -1324,6 +1318,8 @@ static httpd_client_t *httpd_ClientNew( int fd, vlc_tls_t *p_tls, mtime_t now ) cl->p_tls = p_tls; httpd_ClientInit( cl, now ); + if( p_tls != NULL ) + cl->i_state = HTTPD_CLIENT_TLS_HS_OUT; return cl; } @@ -1882,9 +1878,9 @@ static void httpd_ClientSend( httpd_client_t *cl ) } } -static void httpd_ClientTlsHsIn( httpd_client_t *cl ) +static void httpd_ClientTlsHandshake( httpd_client_t *cl ) { - switch( vlc_tls_ServerSessionHandshake( cl->p_tls ) ) + switch( vlc_tls_SessionHandshake( cl->p_tls ) ) { case 0: cl->i_state = HTTPD_CLIENT_RECEIVING; @@ -1892,30 +1888,15 @@ static void httpd_ClientTlsHsIn( httpd_client_t *cl ) case -1: cl->i_state = HTTPD_CLIENT_DEAD; - cl->p_tls = NULL; - break; - - case 2: - cl->i_state = HTTPD_CLIENT_TLS_HS_OUT; - } -} - -static void httpd_ClientTlsHsOut( httpd_client_t *cl ) -{ - switch( vlc_tls_ServerSessionHandshake( cl->p_tls ) ) - { - case 0: - cl->i_state = HTTPD_CLIENT_RECEIVING; - break; - - case -1: - cl->i_state = HTTPD_CLIENT_DEAD; - cl->p_tls = NULL; break; case 1: cl->i_state = HTTPD_CLIENT_TLS_HS_IN; break; + + case 2: + cl->i_state = HTTPD_CLIENT_TLS_HS_OUT; + break; } } @@ -2303,13 +2284,10 @@ static void* httpd_HostThread( void *data ) { httpd_ClientSend( cl ); } - else if( cl->i_state == HTTPD_CLIENT_TLS_HS_IN ) + else if( cl->i_state == HTTPD_CLIENT_TLS_HS_IN + || cl->i_state == HTTPD_CLIENT_TLS_HS_OUT ) { - httpd_ClientTlsHsIn( cl ); - } - else if( cl->i_state == HTTPD_CLIENT_TLS_HS_OUT ) - { - httpd_ClientTlsHsOut( cl ); + httpd_ClientTlsHandshake( cl ); } } @@ -2317,7 +2295,6 @@ static void* httpd_HostThread( void *data ) for( nfd = 0; nfd < host->nfd; nfd++ ) { httpd_client_t *cl; - int i_state = -1; int fd = ufd[nfd].fd; assert (fd == host->fds[nfd]); @@ -2335,34 +2312,13 @@ static void* httpd_HostThread( void *data ) vlc_tls_t *p_tls; if( host->p_tls != NULL ) - { p_tls = vlc_tls_ServerSessionCreate( host->p_tls, fd ); - switch( vlc_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; - continue; - - case 1: /* missing input - most likely */ - i_state = HTTPD_CLIENT_TLS_HS_IN; - break; - - case 2: /* missing output */ - i_state = HTTPD_CLIENT_TLS_HS_OUT; - break; - } - } else p_tls = NULL; cl = httpd_ClientNew( fd, p_tls, now ); + TAB_APPEND( host->i_client, host->client, cl ); - if( i_state != -1 ) - cl->i_state = i_state; // override state for TLS } } vlc_mutex_unlock( &host->lock ); diff --git a/src/network/tls.c b/src/network/tls.c index 0c0583d..1ffc465 100644 --- a/src/network/tls.c +++ b/src/network/tls.c @@ -185,12 +185,9 @@ vlc_tls_t *vlc_tls_ServerSessionCreate (vlc_tls_creds_t *crd, int fd) return vlc_tls_SessionCreate (crd, fd, NULL); } -int vlc_tls_ServerSessionHandshake (vlc_tls_t *ses) +int vlc_tls_SessionHandshake (vlc_tls_t *session) { - int val = ses->handshake (ses); - if (val < 0) - vlc_tls_ServerSessionDelete (ses); - return val; + return session->handshake (session); } /** _______________________________________________ vlc-commits mailing list vlc-commits@videolan.org http://mailman.videolan.org/listinfo/vlc-commits