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

- Add httpd_ServerIP() to obtain HTTP server's IP used with a given client

(much like httpd_ClientIP())
- Rewrite httpd_ClientIP() to use existing API and not use malloc/free
parent 7a8c3950
......@@ -131,7 +131,8 @@ VLC_EXPORT( void, httpd_UrlDelete, ( httpd_url_t * ) );
/* Default client mode is FILE, use these to change it */
VLC_EXPORT( void, httpd_ClientModeStream, ( httpd_client_t *cl ) );
VLC_EXPORT( void, httpd_ClientModeBidir, ( httpd_client_t *cl ) );
VLC_EXPORT( char*, httpd_ClientIP, ( httpd_client_t *cl ) );
VLC_EXPORT( char*, httpd_ClientIP, ( httpd_client_t *cl, char *psz_ip ) );
VLC_EXPORT( char*, httpd_ServerIP, ( httpd_client_t *cl, char *psz_ip ) );
/* High level */
......
......@@ -201,7 +201,7 @@ struct module_symbols_t
void (*httpd_UrlDelete_inner) (httpd_url_t *);
void (*httpd_ClientModeStream_inner) (httpd_client_t *cl);
void (*httpd_ClientModeBidir_inner) (httpd_client_t *cl);
char* (*httpd_ClientIP_inner) (httpd_client_t *cl);
char* (*httpd_ClientIP_inner) (httpd_client_t *cl, char *psz_ip);
httpd_file_t * (*httpd_FileNew_inner) (httpd_host_t *, char *psz_url, char *psz_mime, char *psz_user, char *psz_password, const vlc_acl_t *p_acl, httpd_file_callback_t pf_fill, httpd_file_sys_t *);
void (*httpd_FileDelete_inner) (httpd_file_t *);
httpd_redirect_t * (*httpd_RedirectNew_inner) (httpd_host_t *, char *psz_url_dst, char *psz_url_src);
......@@ -382,6 +382,7 @@ struct module_symbols_t
int (*ACL_LoadFile_inner) (vlc_acl_t *p_acl, const char *path);
int (*ACL_AddNet_inner) (vlc_acl_t *p_acl, const char *psz_ip, int i_len, vlc_bool_t b_allow);
void (*ACL_Destroy_inner) (vlc_acl_t *p_acl);
char* (*httpd_ServerIP_inner) (httpd_client_t *cl, char *psz_ip);
};
# if defined (__PLUGIN__)
# define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner
......@@ -749,6 +750,7 @@ struct module_symbols_t
# define ACL_LoadFile (p_symbols)->ACL_LoadFile_inner
# define ACL_AddNet (p_symbols)->ACL_AddNet_inner
# define ACL_Destroy (p_symbols)->ACL_Destroy_inner
# define httpd_ServerIP (p_symbols)->httpd_ServerIP_inner
# elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)
/******************************************************************
* STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access.
......@@ -1119,6 +1121,7 @@ struct module_symbols_t
((p_symbols)->ACL_LoadFile_inner) = ACL_LoadFile; \
((p_symbols)->ACL_AddNet_inner) = ACL_AddNet; \
((p_symbols)->ACL_Destroy_inner) = ACL_Destroy; \
((p_symbols)->httpd_ServerIP_inner) = httpd_ServerIP; \
(p_symbols)->net_ConvertIPv4_deprecated = NULL; \
# endif /* __PLUGIN__ */
......
......@@ -171,7 +171,7 @@ static int RtspCallback( httpd_callback_sys_t *, httpd_client_t *,
static int RtspCallbackES( httpd_callback_sys_t *, httpd_client_t *,
httpd_message_t *, httpd_message_t * );
static char *SDPGenerate( const vod_media_t * );
static char *SDPGenerate( const vod_media_t *, httpd_client_t *cl );
static void sprintf_hexa( char *s, uint8_t *p_data, int i_data )
{
......@@ -623,7 +623,7 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
case HTTPD_MSG_DESCRIBE:
{
char *psz_sdp =
SDPGenerate( p_media );
SDPGenerate( p_media, cl );
answer->i_status = 200;
answer->psz_status = strdup( "OK" );
......@@ -636,7 +636,7 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
case HTTPD_MSG_PLAY:
{
char *psz_output, *ip;
char *psz_output, ip[NI_MAXNUMERICHOST];
int i, i_port_audio = 0, i_port_video = 0;
/* for now only multicast so easy */
......@@ -660,7 +660,7 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
}
else if( p_rtsp->b_playing ) break;
if( !(ip = httpd_ClientIP( cl )) ) break;
if( httpd_ClientIP( cl, ip ) == NULL ) break;
p_rtsp->b_playing = VLC_TRUE;
......@@ -687,7 +687,6 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
vod_MediaControl( p_vod, p_media, psz_session, VOD_MEDIA_PLAY,
psz_output );
free( psz_output );
free( ip );
break;
}
......@@ -773,11 +772,11 @@ static int RtspCallbackES( httpd_callback_sys_t *p_args, httpd_client_t *cl,
{
rtsp_client_t *p_rtsp;
rtsp_client_es_t *p_rtsp_es;
char *ip = httpd_ClientIP( cl );
char ip[NI_MAXNUMERICHOST];
int i_port = atoi( strstr( psz_transport, "client_port=" ) +
strlen("client_port=") );
if( !ip )
if( httpd_ClientIP( cl, ip ) == NULL )
{
answer->i_status = 500;
answer->psz_status = strdup( "Internal server error" );
......@@ -935,10 +934,10 @@ static int RtspCallbackES( httpd_callback_sys_t *p_args, httpd_client_t *cl,
* SDPGenerate: TODO
* FIXME: need to be moved to a common place ?
*****************************************************************************/
static char *SDPGenerate( const vod_media_t *p_media )
static char *SDPGenerate( const vod_media_t *p_media, httpd_client_t *cl )
{
int i, i_size;
char *p, *psz_sdp;
char *p, *psz_sdp, *ip;
/* Calculate size */
i_size = strlen( "v=0\r\n" ) +
......
......@@ -1641,7 +1641,7 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args,
else if( strstr( psz_transport, "unicast" ) && strstr( psz_transport, "client_port=" ) )
{
int i_port = atoi( strstr( psz_transport, "client_port=" ) + strlen("client_port=") );
char *ip = httpd_ClientIP( cl );
char ip[NI_MAXNUMERICHOST];
char psz_access[100];
char psz_url[100];
......@@ -1650,7 +1650,7 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args,
rtsp_client_t *rtsp = NULL;
if( ip == NULL )
if( httpd_ClientIP( cl, ip ) == NULL )
{
answer->i_status = 500;
answer->psz_status = strdup( "Internal server error" );
......@@ -1679,7 +1679,6 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args,
answer->psz_status = strdup( "Unknown session id" );
answer->i_body = 0;
answer->p_body = NULL;
free( ip );
break;
}
}
......@@ -1690,8 +1689,7 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args,
else
sprintf( psz_access, "udp{raw}" );
sprintf( psz_url, "%s:%d", ip, i_port );
free( ip );
if( ( p_access = sout_AccessOutNew( p_stream->p_sout, psz_access, psz_url ) ) == NULL )
{
msg_Err( p_stream, "cannot create the access out for %s://%s",
......
......@@ -1329,20 +1329,14 @@ void httpd_ClientModeBidir( httpd_client_t *cl )
cl->i_mode = HTTPD_CLIENT_BIDIR;
}
char* httpd_ClientIP( httpd_client_t *cl )
char* httpd_ClientIP( httpd_client_t *cl, char *psz_ip )
{
int i;
char *psz_ip = malloc( NI_MAXNUMERICHOST );
if( psz_ip == NULL )
return NULL;
i = vlc_getnameinfo( (const struct sockaddr *)&cl->sock, cl->i_sock_size,
psz_ip, NI_MAXNUMERICHOST, NULL, NI_NUMERICHOST );
if( i )
return NULL;
return net_GetPeerAddress( cl->fd, psz_ip, NULL ) ? NULL : psz_ip;
}
return psz_ip;
char* httpd_ServerIP( httpd_client_t *cl, char *psz_ip )
{
return net_GetSockAddress( cl->fd, psz_ip, NULL ) ? NULL : psz_ip;
}
static void httpd_ClientClean( httpd_client_t *cl )
......
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