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

Code reuse

parent 4097f9fa
......@@ -120,8 +120,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, char *psz_ip ) );
VLC_EXPORT( char*, httpd_ServerIP, ( httpd_client_t *cl, char *psz_ip ) );
VLC_EXPORT( char*, httpd_ClientIP, ( const httpd_client_t *cl, char *psz_ip ) );
VLC_EXPORT( char*, httpd_ServerIP, ( const httpd_client_t *cl, char *psz_ip ) );
/* High level */
......
......@@ -204,7 +204,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 *psz_ip);
char* (*httpd_ClientIP_inner) (const httpd_client_t *cl, char *psz_ip);
httpd_file_t * (*httpd_FileNew_inner) (httpd_host_t *, const char *psz_url, const char *psz_mime, const char *psz_user, const 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 *, const char *psz_url_dst, const char *psz_url_src);
......@@ -385,7 +385,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);
char* (*httpd_ServerIP_inner) (const httpd_client_t *cl, char *psz_ip);
char * (*FromLocale_inner) (const char *);
void (*LocaleFree_inner) (const char *);
char * (*ToLocale_inner) (const char *);
......
......@@ -47,15 +47,8 @@
# include <winsock.h>
#elif defined( WIN32 )
# include <winsock2.h>
# include <ws2tcpip.h>
#else
# include <netdb.h> /* hostent ... */
# include <sys/socket.h>
/* FIXME: should not be needed */
# include <netinet/in.h>
# ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h> /* inet_ntoa(), inet_aton() */
# endif
#endif
#if defined( WIN32 )
......@@ -440,7 +433,7 @@ static int httpd_HandlerCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *c
{
httpd_handler_t *handler = (httpd_handler_t*)p_sys;
uint8_t *psz_args = query->psz_args;
char psz_remote_addr[100];
char psz_remote_addr[NI_MAXNUMERICHOST];
if( answer == NULL || query == NULL )
{
......@@ -453,30 +446,8 @@ static int httpd_HandlerCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *c
answer->i_status = 0;
answer->psz_status = NULL;
switch( cl->sock.ss_family )
{
#ifdef HAVE_INET_PTON
case AF_INET:
inet_ntop( cl->sock.ss_family,
&((struct sockaddr_in *)&cl->sock)->sin_addr,
psz_remote_addr, sizeof(psz_remote_addr) );
break;
case AF_INET6:
inet_ntop( cl->sock.ss_family,
&((struct sockaddr_in6 *)&cl->sock)->sin6_addr,
psz_remote_addr, sizeof(psz_remote_addr) );
break;
#else
case AF_INET:
{
char *psz_tmp = inet_ntoa( ((struct sockaddr_in *)&cl->sock)->sin_addr );
strncpy( psz_remote_addr, psz_tmp, sizeof(psz_remote_addr) );
break;
}
#endif
default:
psz_remote_addr[0] = '\0';
}
if( httpd_ClientIP( cl, psz_remote_addr ) == NULL )
*psz_remote_addr = '\0';
handler->pf_fill( handler->p_sys, handler, query->psz_url, psz_args,
query->i_type, query->p_body, query->i_body,
......@@ -1371,12 +1342,12 @@ void httpd_ClientModeBidir( httpd_client_t *cl )
cl->i_mode = HTTPD_CLIENT_BIDIR;
}
char* httpd_ClientIP( httpd_client_t *cl, char *psz_ip )
char* httpd_ClientIP( const httpd_client_t *cl, char *psz_ip )
{
return net_GetPeerAddress( cl->fd, psz_ip, NULL ) ? NULL : psz_ip;
}
char* httpd_ServerIP( httpd_client_t *cl, char *psz_ip )
char* httpd_ServerIP( const httpd_client_t *cl, char *psz_ip )
{
return net_GetSockAddress( cl->fd, psz_ip, NULL ) ? NULL : psz_ip;
}
......
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