[vlc-commits] httpd_ServerIP(): return server port too
Rémi Denis-Courmont
git at videolan.org
Tue Aug 2 18:19:25 CEST 2011
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Aug 2 19:00:46 2011 +0300| [de8438c30213e0f29dee66738bd78391bdc0de02] | committer: Rémi Denis-Courmont
httpd_ServerIP(): return server port too
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=de8438c30213e0f29dee66738bd78391bdc0de02
---
include/vlc_httpd.h | 4 ++--
modules/misc/rtsp.c | 23 +++++++++++------------
modules/stream_out/rtsp.c | 20 +++++++++-----------
src/missing.c | 8 ++++----
src/network/httpd.c | 12 ++++++------
5 files changed, 32 insertions(+), 35 deletions(-)
diff --git a/include/vlc_httpd.h b/include/vlc_httpd.h
index 78bf51c..8818348 100644
--- a/include/vlc_httpd.h
+++ b/include/vlc_httpd.h
@@ -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 */
diff --git a/modules/misc/rtsp.c b/modules/misc/rtsp.c
index c7f6c4f..2c9f30b 100644
--- a/modules/misc/rtsp.c
+++ b/modules/misc/rtsp.c
@@ -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;
diff --git a/modules/stream_out/rtsp.c b/modules/stream_out/rtsp.c
index 733bc3a..c9ab534 100644
--- a/modules/stream_out/rtsp.c
+++ b/modules/stream_out/rtsp.c
@@ -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 */
diff --git a/src/missing.c b/src/missing.c
index faec56d..45439d5 100644
--- a/src/missing.c
+++ b/src/missing.c
@@ -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);
}
diff --git a/src/network/httpd.c b/src/network/httpd.c
index cb42be3..d5caf6a 100644
--- a/src/network/httpd.c
+++ b/src/network/httpd.c
@@ -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;
More information about the vlc-commits
mailing list