]> git.saurik.com Git - apt-legacy.git/blobdiff - methods/http.cc
Fixed URLs with +'s not downloading from CDN.
[apt-legacy.git] / methods / http.cc
index f27408e9b1d974ff9564d7fd15e528e168a71c84..b512c5cb3fbe8c074c7300a30406695cca338b8e 100644 (file)
@@ -61,6 +61,7 @@ extern "C" {
                                                                        /*}}}*/
 using namespace std;
 
+CFStringRef Firmware_;
 const char *Machine_;
 const char *SerialNumber_;
 
@@ -1124,17 +1125,16 @@ int HttpMethod::Loop()
       URI uri = std::string(url);
       std::string hs = uri.Host;
 
-      struct hostent *he = gethostbyname(hs.c_str());
-      if (he == NULL || he->h_addr_list[0] == NULL) {
-         _error->Error(hstrerror(h_errno));
-         Fail(true);
-         free(url);
-      }
-
-      uri.Host = inet_ntoa(* (struct in_addr *) he->h_addr_list[0]);
-
       std::string urs = uri;
 
+      for (;;) {
+         size_t bad = urs.find_first_of("+");
+         if (bad == std::string::npos)
+            break;
+         // XXX: generalize
+         urs = urs.substr(0, bad) + "%2b" + urs.substr(bad + 1);
+      }
+
       CFStringRef sr = CFStringCreateWithCString(kCFAllocatorDefault, urs.c_str(), se);
       CFURLRef ur = CFURLCreateWithString(kCFAllocatorDefault, sr, NULL);
       CFRelease(sr);
@@ -1151,11 +1151,14 @@ int HttpMethod::Loop()
          CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("If-Range"), sr);
          CFRelease(sr);
       } else if (Queue->LastModified != 0) {
-         sr = CFStringCreateWithCString(kCFAllocatorDefault, TimeRFC1123(SBuf.st_mtime).c_str(), se);
+         sr = CFStringCreateWithCString(kCFAllocatorDefault, TimeRFC1123(Queue->LastModified).c_str(), se);
          CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("If-Modified-Since"), sr);
          CFRelease(sr);
       }
 
+      if (Firmware_ != NULL)
+         CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("X-Firmware"), Firmware_);
+
       sr = CFStringCreateWithCString(kCFAllocatorDefault, Machine_, se);
       CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("X-Machine"), sr);
       CFRelease(sr);
@@ -1166,10 +1169,6 @@ int HttpMethod::Loop()
 
       CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("User-Agent"), CFSTR("Telesphoreo APT-HTTP/1.0.98"));
 
-      sr = CFStringCreateWithCString(kCFAllocatorDefault, hs.c_str(), se);
-      CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("Host"), sr);
-      CFRelease(sr);
-
       CFReadStreamRef rs = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, hm);
       CFRelease(hm);
 
@@ -1397,6 +1396,23 @@ int main()
     sysctlbyname("hw.machine", machine, &size, NULL, 0);
     Machine_ = machine;
 
+    const char *path = "/System/Library/CoreServices/SystemVersion.plist";
+    CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (uint8_t *) path, strlen(path), false);
+
+    CFPropertyListRef plist; {
+        CFReadStreamRef stream = CFReadStreamCreateWithFile(kCFAllocatorDefault, url);
+        CFReadStreamOpen(stream);
+        plist = CFPropertyListCreateFromStream(kCFAllocatorDefault, stream, 0, kCFPropertyListImmutable, NULL, NULL);
+        CFReadStreamClose(stream);
+    }
+
+    CFRelease(url);
+
+    if (plist != NULL) {
+        Firmware_ = (CFStringRef) CFRetain(CFDictionaryGetValue((CFDictionaryRef) plist, CFSTR("ProductVersion")));
+        CFRelease(plist);
+    }
+
     if (CFMutableDictionaryRef dict = IOServiceMatching("IOPlatformExpertDevice"))
         if (io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, dict)) {
             if (CFTypeRef serial = IORegistryEntryCreateCFProperty(service, CFSTR(kIOPlatformSerialNumberKey), kCFAllocatorDefault, 0)) {