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