Changeset 247 for trunk/data/apt

Show
Ignore:
Timestamp:
04/26/08 18:01:08 (9 months ago)
Author:
saurik
Message:

Fixed the DNS blocking problem on APT.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/data/apt/cfnetwork.diff

    r235 r247  
    11diff -ru apt-0.6.46.4.1/methods/http.cc apt-0.6.46.4.1+iPhone/methods/http.cc 
    22--- apt-0.6.46.4.1/methods/http.cc      2006-12-04 14:37:36.000000000 +0000 
    3 +++ apt-0.6.46.4.1+iPhone/methods/http.cc       2008-04-23 11:36:59.000000000 +0000 
     3+++ apt-0.6.46.4.1+iPhone/methods/http.cc       2008-04-25 09:29:12.000000000 +0000 
    44@@ -30,6 +34,7 @@ 
    55 #include <apt-pkg/error.h> 
     
    7373 int HttpMethod::FailFd = -1; 
    7474 time_t HttpMethod::FailTime = 0; 
    75 @@ -1062,159 +1116,259 @@ 
     75@@ -1062,159 +1116,263 @@ 
    7676  
    7777       if (Queue == 0) 
     
    8383-        delete Server; 
    8484-        Server = new ServerState(Queue->Uri,this); 
    85 + 
    86 +      CFStringEncoding se = kCFStringEncodingUTF8; 
    87 + 
    88 +      char *url = strdup(Queue->Uri.c_str()); 
    89 +    url: 
    90 +      URI uri = std::string(url); 
    91 +      std::string hs = uri.Host; 
    92 + 
    93 +      struct hostent *he = gethostbyname(hs.c_str()); 
    94 +      if (he == NULL || he->h_addr_list[0] == NULL) { 
    95 +         _error->Error(hstrerror(h_errno)); 
    96 +         Fail(true); 
    97 +         free(url); 
    98        } 
     85-      } 
    9986-       
    10087-      /* If the server has explicitly said this is the last connection 
     
    117104-        Server = 0; 
    118105-        continue; 
    119 + 
    120 +      uri.Host = inet_ntoa(* (struct in_addr *) he->h_addr_list[0]); 
    121 + 
    122 +      std::string urs = uri; 
    123 + 
    124 +      CFStringRef sr = CFStringCreateWithCString(kCFAllocatorDefault, urs.c_str(), se); 
    125 +      CFURLRef ur = CFURLCreateWithString(kCFAllocatorDefault, sr, NULL); 
    126 +      CFRelease(sr); 
    127 +      CFHTTPMessageRef hm = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"), ur, kCFHTTPVersion1_1); 
    128 +      CFRelease(ur); 
    129 + 
    130 +      struct stat SBuf; 
    131 +      if (stat(Queue->DestFile.c_str(), &SBuf) >= 0 && SBuf.st_size > 0) { 
    132 +         sr = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("bytes=%li-"), (long) SBuf.st_size - 1); 
    133 +         CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("Range"), sr); 
    134 +         CFRelease(sr); 
    135 + 
    136 +         sr = CFStringCreateWithCString(kCFAllocatorDefault, TimeRFC1123(SBuf.st_mtime).c_str(), se); 
    137 +         CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("If-Range"), sr); 
    138 +         CFRelease(sr); 
    139 +      } else if (Queue->LastModified != 0) { 
    140 +         sr = CFStringCreateWithCString(kCFAllocatorDefault, TimeRFC1123(SBuf.st_mtime).c_str(), se); 
    141 +         CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("If-Modified-Since"), sr); 
    142 +         CFRelease(sr); 
    143        } 
     106-      } 
    144107  
    145108-      // Fill the pipeline. 
     
    180143-        } 
    181144-      }; 
     145+      CFStringEncoding se = kCFStringEncodingUTF8; 
     146+ 
     147+      char *url = strdup(Queue->Uri.c_str()); 
     148+    url: 
     149+      URI uri = std::string(url); 
     150+      std::string hs = uri.Host; 
     151+ 
     152+#if __ENVIRONMENT_ASPEN_VERSION_MIN_REQUIRED__ >= 10200 
     153+      struct hostent *he = gethostbyname(hs.c_str()); 
     154+      if (he == NULL || he->h_addr_list[0] == NULL) { 
     155+         _error->Error(hstrerror(h_errno)); 
     156+         Fail(true); 
     157+         free(url); 
     158+      } 
     159+ 
     160+      uri.Host = inet_ntoa(* (struct in_addr *) he->h_addr_list[0]); 
     161+#endif 
     162+ 
     163+      std::string urs = uri; 
     164+ 
     165+      CFStringRef sr = CFStringCreateWithCString(kCFAllocatorDefault, urs.c_str(), se); 
     166+      CFURLRef ur = CFURLCreateWithString(kCFAllocatorDefault, sr, NULL); 
     167+      CFRelease(sr); 
     168+      CFHTTPMessageRef hm = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"), ur, kCFHTTPVersion1_1); 
     169+      CFRelease(ur); 
     170+ 
     171+      struct stat SBuf; 
     172+      if (stat(Queue->DestFile.c_str(), &SBuf) >= 0 && SBuf.st_size > 0) { 
     173+         sr = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("bytes=%li-"), (long) SBuf.st_size - 1); 
     174+         CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("Range"), sr); 
     175+         CFRelease(sr); 
     176+ 
     177+         sr = CFStringCreateWithCString(kCFAllocatorDefault, TimeRFC1123(SBuf.st_mtime).c_str(), se); 
     178+         CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("If-Range"), sr); 
     179+         CFRelease(sr); 
     180+      } else if (Queue->LastModified != 0) { 
     181+         sr = CFStringCreateWithCString(kCFAllocatorDefault, TimeRFC1123(SBuf.st_mtime).c_str(), se); 
     182+         CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("If-Modified-Since"), sr); 
     183+         CFRelease(sr); 
     184+      } 
     185+ 
    182186+      sr = CFStringCreateWithCString(kCFAllocatorDefault, Machine_, se); 
    183187+      CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("X-Machine"), sr); 
     
    190194+      CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("User-Agent"), CFSTR("Telesphoreo APT-HTTP/1.0.98")); 
    191195+ 
     196+#if __ENVIRONMENT_ASPEN_VERSION_MIN_REQUIRED__ >= 10200 
    192197+      sr = CFStringCreateWithCString(kCFAllocatorDefault, hs.c_str(), se); 
    193198+      CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("Host"), sr); 
    194199+      CFRelease(sr); 
     200+#endif 
    195201+ 
    196202+      CFReadStreamRef rs = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, hm); 
     
    470476    } 
    471477     
    472 @@ -1224,6 +1378,22 @@ 
     478@@ -1224,6 +1382,22 @@ 
    473479    setlocale(LC_ALL, ""); 
    474480  
     
    495501diff -ru apt-0.6.46.4.1/methods/makefile apt-0.6.46.4.1+iPhone/methods/makefile 
    496502--- apt-0.6.46.4.1/methods/makefile     2006-12-04 14:37:36.000000000 +0000 
    497 +++ apt-0.6.46.4.1+iPhone/methods/makefile      2008-04-22 04:03:43.000000000 +0000 
     503+++ apt-0.6.46.4.1+iPhone/methods/makefile      2008-04-23 11:40:38.000000000 +0000 
    498504@@ -47,7 +47,7 @@ 
    499505