Commit 0af9a41a authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Factor HTTP/HTTPS/RTSP (bind) address in core

parent e5c2a63d
......@@ -99,9 +99,9 @@ struct httpd_message_t
};
/* create a new host */
VLC_API httpd_host_t *vlc_http_HostNew( vlc_object_t *, const char *psz_host, int i_port ) VLC_USED;
VLC_API httpd_host_t *vlc_https_HostNew( vlc_object_t *, const char *, int ) VLC_USED;
VLC_API httpd_host_t *vlc_rtsp_HostNew( vlc_object_t *, const char *, int ) VLC_USED;
VLC_API httpd_host_t *vlc_http_HostNew( vlc_object_t *, int ) VLC_USED;
VLC_API httpd_host_t *vlc_https_HostNew( vlc_object_t *, int ) VLC_USED;
VLC_API httpd_host_t *vlc_rtsp_HostNew( vlc_object_t *, int ) VLC_USED;
/* delete a host */
VLC_API void httpd_HostDelete( httpd_host_t * );
......
......@@ -94,13 +94,12 @@ int HTTPOpen( access_t *p_access )
sprintf( psz_tmp, ":%d", i_port + 1 );
config_PutPsz( p_access, "dvb-http-host", psz_tmp );
msg_Dbg( p_access, "base %s:%d", psz_address, i_port );
msg_Dbg( p_access, "base %d", i_port );
p_sys->p_httpd_host = vlc_http_HostNew( VLC_OBJECT(p_access), psz_address,
i_port );
p_sys->p_httpd_host = vlc_http_HostNew( VLC_OBJECT(p_access), i_port );
if ( p_sys->p_httpd_host == NULL )
{
msg_Err( p_access, "cannot listen on %s:%d", psz_address, i_port );
msg_Err( p_access, "cannot listen on port %d", i_port );
free( psz_address );
return VLC_EGENERIC;
}
......
......@@ -149,7 +149,7 @@ static int Open( vlc_object_t *p_this )
config_ChainParse( p_access, SOUT_CFG_PREFIX, ppsz_sout_options, p_access->p_cfg );
/* p_access->psz_path = "hostname:port/filename" */
/* p_access->psz_path = ":port/filename" */
psz_bind_addr = strdup( p_access->psz_path );
i_bind_port = 0;
......@@ -163,27 +163,13 @@ static int Open( vlc_object_t *p_this )
else
psz_file_name = strdup( "/" );
if( psz_bind_addr[0] == '[' )
{
psz_bind_addr++;
psz_parser = strstr( psz_bind_addr, "]:" );
if( psz_parser )
{
*psz_parser = '\0';
i_bind_port = atoi( psz_parser + 2 );
}
psz_parser = psz_bind_addr - 1;
}
else
psz_parser = strrchr( psz_bind_addr, ':' );
if( psz_parser )
{
psz_parser = strrchr( psz_bind_addr, ':' );
if( psz_parser )
{
*psz_parser = '\0';
i_bind_port = atoi( psz_parser + 1 );
}
psz_parser = psz_bind_addr;
*psz_parser = '\0';
i_bind_port = atoi( psz_parser + 1 );
}
psz_parser = psz_bind_addr;
/* TLS support */
if( p_access->psz_access && !strcmp( p_access->psz_access, "https" ) )
......@@ -191,14 +177,14 @@ static int Open( vlc_object_t *p_this )
if( i_bind_port <= 0 )
i_bind_port = DEFAULT_SSL_PORT;
p_sys->p_httpd_host = vlc_https_HostNew( VLC_OBJECT(p_access),
psz_bind_addr, i_bind_port );
i_bind_port );
}
else
{
if( i_bind_port <= 0 )
i_bind_port = DEFAULT_PORT;
p_sys->p_httpd_host = vlc_http_HostNew( VLC_OBJECT(p_access),
psz_bind_addr, i_bind_port );
i_bind_port );
}
if( p_sys->p_httpd_host == NULL )
......
......@@ -203,16 +203,8 @@ static int Start_LuaIntf( vlc_object_t *p_this, const char *name )
{
if( !strcmp( name, "http" ) )
{
char *psz_http_host = var_CreateGetNonEmptyString( p_intf, "http-host" );
char *psz_http_src = var_CreateGetNonEmptyString( p_intf, "http-src" );
bool b_http_index = var_CreateGetBool( p_intf, "http-index" );
if( psz_http_host )
{
char *psz_esc = config_StringEscape( psz_http_host );
asprintf( &psz_config, "http={host='%s'", psz_esc );
free( psz_esc );
free( psz_http_host );
}
if( psz_http_src )
{
char *psz_esc = config_StringEscape( psz_http_src );
......
......@@ -68,12 +68,10 @@ static const luaL_Reg vlclua_httpd_reg[] = {
static int vlclua_httpd_tls_host_new( lua_State *L )
{
vlc_object_t *p_this = vlclua_get_this( L );
const char *psz_host = luaL_checkstring( L, 1 );
int i_port = luaL_checkint( L, 2 );
httpd_host_t *p_host = vlc_http_HostNew( p_this, psz_host, i_port );
httpd_host_t *p_host = vlc_http_HostNew( p_this, i_port );
if( !p_host )
return luaL_error( L, "Failed to create HTTP host \"%s:%d\" ",
psz_host, i_port );
return luaL_error( L, "Failed to create HTTP port %d\" ", i_port );
httpd_host_t **pp_host = lua_newuserdata( L, sizeof( httpd_host_t * ) );
*pp_host = p_host;
......
......@@ -59,12 +59,6 @@
#define CONFIG_TEXT N_("Lua interface configuration")
#define CONFIG_LONGTEXT N_("Lua interface configuration string. Format is: '[\"<interface module name>\"] = { <option> = <value>, ...}, ...'.")
#define HOST_TEXT N_( "Host address" )
#define HOST_LONGTEXT N_( \
"Address and port the HTTP interface will listen on. It defaults to " \
"all network interfaces (0.0.0.0)." \
" If you want the HTTP interface to be available only on the local " \
"machine, enter 127.0.0.1" )
#define SRC_TEXT N_( "Source directory" )
#define SRC_LONGTEXT N_( "Source directory" )
#define INDEX_TEXT N_( "Directory index" )
......@@ -108,7 +102,6 @@ vlc_module_begin ()
add_submodule ()
set_section( N_("Lua HTTP"), 0 )
add_string ( "http-host", NULL, HOST_TEXT, HOST_LONGTEXT, true )
add_string ( "http-src", NULL, SRC_TEXT, SRC_LONGTEXT, true )
add_bool ( "http-index", false, INDEX_TEXT, INDEX_LONGTEXT, true )
set_capability( "interface", 0 )
......
......@@ -58,13 +58,6 @@
static int Open ( vlc_object_t * );
static void Close( vlc_object_t * );
#define HOST_TEXT N_( "RTSP host address" )
#define HOST_LONGTEXT N_( \
"This defines the address, port and path the RTSP VOD server will listen " \
"on.\nSyntax is address:port/path. The default is to listen on all "\
"interfaces (address 0.0.0.0), on port 554, with no path.\nTo listen " \
"only on the local interface, use \"localhost\" as address." )
#define THROTTLE_TEXT N_( "Maximum number of connections" )
#define THROTTLE_LONGTEXT N_( "This limits the maximum number of clients " \
"that can connect to the RTSP VOD. 0 means no limit." )
......@@ -86,7 +79,6 @@ vlc_module_begin ()
set_capability( "vod server", 1 )
set_callbacks( Open, Close )
add_shortcut( "rtsp" )
add_string ( "rtsp-host", NULL, HOST_TEXT, HOST_LONGTEXT, true )
add_string( "rtsp-raw-mux", "ts", RAWMUX_TEXT,
RAWMUX_TEXT, true )
add_integer( "rtsp-throttle-users", 0, THROTTLE_TEXT,
......@@ -172,7 +164,6 @@ struct vod_sys_t
{
/* RTSP server */
httpd_host_t *p_rtsp_host;
char *psz_path;
int i_port;
int i_throttle_users;
int i_connections;
......@@ -260,14 +251,6 @@ static int Open( vlc_object_t *p_this )
{
vod_t *p_vod = (vod_t *)p_this;
vod_sys_t *p_sys = NULL;
char *psz_url = NULL;
vlc_url_t url;
psz_url = var_InheritString( p_vod, "rtsp-host" );
vlc_UrlParse( &url, psz_url, 0 );
free( psz_url );
if( url.i_port <= 0 ) url.i_port = 554;
p_vod->p_sys = p_sys = malloc( sizeof( vod_sys_t ) );
if( !p_sys ) goto error;
......@@ -281,19 +264,14 @@ static int Open( vlc_object_t *p_this )
p_sys->psz_raw_mux = var_CreateGetString( p_this, "rtsp-raw-mux" );
p_sys->p_rtsp_host =
vlc_rtsp_HostNew( VLC_OBJECT(p_vod), url.psz_host, url.i_port );
p_sys->p_rtsp_host = vlc_rtsp_HostNew( VLC_OBJECT(p_vod), 554 );
if( !p_sys->p_rtsp_host )
{
msg_Err( p_vod, "cannot create RTSP server (%s:%i)",
url.psz_host, url.i_port );
msg_Err( p_vod, "cannot create RTSP server" );
goto error;
}
p_sys->psz_path = strdup( url.psz_path ? url.psz_path : "/" );
p_sys->i_port = url.i_port;
vlc_UrlClean( &url );
p_sys->i_port = 554;
TAB_INIT( p_sys->i_media, p_sys->media );
p_sys->i_media_id = 0;
......@@ -306,7 +284,6 @@ static int Open( vlc_object_t *p_this )
{
msg_Err( p_vod, "cannot spawn rtsp vod thread" );
block_FifoRelease( p_sys->p_fifo_cmd );
free( p_sys->psz_path );
goto error;
}
......@@ -319,8 +296,6 @@ error:
free( p_sys->psz_raw_mux );
free( p_sys );
}
vlc_UrlClean( &url );
return VLC_EGENERIC;
}
......@@ -359,7 +334,6 @@ static void Close( vlc_object_t * p_this )
msg_Err( p_vod, "rtsp vod leaking %d medias", p_sys->i_media );
TAB_CLEAN( p_sys->i_media, p_sys->media );
free( p_sys->psz_path );
free( p_sys->psz_raw_mux );
free( p_sys );
}
......@@ -382,16 +356,15 @@ static vod_media_t *MediaNew( vod_t *p_vod, const char *psz_name,
TAB_INIT( p_media->i_rtsp, p_media->rtsp );
p_media->b_raw = false;
if( asprintf( &p_media->psz_rtsp_path, "%s%s",
p_sys->psz_path, psz_name ) <0 )
return NULL;
p_media->psz_rtsp_path = strdup( psz_name );
p_media->p_rtsp_url =
httpd_UrlNewUnique( p_sys->p_rtsp_host, p_media->psz_rtsp_path, NULL,
NULL, NULL );
httpd_UrlNewUnique( p_sys->p_rtsp_host, psz_name, NULL, NULL, NULL );
if( !p_media->p_rtsp_url )
if( !p_media->psz_rtsp_path || !p_media->p_rtsp_url )
{
msg_Err( p_vod, "cannot create RTSP url (%s)", p_media->psz_rtsp_path);
msg_Err( p_vod, "cannot create RTSP url (%s)", psz_name );
if( p_media->p_rtsp_url )
httpd_UrlDelete( p_media->p_rtsp_url );
free( p_media->psz_rtsp_path );
free( p_media );
return NULL;
......
......@@ -1320,7 +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;
p_sys->p_httpd_host = vlc_http_HostNew( VLC_OBJECT(p_stream), url->psz_host,
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 )
{
......
......@@ -117,11 +117,9 @@ rtsp_stream_t *RtspSetup( vlc_object_t *owner, vod_media_t *media,
if( rtsp->psz_path == NULL )
goto error;
msg_Dbg( owner, "RTSP stream: host %s port %d at %s",
url->psz_host, rtsp->port, rtsp->psz_path );
msg_Dbg( owner, "RTSP stream: port %d at %s", rtsp->port, rtsp->psz_path );
rtsp->host = vlc_rtsp_HostNew( VLC_OBJECT(owner), url->psz_host,
rtsp->port );
rtsp->host = vlc_rtsp_HostNew( VLC_OBJECT(owner), rtsp->port );
if( rtsp->host == NULL )
goto error;
......
......@@ -889,6 +889,13 @@ static const char *const ppsz_clock_descriptions[] =
#define TIMEOUT_LONGTEXT N_( \
"Default TCP connection timeout (in milliseconds). " )
#define HTTP_HOST_TEXT N_( "HTTP server address" )
#define RTSP_HOST_TEXT N_( "RTSP server address" )
#define HOST_LONGTEXT N_( \
"By default, the server will listen on any local IP address. " \
"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." )
#define HTTP_CERT_TEXT N_("HTTP/TLS server certificate")
#define CERT_LONGTEXT N_( \
"This X.509 certicate file (PEM format) is used for server-side TLS." )
......@@ -1899,6 +1906,8 @@ vlc_module_begin ()
add_integer( "ipv4-timeout", 5 * 1000, TIMEOUT_TEXT,
TIMEOUT_LONGTEXT, true )
add_string( "http-host", NULL, HTTP_HOST_TEXT, HOST_LONGTEXT, true )
add_string( "rtsp-host", NULL, RTSP_HOST_TEXT, HOST_LONGTEXT, true )
add_loadfile( "http-cert", NULL, HTTP_CERT_TEXT, CERT_LONGTEXT, true )
add_deprecated_alias( "sout-http-cert" ) /* since 1.2.0 */
add_loadfile( "http-key", NULL, HTTP_KEY_TEXT, KEY_LONGTEXT, true )
......
......@@ -93,21 +93,21 @@ void httpd_HostDelete (httpd_host_t *h)
assert (0);
}
httpd_host_t *vlc_http_HostNew (vlc_object_t *obj, const char *host, int port)
httpd_host_t *vlc_http_HostNew (vlc_object_t *obj, int port)
{
(void) host; (void) port;
(void) port;
msg_Err (obj, "HTTP server not compiled-in!");
return NULL;
}
httpd_host_t *vlc_https_HostNew (vlc_object_t *obj, const char *host, int port)
httpd_host_t *vlc_https_HostNew (vlc_object_t *obj, int port)
{
return httpd_HostNew (obj, host, port);
return httpd_HostNew (obj, port);
}
httpd_host_t *vlc_rtsp_HostNew (vlc_object_t *obj, const char *host, int port)
httpd_host_t *vlc_rtsp_HostNew (vlc_object_t *obj, int port)
{
(void) host; (void) port;
(void) port;
msg_Err (obj, "RTSP server not compiled-in!");
return NULL;
}
......
......@@ -88,7 +88,6 @@ struct httpd_host_t
unsigned i_ref;
/* address/port and socket for listening at connections */
char *psz_hostname;
int i_port;
int *fds;
unsigned nfd;
......@@ -968,13 +967,12 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *, const char *, int,
vlc_tls_creds_t * );
/* create a new host */
httpd_host_t *vlc_http_HostNew( vlc_object_t *p_this, const char *psz_host,
int i_port )
httpd_host_t *vlc_http_HostNew( vlc_object_t *p_this, int i_port )
{
return httpd_HostCreate( p_this, psz_host, i_port, NULL );
return httpd_HostCreate( p_this, "http-host", i_port, NULL );
}
httpd_host_t *vlc_https_HostNew( vlc_object_t *obj, const char *host, int port )
httpd_host_t *vlc_https_HostNew( vlc_object_t *obj, int port )
{
char *cert = var_InheritString( obj, "http-cert" );
if( cert == NULL )
......@@ -1021,37 +1019,28 @@ httpd_host_t *vlc_https_HostNew( vlc_object_t *obj, const char *host, int port )
free( crl );
}
return httpd_HostCreate( obj, host, port, tls );
return httpd_HostCreate( obj, "http-host", port, tls );
error:
vlc_tls_ServerDelete( tls );
return NULL;
}
httpd_host_t *vlc_rtsp_HostNew( vlc_object_t *p_this, const char *psz_host,
int i_port )
httpd_host_t *vlc_rtsp_HostNew( vlc_object_t *p_this, int i_port )
{
return httpd_HostCreate( p_this, psz_host, i_port, NULL );
return httpd_HostCreate( p_this, "rtsp-host", i_port, NULL );
}
static vlc_mutex_t httpd_mutex = VLC_STATIC_MUTEX;
static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
const char *psz_hostname, int i_port,
const char *hostvar, int i_port,
vlc_tls_creds_t *p_tls )
{
httpd_t *httpd;
httpd_host_t *host;
char *psz_host;
int i;
if( psz_hostname == NULL )
psz_hostname = "";
psz_host = strdup( psz_hostname );
if( psz_host == NULL )
return NULL;
/* to be sure to avoid multiple creation */
vlc_mutex_lock( &httpd_mutex );
httpd = libvlc_priv (p_this->p_libvlc)->p_httpd;
......@@ -1064,7 +1053,6 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
if( httpd == NULL )
{
vlc_mutex_unlock( &httpd_mutex );
free( psz_host );
return NULL;
}
......@@ -1081,8 +1069,7 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
/* cannot mix TLS and non-TLS hosts */
if( ( ( httpd->host[i]->p_tls != NULL ) != ( p_tls != NULL ) )
|| ( host->i_port != i_port )
|| strcmp( host->psz_hostname, psz_hostname ) )
|| ( host->i_port != i_port ) )
continue;
/* Increase existing matching host reference count.
......@@ -1112,7 +1099,9 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
vlc_cond_init( &host->wait );
host->i_ref = 1;
host->fds = net_ListenTCP( p_this, psz_host, i_port );
char *hostname = var_InheritString( p_this->p_libvlc, hostvar );
host->fds = net_ListenTCP( p_this, hostname, i_port );
free( hostname );
if( host->fds == NULL )
{
msg_Err( p_this, "cannot create socket(s) for HTTP host" );
......@@ -1127,8 +1116,6 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
}
host->i_port = i_port;
host->psz_hostname = psz_host;
host->i_url = 0;
host->url = NULL;
host->i_client = 0;
......@@ -1151,7 +1138,6 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
return host;
error:
free( psz_host );
if( httpd->i_host <= 0 )
{
libvlc_priv (httpd->p_libvlc)->p_httpd = NULL;
......@@ -1223,8 +1209,6 @@ void httpd_HostDelete( httpd_host_t *host )
vlc_tls_ServerDelete( host->p_tls );
net_ListenClose( host->fds );
free( host->psz_hostname );
vlc_cond_destroy( &host->wait );
vlc_mutex_destroy( &host->lock );
vlc_object_release( 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