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

Fixes httpd_ClientIP on Win32 & the likes

parent 22571f1a
......@@ -422,7 +422,7 @@ struct addrinfo
# endif
VLC_EXPORT( const char *, vlc_gai_strerror, ( int ) );
VLC_EXPORT( int, vlc_getnameinfo, ( vlc_object_t *, const struct sockaddr *, int, char *, int, int *, int ) );
VLC_EXPORT( int, vlc_getnameinfo, ( const struct sockaddr *, int, char *, int, int *, int ) );
VLC_EXPORT( int, vlc_getaddrinfo, ( vlc_object_t *, const char *, int, const struct addrinfo *, struct addrinfo ** ) );
VLC_EXPORT( void, vlc_freeaddrinfo, ( struct addrinfo * ) );
......
......@@ -367,7 +367,7 @@ struct module_symbols_t
mtime_t (*vout_SynchroDate_inner) (vout_synchro_t *);
void (*vout_SynchroNewPicture_inner) (vout_synchro_t *, int, int, mtime_t, mtime_t, int, vlc_bool_t);
int (*vlc_getaddrinfo_inner) (vlc_object_t *, const char *, int, const struct addrinfo *, struct addrinfo **);
int (*vlc_getnameinfo_inner) (vlc_object_t *, const struct sockaddr *, int, char *, int, int *, int);
int (*vlc_getnameinfo_inner) (const struct sockaddr *, int, char *, int, int *, int);
void (*InitMD5_inner) (struct md5_s *);
void (*EndMD5_inner) (struct md5_s *);
void (*vlc_freeaddrinfo_inner) (struct addrinfo *);
......
......@@ -250,9 +250,8 @@ static int Open( vlc_object_t *p_this )
goto exit_error;
}
i_answer = vlc_getnameinfo( p_this, (struct sockaddr *)&addr, len,
hostaddr, sizeof( hostaddr ), NULL,
NI_NUMERICHOST );
i_answer = vlc_getnameinfo( (struct sockaddr *)&addr, len, hostaddr,
sizeof( hostaddr ), NULL, NI_NUMERICHOST );
if( i_answer )
{
msg_Err( p_access, "getnameinfo failed: %s",
......
......@@ -493,7 +493,7 @@ __getaddrinfo (const char *node, const char *service,
#endif /* if !HAVE_GETADDRINFO */
int vlc_getnameinfo( vlc_object_t *p_this, const struct sockaddr *sa, int salen,
int vlc_getnameinfo( const struct sockaddr *sa, int salen,
char *host, int hostlen, int *portnum, int flags )
{
char psz_servbuf[6], *psz_serv;
......@@ -545,17 +545,20 @@ int vlc_getnameinfo( vlc_object_t *p_this, const struct sockaddr *sa, int salen,
flags );
#else
{
vlc_value_t lock;
# ifdef HAVE_USABLE_MUTEX_THAT_DONT_NEED_LIBVLC_POINTER
static vlc_value_t lock;
/* my getnameinfo implementation is not thread-safe as it uses
* gethostbyaddr and the likes */
var_Create( p_this->p_libvlc, "getnameinfo_mutex", VLC_VAR_MUTEX );
var_Get( p_this->p_libvlc, "getnameinfo_mutex", &lock );
vlc_mutex_lock( lock.p_address );
#else
# warning FIXME : This is not thread-safe! Your platform is outdated.
#endif
i_val = __getnameinfo( sa, salen, host, hostlen, psz_serv, i_servlen,
flags );
# ifdef HAVE_USABLE_MUTEX_THAT_DONT_NEED_LIBVLC_POINTER
vlc_mutex_unlock( lock.p_address );
# endif
}
#endif
......
......@@ -1331,15 +1331,13 @@ void httpd_ClientModeBidir( httpd_client_t *cl )
cl->i_mode = HTTPD_CLIENT_BIDIR;
}
/*
* FIXME: use vlc_getnameinfo
*/
char* httpd_ClientIP( httpd_client_t *cl )
{
#ifdef HAVE_GETNAMEINFO
char sz_ip[INET6_ADDRSTRLEN + 2];
int i;
char *psz_ip;
psz_ip = (char *)malloc( NI_MAXNUMERICHOST + 2 );
#ifdef HAVE_GETNAMEINFO /* FIXME not very good check */
if( (cl->sock.ss_family == AF_INET6) &&
IN6_IS_ADDR_V4MAPPED( &((const struct sockaddr_in6 *)
&cl->sock)->sin6_addr) )
......@@ -1352,34 +1350,31 @@ char* httpd_ClientIP( httpd_client_t *cl )
a.sin_port = ((const struct sockaddr_in6 *)&cl->sock)->sin6_port;
a.sin_addr.s_addr = ((const uint32_t *)&((const struct sockaddr_in6 *)
&cl->sock)->sin6_addr)[3];
i = getnameinfo( (const struct sockaddr *)&a, sizeof( a ),
&sz_ip[1], INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST );
i = vlc_getnameinfo( (const struct sockaddr *)&a, sizeof( a ),
psz_ip + 1, NI_MAXNUMERICHOST, NULL,
NI_NUMERICHOST );
}
else
i = getnameinfo( (const struct sockaddr *)&cl->sock, cl->i_sock_size,
&sz_ip[1], INET6_ADDRSTRLEN, NULL, 0,
NI_NUMERICHOST );
#endif
i = vlc_getnameinfo( (const struct sockaddr *)&cl->sock,
cl->i_sock_size, psz_ip + 1, NI_MAXNUMERICHOST,
NULL, NI_NUMERICHOST );
if( i != 0 )
/* FIXME: msg_Err */
return NULL;
if( strchr( &sz_ip[1], ':' ) != NULL )
/* semi-colon in address => must add bracket for HTTP */
if( strchr( psz_ip + 1, ':' ) != NULL )
{
*sz_ip = '[';
i = strlen( sz_ip );
sz_ip[i++] = ']';
sz_ip[i] = '\0';
psz_ip[0] = '[';
i = strlen( psz_ip );
psz_ip[i++] = ']';
psz_ip[i] = '\0';
return strdup( sz_ip );
return psz_ip;
}
return strdup( &sz_ip[1] );
#else
/* FIXME not thread safe */
return strdup( inet_ntoa( ((const struct sockaddr_in *)&cl->sock)->sin_addr ) );
#endif
return psz_ip + 1;
}
static void httpd_ClientClean( httpd_client_t *cl )
......@@ -1961,14 +1956,6 @@ static void httpd_HostThread( httpd_host_t *host )
( cl->i_activity_timeout > 0 &&
cl->i_activity_date+cl->i_activity_timeout < mdate()) ) ) )
{
char *ip;
// FIXME: it sucks to allocate memory on the stack for debug
ip = httpd_ClientIP( cl );
msg_Dbg( host, "connection closed(%s)",
(ip != NULL) ? ip : "unknown" );
free( ip );
httpd_ClientClean( cl );
TAB_REMOVE( host->i_client, host->client, cl );
free( cl );
......@@ -2392,7 +2379,6 @@ static void httpd_HostThread( httpd_host_t *host )
if( fd >= 0 )
{
char *ip;
httpd_client_t *cl;
cl = httpd_ClientNew( fd, &sock, i_sock_size, p_tls );
......@@ -2403,13 +2389,6 @@ static void httpd_HostThread( httpd_host_t *host )
if( i_state != 0 )
cl->i_state = i_state; // override state for TLS
// FIXME: it sucks to allocate memory for debug
ip = httpd_ClientIP( cl );
msg_Dbg( host, "new connection (%s)",
ip != NULL ? ip : "unknown" );
if( ip != NULL )
free( ip );
}
}
}
......
......@@ -298,9 +298,8 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
i = vlc_getaddrinfo( (vlc_object_t *)p_sap, p_session->psz_uri, 0,
&hints, &res );
if( i == 0 )
i = vlc_getnameinfo( (vlc_object_t *)p_sap, res->ai_addr,
res->ai_addrlen, psz_buf, sizeof( psz_buf ),
NULL, NI_NUMERICHOST );
i = vlc_getnameinfo( res->ai_addr, res->ai_addrlen, psz_buf,
sizeof( psz_buf ), NULL, NI_NUMERICHOST );
if( i )
{
msg_Err( p_sap, "Invalid URI for SAP announce : %s : %s",
......
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