From 31683caff435305a0f19f4becd2f39f2563d1fbb Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Thu, 2 Mar 2006 22:39:03 +0000 Subject: [PATCH] Code reuse --- include/vlc_httpd.h | 4 ++-- include/vlc_symbols.h | 4 ++-- src/network/httpd.c | 39 +++++---------------------------------- 3 files changed, 9 insertions(+), 38 deletions(-) diff --git a/include/vlc_httpd.h b/include/vlc_httpd.h index e21ee634e5..3edd0f95e7 100644 --- a/include/vlc_httpd.h +++ b/include/vlc_httpd.h @@ -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 */ diff --git a/include/vlc_symbols.h b/include/vlc_symbols.h index 19e0b8a356..fcb5f75aa9 100644 --- a/include/vlc_symbols.h +++ b/include/vlc_symbols.h @@ -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 *); diff --git a/src/network/httpd.c b/src/network/httpd.c index b9ab16fa6f..4ddf530891 100644 --- a/src/network/httpd.c +++ b/src/network/httpd.c @@ -47,15 +47,8 @@ # include #elif defined( WIN32 ) # include -# include #else -# include /* hostent ... */ # include -/* FIXME: should not be needed */ -# include -# ifdef HAVE_ARPA_INET_H -# include /* 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; } -- 2.39.2