]> git.sesse.net Git - vlc/blobdiff - src/misc/httpd.c
Fix compilation. Thanks bigben
[vlc] / src / misc / httpd.c
index b3e4d001be33b38018f4e027e1513460ca8feb3c..66c4bc2afd6bce5cc8bdd0c3716b3745b2e2fc52 100644 (file)
@@ -901,6 +901,9 @@ httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, const char *psz_hostname,
     vlc_value_t  lockval;
     int i;
 
+    if( psz_hostname == NULL )
+        psz_hostname = "";
+
     psz_host = strdup( psz_hostname );
     if( psz_host == NULL )
     {
@@ -1326,29 +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 sz_ip[NI_MAXNUMERICHOST + 2];
-
-    i = vlc_getnameinfo( (const struct sockaddr *)&cl->sock, cl->i_sock_size,
-                         sz_ip+1, NI_MAXNUMERICHOST, NULL, NI_NUMERICHOST );
-
-    if( i != 0 )
-        return NULL;
-
-    /* semi-colon in address => must add bracket for HTTP */        
-    if( strchr( sz_ip + 1, ':' ) != NULL )
-    {
-        sz_ip[0] = '[';
-        i = strlen( sz_ip );
-        sz_ip[i++] = ']';
-        sz_ip[i] = '\0';
+    return net_GetPeerAddress( cl->fd, psz_ip, NULL ) ? NULL : psz_ip;
+}
 
-        return strdup(sz_ip);
-    }
-    
-    return strdup(sz_ip + 1);
+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 )
@@ -2076,17 +2064,18 @@ static void httpd_HostThread( httpd_host_t *host )
                             {
                                 if( answer && ( url->p_acl != NULL ) )
                                 {
-                                    char *ip = httpd_ClientIP( cl );
-                                    if( ip != NULL )
+                                    char ip[NI_MAXNUMERICHOST];
+
+                                    if( httpd_ClientIP( cl, ip ) != NULL )
                                     {
                                         if( ACL_Check( url->p_acl, ip ) )
                                         {
                                             b_hosts_failed = VLC_TRUE;
-                                            free( ip );
                                             break;
                                         }
-                                        free( ip );
                                     }
+                                    else
+                                        b_hosts_failed = VLC_TRUE;
                                 }
 
                                 if( answer && ( *url->psz_user || *url->psz_password ) )