Commit 7656b8c5 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Factor HTTP/HTTPS/RTSP port in core

parent de8438c3
...@@ -99,9 +99,9 @@ struct httpd_message_t ...@@ -99,9 +99,9 @@ struct httpd_message_t
}; };
/* create a new host */ /* create a new host */
VLC_API httpd_host_t *vlc_http_HostNew( vlc_object_t *, int ) VLC_USED; VLC_API httpd_host_t *vlc_http_HostNew( vlc_object_t * ) VLC_USED;
VLC_API httpd_host_t *vlc_https_HostNew( vlc_object_t *, int ) VLC_USED; VLC_API httpd_host_t *vlc_https_HostNew( vlc_object_t * ) VLC_USED;
VLC_API httpd_host_t *vlc_rtsp_HostNew( vlc_object_t *, int ) VLC_USED; VLC_API httpd_host_t *vlc_rtsp_HostNew( vlc_object_t * ) VLC_USED;
/* delete a host */ /* delete a host */
VLC_API void httpd_HostDelete( httpd_host_t * ); VLC_API void httpd_HostDelete( httpd_host_t * );
......
...@@ -64,8 +64,7 @@ static int HttpCallback( httpd_file_sys_t *p_args, ...@@ -64,8 +64,7 @@ static int HttpCallback( httpd_file_sys_t *p_args,
int HTTPOpen( access_t *p_access ) int HTTPOpen( access_t *p_access )
{ {
access_sys_t *p_sys = p_access->p_sys; access_sys_t *p_sys = p_access->p_sys;
char *psz_address, *psz_user = NULL, *psz_password = NULL; char *psz_user = NULL, *psz_password = NULL;
int i_port = 0;
char psz_tmp[10]; char psz_tmp[10];
httpd_file_sys_t *f; httpd_file_sys_t *f;
...@@ -74,33 +73,9 @@ int HTTPOpen( access_t *p_access ) ...@@ -74,33 +73,9 @@ int HTTPOpen( access_t *p_access )
p_sys->b_request_frontend_info = p_sys->b_request_mmi_info = false; p_sys->b_request_frontend_info = p_sys->b_request_mmi_info = false;
p_sys->i_httpd_timeout = 0; p_sys->i_httpd_timeout = 0;
psz_address = var_GetNonEmptyString( p_access, "dvb-http-host" ); p_sys->p_httpd_host = vlc_http_HostNew( VLC_OBJECT(p_access) );
if( psz_address != NULL )
{
char *psz_parser = strchr( psz_address, ':' );
if( psz_parser )
{
*psz_parser++ = '\0';
i_port = atoi( psz_parser );
}
}
else
return VLC_SUCCESS;
if ( i_port <= 0 )
i_port= 8082;
/* Ugly hack to allow to run several HTTP servers on different ports. */
sprintf( psz_tmp, ":%d", i_port + 1 );
config_PutPsz( p_access, "dvb-http-host", psz_tmp );
msg_Dbg( p_access, "base %d", i_port );
p_sys->p_httpd_host = vlc_http_HostNew( VLC_OBJECT(p_access), i_port );
if ( p_sys->p_httpd_host == NULL ) if ( p_sys->p_httpd_host == NULL )
{ {
msg_Err( p_access, "cannot listen on port %d", i_port );
free( psz_address );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
free( psz_address ); free( psz_address );
......
...@@ -134,10 +134,6 @@ static int Open( vlc_object_t *p_this ) ...@@ -134,10 +134,6 @@ static int Open( vlc_object_t *p_this )
sout_access_out_t *p_access = (sout_access_out_t*)p_this; sout_access_out_t *p_access = (sout_access_out_t*)p_this;
sout_access_out_sys_t *p_sys; sout_access_out_sys_t *p_sys;
char *psz_parser;
char *psz_bind_addr;
int i_bind_port;
char *psz_file_name; char *psz_file_name;
char *psz_user; char *psz_user;
char *psz_pwd; char *psz_pwd;
...@@ -149,54 +145,26 @@ static int Open( vlc_object_t *p_this ) ...@@ -149,54 +145,26 @@ static int Open( vlc_object_t *p_this )
config_ChainParse( p_access, SOUT_CFG_PREFIX, ppsz_sout_options, p_access->p_cfg ); config_ChainParse( p_access, SOUT_CFG_PREFIX, ppsz_sout_options, p_access->p_cfg );
/* p_access->psz_path = ":port/filename" */ /* Skip everything before / - backward compatibiltiy with VLC 1.1 */
psz_bind_addr = strdup( p_access->psz_path ); const char *psz_parser = strchr( p_access->psz_path, '/' );
i_bind_port = 0;
psz_parser = strchr( psz_bind_addr, '/' );
if( psz_parser ) if( psz_parser )
{
psz_file_name = strdup( psz_parser ); psz_file_name = strdup( psz_parser );
*psz_parser = '\0';
}
else else
psz_file_name = strdup( "/" ); psz_file_name = strdup( "/" );
psz_parser = strrchr( psz_bind_addr, ':' );
if( psz_parser )
{
*psz_parser = '\0';
i_bind_port = atoi( psz_parser + 1 );
}
psz_parser = psz_bind_addr;
/* TLS support */ /* TLS support */
if( p_access->psz_access && !strcmp( p_access->psz_access, "https" ) ) if( p_access->psz_access && !strcmp( p_access->psz_access, "https" ) )
{ p_sys->p_httpd_host = vlc_https_HostNew( VLC_OBJECT(p_access) );
if( i_bind_port <= 0 )
i_bind_port = DEFAULT_SSL_PORT;
p_sys->p_httpd_host = vlc_https_HostNew( VLC_OBJECT(p_access),
i_bind_port );
}
else else
{ p_sys->p_httpd_host = vlc_http_HostNew( VLC_OBJECT(p_access) );
if( i_bind_port <= 0 )
i_bind_port = DEFAULT_PORT;
p_sys->p_httpd_host = vlc_http_HostNew( VLC_OBJECT(p_access),
i_bind_port );
}
if( p_sys->p_httpd_host == NULL ) if( p_sys->p_httpd_host == NULL )
{ {
msg_Err( p_access, "cannot listen on %s port %d", msg_Err( p_access, "cannot start HTTP server" );
psz_bind_addr, i_bind_port );
free( psz_file_name ); free( psz_file_name );
free( psz_parser );
free( p_sys ); free( p_sys );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
free( psz_parser );
psz_user = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "user" ); psz_user = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "user" );
psz_pwd = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "pwd" ); psz_pwd = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "pwd" );
......
...@@ -68,10 +68,9 @@ static const luaL_Reg vlclua_httpd_reg[] = { ...@@ -68,10 +68,9 @@ static const luaL_Reg vlclua_httpd_reg[] = {
static int vlclua_httpd_tls_host_new( lua_State *L ) static int vlclua_httpd_tls_host_new( lua_State *L )
{ {
vlc_object_t *p_this = vlclua_get_this( L ); vlc_object_t *p_this = vlclua_get_this( L );
int i_port = luaL_checkint( L, 2 ); httpd_host_t *p_host = vlc_http_HostNew( p_this );
httpd_host_t *p_host = vlc_http_HostNew( p_this, i_port );
if( !p_host ) if( !p_host )
return luaL_error( L, "Failed to create HTTP port %d\" ", i_port ); return luaL_error( L, "Failed to create HTTP host" );
httpd_host_t **pp_host = lua_newuserdata( L, sizeof( httpd_host_t * ) ); httpd_host_t **pp_host = lua_newuserdata( L, sizeof( httpd_host_t * ) );
*pp_host = p_host; *pp_host = p_host;
......
...@@ -263,7 +263,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -263,7 +263,7 @@ static int Open( vlc_object_t *p_this )
p_sys->psz_raw_mux = var_CreateGetString( p_this, "rtsp-raw-mux" ); p_sys->psz_raw_mux = var_CreateGetString( p_this, "rtsp-raw-mux" );
p_sys->p_rtsp_host = vlc_rtsp_HostNew( VLC_OBJECT(p_vod), 554 ); p_sys->p_rtsp_host = vlc_rtsp_HostNew( VLC_OBJECT(p_vod) );
if( !p_sys->p_rtsp_host ) if( !p_sys->p_rtsp_host )
{ {
msg_Err( p_vod, "cannot create RTSP server" ); msg_Err( p_vod, "cannot create RTSP server" );
......
...@@ -1320,8 +1320,7 @@ static int HttpSetup( sout_stream_t *p_stream, const vlc_url_t *url) ...@@ -1320,8 +1320,7 @@ static int HttpSetup( sout_stream_t *p_stream, const vlc_url_t *url)
{ {
sout_stream_sys_t *p_sys = p_stream->p_sys; sout_stream_sys_t *p_sys = p_stream->p_sys;
p_sys->p_httpd_host = vlc_http_HostNew( VLC_OBJECT(p_stream), p_sys->p_httpd_host = vlc_http_HostNew( VLC_OBJECT(p_stream) );
url->i_port > 0 ? url->i_port : 80 );
if( p_sys->p_httpd_host ) if( p_sys->p_httpd_host )
{ {
p_sys->p_httpd_file = httpd_FileNew( p_sys->p_httpd_host, p_sys->p_httpd_file = httpd_FileNew( p_sys->p_httpd_host,
......
...@@ -111,14 +111,13 @@ rtsp_stream_t *RtspSetup( vlc_object_t *owner, vod_media_t *media, ...@@ -111,14 +111,13 @@ rtsp_stream_t *RtspSetup( vlc_object_t *owner, vod_media_t *media,
goto error; goto error;
} }
int port = (url->i_port > 0) ? url->i_port : 554;
rtsp->psz_path = strdup( ( url->psz_path != NULL ) ? url->psz_path : "/" ); rtsp->psz_path = strdup( ( url->psz_path != NULL ) ? url->psz_path : "/" );
if( rtsp->psz_path == NULL ) if( rtsp->psz_path == NULL )
goto error; goto error;
msg_Dbg( owner, "RTSP stream: port %d at %s", port, rtsp->psz_path ); msg_Dbg( owner, "RTSP stream at %s", rtsp->psz_path );
rtsp->host = vlc_rtsp_HostNew( VLC_OBJECT(owner), port ); rtsp->host = vlc_rtsp_HostNew( VLC_OBJECT(owner) );
if( rtsp->host == NULL ) if( rtsp->host == NULL )
goto error; goto error;
......
...@@ -896,6 +896,27 @@ static const char *const ppsz_clock_descriptions[] = ...@@ -896,6 +896,27 @@ static const char *const ppsz_clock_descriptions[] =
"Specify an IP address (e.g. ::1 or 127.0.0.1) or a host name " \ "Specify an IP address (e.g. ::1 or 127.0.0.1) or a host name " \
"(e.g. localhost) to restrict them to a specific network interface." ) "(e.g. localhost) to restrict them to a specific network interface." )
#define HTTP_PORT_TEXT N_( "HTTP server port" )
#define HTTP_PORT_LONGTEXT N_( \
"The HTTP server will listen on this TCP port. " \
"The standard HTTP port number is 80. " \
"However allocation of port numbers below 1025 is usually restricted " \
"by the operating system." )
#define HTTPS_PORT_TEXT N_( "HTTPS server port" )
#define HTTPS_PORT_LONGTEXT N_( \
"The HTTPS server will listen on this TCP port. " \
"The standard HTTPS port number is 443. " \
"However allocation of port numbers below 1025 is usually restricted " \
"by the operating system." )
#define RTSP_PORT_TEXT N_( "RTSP server port" )
#define RTSP_PORT_LONGTEXT N_( \
"The HTTPS server will listen on this TCP port. " \
"The standard RTSP port number is 554. " \
"However allocation of port numbers below 1025 is usually restricted " \
"by the operating system." )
#define HTTP_CERT_TEXT N_("HTTP/TLS server certificate") #define HTTP_CERT_TEXT N_("HTTP/TLS server certificate")
#define CERT_LONGTEXT N_( \ #define CERT_LONGTEXT N_( \
"This X.509 certicate file (PEM format) is used for server-side TLS." ) "This X.509 certicate file (PEM format) is used for server-side TLS." )
...@@ -1907,7 +1928,13 @@ vlc_module_begin () ...@@ -1907,7 +1928,13 @@ vlc_module_begin ()
TIMEOUT_LONGTEXT, true ) TIMEOUT_LONGTEXT, true )
add_string( "http-host", NULL, HTTP_HOST_TEXT, HOST_LONGTEXT, true ) add_string( "http-host", NULL, HTTP_HOST_TEXT, HOST_LONGTEXT, true )
add_integer( "http-port", 8080, HTTP_PORT_TEXT, HTTP_PORT_LONGTEXT, true )
change_integer_range( 1, 65535 )
add_integer( "https-port", 8443, HTTPS_PORT_TEXT, HTTPS_PORT_LONGTEXT, true )
change_integer_range( 1, 65535 )
add_string( "rtsp-host", NULL, RTSP_HOST_TEXT, HOST_LONGTEXT, true ) add_string( "rtsp-host", NULL, RTSP_HOST_TEXT, HOST_LONGTEXT, true )
add_integer( "rtsp-port", 5554, RTSP_PORT_TEXT, RTSP_PORT_LONGTEXT, true )
change_integer_range( 1, 65535 )
add_loadfile( "http-cert", NULL, HTTP_CERT_TEXT, CERT_LONGTEXT, true ) add_loadfile( "http-cert", NULL, HTTP_CERT_TEXT, CERT_LONGTEXT, true )
add_deprecated_alias( "sout-http-cert" ) /* since 1.2.0 */ add_deprecated_alias( "sout-http-cert" ) /* since 1.2.0 */
add_loadfile( "http-key", NULL, HTTP_KEY_TEXT, KEY_LONGTEXT, true ) add_loadfile( "http-key", NULL, HTTP_KEY_TEXT, KEY_LONGTEXT, true )
......
...@@ -93,21 +93,20 @@ void httpd_HostDelete (httpd_host_t *h) ...@@ -93,21 +93,20 @@ void httpd_HostDelete (httpd_host_t *h)
assert (0); assert (0);
} }
httpd_host_t *vlc_http_HostNew (vlc_object_t *obj, int port) httpd_host_t *vlc_http_HostNew (vlc_object_t *obj)
{ {
(void) port;
msg_Err (obj, "HTTP server not compiled-in!"); msg_Err (obj, "HTTP server not compiled-in!");
return NULL; return NULL;
} }
httpd_host_t *vlc_https_HostNew (vlc_object_t *obj, int port) httpd_host_t *vlc_https_HostNew (vlc_object_t *obj)
{ {
return httpd_HostNew (obj, port); msg_Err (obj, "HTTPS server not compiled-in!");
return NULL;
} }
httpd_host_t *vlc_rtsp_HostNew (vlc_object_t *obj, int port) httpd_host_t *vlc_rtsp_HostNew (vlc_object_t *obj)
{ {
(void) port;
msg_Err (obj, "RTSP server not compiled-in!"); msg_Err (obj, "RTSP server not compiled-in!");
return NULL; return NULL;
} }
......
...@@ -88,7 +88,6 @@ struct httpd_host_t ...@@ -88,7 +88,6 @@ struct httpd_host_t
unsigned i_ref; unsigned i_ref;
/* address/port and socket for listening at connections */ /* address/port and socket for listening at connections */
int i_port;
int *fds; int *fds;
unsigned nfd; unsigned nfd;
...@@ -963,16 +962,16 @@ void httpd_StreamDelete( httpd_stream_t *stream ) ...@@ -963,16 +962,16 @@ 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 *, const char *, int, static httpd_host_t *httpd_HostCreate( vlc_object_t *, const char *,
vlc_tls_creds_t * ); const char *, vlc_tls_creds_t * );
/* create a new host */ /* create a new host */
httpd_host_t *vlc_http_HostNew( vlc_object_t *p_this, int i_port ) httpd_host_t *vlc_http_HostNew( vlc_object_t *p_this )
{ {
return httpd_HostCreate( p_this, "http-host", i_port, NULL ); return httpd_HostCreate( p_this, "http-host", "http-port", NULL );
} }
httpd_host_t *vlc_https_HostNew( vlc_object_t *obj, int port ) httpd_host_t *vlc_https_HostNew( vlc_object_t *obj )
{ {
char *cert = var_InheritString( obj, "http-cert" ); char *cert = var_InheritString( obj, "http-cert" );
if( cert == NULL ) if( cert == NULL )
...@@ -1019,22 +1018,23 @@ httpd_host_t *vlc_https_HostNew( vlc_object_t *obj, int port ) ...@@ -1019,22 +1018,23 @@ httpd_host_t *vlc_https_HostNew( vlc_object_t *obj, int port )
free( crl ); free( crl );
} }
return httpd_HostCreate( obj, "http-host", port, tls ); return httpd_HostCreate( obj, "http-host", "https-port", tls );
error: error:
vlc_tls_ServerDelete( tls ); vlc_tls_ServerDelete( tls );
return NULL; return NULL;
} }
httpd_host_t *vlc_rtsp_HostNew( vlc_object_t *p_this, int i_port ) httpd_host_t *vlc_rtsp_HostNew( vlc_object_t *p_this )
{ {
return httpd_HostCreate( p_this, "rtsp-host", i_port, NULL ); return httpd_HostCreate( p_this, "rtsp-host", "rtsp-port", NULL );
} }
static vlc_mutex_t httpd_mutex = VLC_STATIC_MUTEX; static vlc_mutex_t httpd_mutex = VLC_STATIC_MUTEX;
static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this, static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
const char *hostvar, int i_port, const char *hostvar,
const char *portvar,
vlc_tls_creds_t *p_tls ) vlc_tls_creds_t *p_tls )
{ {
httpd_t *httpd; httpd_t *httpd;
...@@ -1068,8 +1068,7 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this, ...@@ -1068,8 +1068,7 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
host = httpd->host[i]; host = httpd->host[i];
/* cannot mix TLS and non-TLS hosts */ /* cannot mix TLS and non-TLS hosts */
if( ( ( httpd->host[i]->p_tls != NULL ) != ( p_tls != NULL ) ) if( ( httpd->host[i]->p_tls != NULL ) != ( p_tls != NULL ) )
|| ( host->i_port != i_port ) )
continue; continue;
/* Increase existing matching host reference count. /* Increase existing matching host reference count.
...@@ -1100,7 +1099,8 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this, ...@@ -1100,7 +1099,8 @@ 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->p_libvlc, hostvar ); char *hostname = var_InheritString( p_this->p_libvlc, hostvar );
host->fds = net_ListenTCP( p_this, hostname, i_port ); int port = var_InheritInteger( p_this->p_libvlc, portvar );
host->fds = net_ListenTCP( p_this, hostname, port );
free( hostname ); free( hostname );
if( host->fds == NULL ) if( host->fds == NULL )
{ {
...@@ -1115,13 +1115,11 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this, ...@@ -1115,13 +1115,11 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
goto error; goto error;
} }
host->i_port = i_port; host->i_url = 0;
host->i_url = 0; host->url = NULL;
host->url = NULL; host->i_client = 0;
host->i_client = 0; host->client = NULL;
host->client = NULL; host->p_tls = p_tls;
host->p_tls = p_tls;
/* create the thread */ /* create the thread */
if( vlc_clone( &host->thread, httpd_HostThread, host, if( vlc_clone( &host->thread, httpd_HostThread, host,
......
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