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

httpd_ServerIP(): return server port too

parent 0af9a41a
......@@ -117,8 +117,8 @@ VLC_API void httpd_UrlDelete( httpd_url_t * );
/* Default client mode is FILE, use these to change it */
VLC_API void httpd_ClientModeStream( httpd_client_t *cl );
VLC_API void httpd_ClientModeBidir( httpd_client_t *cl );
VLC_API char* httpd_ClientIP( const httpd_client_t *cl, char *psz_ip );
VLC_API char* httpd_ServerIP( const httpd_client_t *cl, char *psz_ip );
VLC_API char* httpd_ClientIP( const httpd_client_t *cl, char *, int * );
VLC_API char* httpd_ServerIP( const httpd_client_t *cl, char *, int * );
/* High level */
......
......@@ -164,7 +164,6 @@ struct vod_sys_t
{
/* RTSP server */
httpd_host_t *p_rtsp_host;
int i_port;
int i_throttle_users;
int i_connections;
......@@ -271,8 +270,6 @@ static int Open( vlc_object_t *p_this )
goto error;
}
p_sys->i_port = 554;
TAB_INIT( p_sys->i_media, p_sys->media );
p_sys->i_media_id = 0;
......@@ -373,8 +370,8 @@ static vod_media_t *MediaNew( vod_t *p_vod, const char *psz_name,
msg_Dbg( p_vod, "created RTSP url: %s", p_media->psz_rtsp_path );
if( asprintf( &p_media->psz_rtsp_control_v4,
"rtsp://%%s:%d%s/trackID=%%d",
p_sys->i_port, p_media->psz_rtsp_path ) < 0 )
"rtsp://%%s:%%d%s/trackID=%%d",
p_media->psz_rtsp_path ) < 0 )
{
httpd_UrlDelete( p_media->p_rtsp_url );
free( p_media->psz_rtsp_path );
......@@ -382,8 +379,8 @@ static vod_media_t *MediaNew( vod_t *p_vod, const char *psz_name,
return NULL;
}
if( asprintf( &p_media->psz_rtsp_control_v6,
"rtsp://[%%s]:%d%s/trackID=%%d",
p_sys->i_port, p_media->psz_rtsp_path ) < 0 )
"rtsp://[%%s]:%%d%s/trackID=%%d",
p_media->psz_rtsp_path ) < 0 )
{
httpd_UrlDelete( p_media->p_rtsp_url );
free( p_media->psz_rtsp_path );
......@@ -402,6 +399,7 @@ static vod_media_t *MediaNew( vod_t *p_vod, const char *psz_name,
httpd_UrlCatch( p_media->p_rtsp_url, HTTPD_MSG_GETPARAMETER,
RtspCallback, (void*)p_media );
httpd_UrlCatch( p_media->p_rtsp_url, HTTPD_MSG_TEARDOWN,
RtspCallback, (void*)p_media );
p_media->p_vod = p_vod;
......@@ -965,7 +963,7 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
p_media->b_raw = true;
}
if( httpd_ClientIP( cl, ip ) == NULL )
if( httpd_ClientIP( cl, ip, NULL ) == NULL )
{
answer->i_status = 500;
answer->i_body = 0;
......@@ -1121,7 +1119,7 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
break;
}
if( httpd_ClientIP( cl, ip ) == NULL ) break;
if( httpd_ClientIP( cl, ip, NULL ) == NULL ) break;
p_rtsp->b_playing = true;
......@@ -1291,7 +1289,7 @@ static int RtspCallbackES( httpd_callback_sys_t *p_args, httpd_client_t *cl,
int i_port = atoi( strstr( psz_transport, "client_port=" ) +
strlen("client_port=") );
if( httpd_ClientIP( cl, ip ) == NULL )
if( httpd_ClientIP( cl, ip, NULL ) == NULL )
{
answer->i_status = 500;
answer->i_body = 0;
......@@ -1489,8 +1487,9 @@ static char *SDPGenerate( const vod_media_t *p_media, httpd_client_t *cl )
{
char *psz_sdp, ip[NI_MAXNUMERICHOST];
const char *psz_control;
int port;
if( httpd_ServerIP( cl, ip ) == NULL )
if( httpd_ServerIP( cl, ip, &port ) == NULL )
return NULL;
bool ipv6 = ( strchr( ip, ':' ) != NULL );
......@@ -1545,7 +1544,7 @@ static char *SDPGenerate( const vod_media_t *p_media, httpd_client_t *cl )
p_es->psz_ptname, p_es->i_clock_rate, p_es->i_channels,
p_es->psz_fmtp );
sdp_AddAttribute( &psz_sdp, "control", psz_control, ip, i );
sdp_AddAttribute( &psz_sdp, "control", psz_control, ip, port, i );
}
return psz_sdp;
......
......@@ -64,7 +64,6 @@ struct rtsp_stream_t
httpd_url_t *url;
char *psz_path;
unsigned track_id;
unsigned port;
int sessionc;
rtsp_session_t **sessionv;
......@@ -112,14 +111,14 @@ rtsp_stream_t *RtspSetup( vlc_object_t *owner, vod_media_t *media,
goto error;
}
rtsp->port = (url->i_port > 0) ? url->i_port : 554;
int port = (url->i_port > 0) ? url->i_port : 554;
rtsp->psz_path = strdup( ( url->psz_path != NULL ) ? url->psz_path : "/" );
if( rtsp->psz_path == NULL )
goto error;
msg_Dbg( owner, "RTSP stream: port %d at %s", rtsp->port, rtsp->psz_path );
msg_Dbg( owner, "RTSP stream: port %d at %s", port, rtsp->psz_path );
rtsp->host = vlc_rtsp_HostNew( VLC_OBJECT(owner), rtsp->port );
rtsp->host = vlc_rtsp_HostNew( VLC_OBJECT(owner), port );
if( rtsp->host == NULL )
goto error;
......@@ -617,18 +616,17 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
{
/* Build self-referential control URL */
char ip[NI_MAXNUMERICHOST], *ptr;
int port;
httpd_ServerIP( cl, ip );
httpd_ServerIP( cl, ip, &port );
ptr = strchr( ip, '%' );
if( ptr != NULL )
*ptr = '\0';
if( strchr( ip, ':' ) != NULL )
sprintf( control, "rtsp://[%s]:%u%s", ip, rtsp->port,
rtsp->psz_path );
sprintf( control, "rtsp://[%s]:%d%s", ip, port, rtsp->psz_path );
else
sprintf( control, "rtsp://%s:%u%s", ip, rtsp->port,
rtsp->psz_path );
sprintf( control, "rtsp://%s:%d%s", ip, port, rtsp->psz_path );
}
/* */
......@@ -809,7 +807,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
int fd, sport;
uint32_t ssrc;
if( httpd_ClientIP( cl, ip ) == NULL )
if( httpd_ClientIP( cl, ip, NULL ) == NULL )
{
answer->i_status = 500;
continue;
......@@ -902,7 +900,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
}
vlc_mutex_unlock( &rtsp->lock );
httpd_ServerIP( cl, ip );
httpd_ServerIP( cl, ip, NULL );
/* Specify source IP only if it is different from the
* RTSP control connection server address */
......
......@@ -32,9 +32,9 @@
#ifndef ENABLE_HTTPD
# include <vlc_httpd.h>
char *httpd_ClientIP (const httpd_client_t *cl, char *psz_ip)
char *httpd_ClientIP (const httpd_client_t *cl, char *psz_ip, int *port)
{
(void) cl; (void) psz_ip;
(void) cl; (void) psz_ip; (void) port
assert (0);
}
......@@ -137,9 +137,9 @@ httpd_redirect_t *httpd_RedirectNew (httpd_host_t *host,
assert (0);
}
char *httpd_ServerIP (const httpd_client_t *client, char *ip)
char *httpd_ServerIP (const httpd_client_t *client, char *ip, int *port)
{
(void) client; (void) ip;
(void) client; (void) ip; (void) port;
assert (0);
}
......
......@@ -533,7 +533,7 @@ httpd_HandlerCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *cl,
/* We do it ourselves, thanks */
answer->i_status = 0;
if( httpd_ClientIP( cl, psz_remote_addr ) == NULL )
if( httpd_ClientIP( cl, psz_remote_addr, NULL ) == NULL )
*psz_remote_addr = '\0';
uint8_t *psz_args = query->psz_args;
......@@ -1434,14 +1434,14 @@ void httpd_ClientModeBidir( httpd_client_t *cl )
cl->i_mode = HTTPD_CLIENT_BIDIR;
}
char* httpd_ClientIP( const httpd_client_t *cl, char *psz_ip )
char* httpd_ClientIP( const httpd_client_t *cl, char *ip, int *port )
{
return net_GetPeerAddress( cl->fd, psz_ip, NULL ) ? NULL : psz_ip;
return net_GetPeerAddress( cl->fd, ip, port ) ? NULL : ip;
}
char* httpd_ServerIP( const httpd_client_t *cl, char *psz_ip )
char* httpd_ServerIP( const httpd_client_t *cl, char *ip, int *port )
{
return net_GetSockAddress( cl->fd, psz_ip, NULL ) ? NULL : psz_ip;
return net_GetSockAddress( cl->fd, ip, port ) ? NULL : ip;
}
static void httpd_ClientClean( httpd_client_t *cl )
......@@ -2259,7 +2259,7 @@ static void* httpd_HostThread( void *data )
{
char ip[NI_MAXNUMERICHOST];
if( ( httpd_ClientIP( cl, ip ) == NULL )
if( ( httpd_ClientIP( cl, ip, NULL ) == NULL )
|| ACL_Check( url->p_acl, ip ) )
{
b_hosts_failed = true;
......
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