]> git.sesse.net Git - vlc/commitdiff
Code reuse
authorRémi Denis-Courmont <rem@videolan.org>
Thu, 2 Mar 2006 22:39:03 +0000 (22:39 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Thu, 2 Mar 2006 22:39:03 +0000 (22:39 +0000)
include/vlc_httpd.h
include/vlc_symbols.h
src/network/httpd.c

index e21ee634e5389a47c1291c9fce29e47c2660442a..3edd0f95e709ab812cadf7810e9a8ed443d86b9f 100644 (file)
@@ -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 */
 
index 19e0b8a35601ea9530874c0928253ca64779dfdc..fcb5f75aa9da4a6291a724cbf1c48824a7e8e0d7 100644 (file)
@@ -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 *);
index b9ab16fa6f843e82191d1a65e649f27a84ea0630..4ddf5308917c8e2991845e7a47e147ae9877a43f 100644 (file)
 #   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;
 }