Commit 40f93137 authored by Pierre Ynard's avatar Pierre Ynard

Revert "Use separate HTTPd host per protocol"

This reverts commit f06b4d30.
This way provides more use-cases that are more useful.

Conflicts:

	src/network/httpd.c
parent e20af8a8
...@@ -79,6 +79,7 @@ struct httpd_host_t ...@@ -79,6 +79,7 @@ struct httpd_host_t
/* address/port and socket for listening at connections */ /* address/port and socket for listening at connections */
int *fds; int *fds;
unsigned nfd; unsigned nfd;
unsigned port;
vlc_thread_t thread; vlc_thread_t thread;
vlc_mutex_t lock; vlc_mutex_t lock;
...@@ -951,21 +952,13 @@ void httpd_StreamDelete( httpd_stream_t *stream ) ...@@ -951,21 +952,13 @@ void httpd_StreamDelete( httpd_stream_t *stream )
* Low level * Low level
*****************************************************************************/ *****************************************************************************/
static void* httpd_HostThread( void * ); static void* httpd_HostThread( void * );
static httpd_host_t *httpd_HostCreate( vlc_object_t *, httpd_host_t **, static httpd_host_t *httpd_HostCreate( vlc_object_t *, const char *,
const char *, const char *, const char *, vlc_tls_creds_t * );
vlc_tls_creds_t * );
static struct httpd_t
{
vlc_mutex_t mutex;
httpd_host_t *http, *https, *rtsp;
} httpd = { VLC_STATIC_MUTEX, NULL, NULL, NULL };
/* create a new host */ /* create a new host */
httpd_host_t *vlc_http_HostNew( vlc_object_t *p_this ) httpd_host_t *vlc_http_HostNew( vlc_object_t *p_this )
{ {
return httpd_HostCreate( p_this, &httpd.http, return httpd_HostCreate( p_this, "http-host", "http-port", NULL );
"http-host", "http-port", NULL );
} }
httpd_host_t *vlc_https_HostNew( vlc_object_t *obj ) httpd_host_t *vlc_https_HostNew( vlc_object_t *obj )
...@@ -1015,8 +1008,7 @@ httpd_host_t *vlc_https_HostNew( vlc_object_t *obj ) ...@@ -1015,8 +1008,7 @@ httpd_host_t *vlc_https_HostNew( vlc_object_t *obj )
free( crl ); free( crl );
} }
return httpd_HostCreate( obj, &httpd.https, return httpd_HostCreate( obj, "http-host", "https-port", tls );
"http-host", "https-port", tls );
error: error:
vlc_tls_ServerDelete( tls ); vlc_tls_ServerDelete( tls );
...@@ -1025,25 +1017,38 @@ error: ...@@ -1025,25 +1017,38 @@ error:
httpd_host_t *vlc_rtsp_HostNew( vlc_object_t *p_this ) httpd_host_t *vlc_rtsp_HostNew( vlc_object_t *p_this )
{ {
return httpd_HostCreate( p_this, &httpd.rtsp, return httpd_HostCreate( p_this, "rtsp-host", "rtsp-port", NULL );
"rtsp-host", "rtsp-port", NULL );
} }
static struct httpd_t
{
vlc_mutex_t mutex;
httpd_host_t **host;
int i_host;
} httpd = { VLC_STATIC_MUTEX, NULL, 0 };
static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this, static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
httpd_host_t **hostp,
const char *hostvar, const char *hostvar,
const char *portvar, const char *portvar,
vlc_tls_creds_t *p_tls ) vlc_tls_creds_t *p_tls )
{ {
httpd_host_t *host; httpd_host_t *host;
unsigned port = var_InheritInteger( p_this, portvar );
/* to be sure to avoid multiple creation */ /* to be sure to avoid multiple creation */
vlc_mutex_lock( &httpd.mutex ); vlc_mutex_lock( &httpd.mutex );
/* verify if it already exist */ /* verify if it already exist */
host = *hostp; for( int i = 0; i < httpd.i_host; i++ )
if( host != NULL )
{ {
host = httpd.host[i];
/* cannot mix TLS and non-TLS hosts */
if( host->port != port
|| (host->p_tls != NULL) != (p_tls != NULL) )
continue;
/* Increase existing matching host reference count. /* Increase existing matching host reference count.
* The reference count is written under both the global httpd and the * The reference count is written under both the global httpd and the
* host lock. It is read with either or both locks held. The global * host lock. It is read with either or both locks held. The global
...@@ -1058,6 +1063,8 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this, ...@@ -1058,6 +1063,8 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
return host; return host;
} }
host = NULL;
/* create the new host */ /* create the new host */
host = (httpd_host_t *)vlc_custom_create( p_this, sizeof (*host), host = (httpd_host_t *)vlc_custom_create( p_this, sizeof (*host),
"http host" ); "http host" );
...@@ -1069,7 +1076,6 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this, ...@@ -1069,7 +1076,6 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
host->i_ref = 1; host->i_ref = 1;
char *hostname = var_InheritString( p_this, hostvar ); char *hostname = var_InheritString( p_this, hostvar );
unsigned port = var_InheritInteger( p_this, portvar );
host->fds = net_ListenTCP( p_this, hostname, port ); host->fds = net_ListenTCP( p_this, hostname, port );
free( hostname ); free( hostname );
if( host->fds == NULL ) if( host->fds == NULL )
...@@ -1085,6 +1091,7 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this, ...@@ -1085,6 +1091,7 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
goto error; goto error;
} }
host->port = port;
host->i_url = 0; host->i_url = 0;
host->url = NULL; host->url = NULL;
host->i_client = 0; host->i_client = 0;
...@@ -1099,7 +1106,8 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this, ...@@ -1099,7 +1106,8 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
goto error; goto error;
} }
*hostp = host; /* now add it to httpd */
TAB_APPEND( httpd.i_host, httpd.host, host );
vlc_mutex_unlock( &httpd.mutex ); vlc_mutex_unlock( &httpd.mutex );
return host; return host;
...@@ -1144,6 +1152,7 @@ void httpd_HostDelete( httpd_host_t *host ) ...@@ -1144,6 +1152,7 @@ void httpd_HostDelete( httpd_host_t *host )
msg_Dbg( host, "httpd_HostDelete: host still in use" ); msg_Dbg( host, "httpd_HostDelete: host still in use" );
return; return;
} }
TAB_REMOVE( httpd.i_host, httpd.host, host );
vlc_object_kill( host ); vlc_object_kill( host );
vlc_join( host->thread, NULL ); vlc_join( host->thread, NULL );
...@@ -1172,14 +1181,6 @@ void httpd_HostDelete( httpd_host_t *host ) ...@@ -1172,14 +1181,6 @@ void httpd_HostDelete( httpd_host_t *host )
vlc_cond_destroy( &host->wait ); vlc_cond_destroy( &host->wait );
vlc_mutex_destroy( &host->lock ); vlc_mutex_destroy( &host->lock );
vlc_object_release( host ); vlc_object_release( host );
if( host == httpd.http )
httpd.http = NULL;
else if( host == httpd.https )
httpd.https = NULL;
else if( host == httpd.rtsp )
httpd.rtsp = NULL;
else
assert(0);
vlc_mutex_unlock( &httpd.mutex ); vlc_mutex_unlock( &httpd.mutex );
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment