]> git.saurik.com Git - apt-legacy.git/blobdiff - methods/http.cc.orig
Drastic, sweeping modifications to support iPhone 1.2.0/2.0.
[apt-legacy.git] / methods / http.cc.orig
index 8a9d594737978f8bd57e26220dbdf064c1e24b1c..d2762c8f99fc137ac6561a92ef66cd9757ea640f 100644 (file)
@@ -92,7 +92,7 @@ void CfrsError(CFReadStreamRef rs) {
     } else if (se.domain == kCFStreamErrorDomainSSL) {
         _error->Error("SSL: %ld", se.error);
     } else {
-        _error->Error("Domain #%d: %ld", se.domain, se.error);
+        _error->Error("Domain #%ld: %ld", se.domain, se.error);
     }
 }
 
@@ -1110,7 +1110,9 @@ int HttpMethod::Loop()
 
       CFStringEncoding se = kCFStringEncodingUTF8;
 
-      CFStringRef sr = CFStringCreateWithCString(kCFAllocatorDefault, Queue->Uri.c_str(), se);
+      char *url = strdup(Queue->Uri.c_str());
+    url:
+      CFStringRef sr = CFStringCreateWithCString(kCFAllocatorDefault, url, se);
       CFURLRef ur = CFURLCreateWithString(kCFAllocatorDefault, sr, NULL);
       CFRelease(sr);
       CFHTTPMessageRef hm = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"), ur, kCFHTTPVersion1_1);
@@ -1139,12 +1141,14 @@ int HttpMethod::Loop()
       CFReadStreamSetProperty(rs, kCFStreamPropertyHTTPProxy, dr);
       CFRelease(dr);
 
-      CFReadStreamSetProperty(rs, kCFStreamPropertyHTTPShouldAutoredirect, kCFBooleanTrue);
+      //CFReadStreamSetProperty(rs, kCFStreamPropertyHTTPShouldAutoredirect, kCFBooleanTrue);
       CFReadStreamSetProperty(rs, kCFStreamPropertyHTTPAttemptPersistentConnection, kCFBooleanTrue);
 
       URI uri = Queue->Uri;
 
       FetchResult Res;
+      CFIndex rd;
+      UInt32 sc;
 
       uint8_t data[10240];
       size_t offset = 0;
@@ -1157,7 +1161,7 @@ int HttpMethod::Loop()
          goto done;
       }
 
-      CFIndex rd = CFReadStreamRead(rs, data, sizeof(data));
+      rd = CFReadStreamRead(rs, data, sizeof(data));
 
       if (rd == -1) {
          CfrsError(rs);
@@ -1168,7 +1172,27 @@ int HttpMethod::Loop()
       Res.Filename = Queue->DestFile;
 
       hm = (CFHTTPMessageRef) CFReadStreamCopyProperty(rs, kCFStreamPropertyHTTPResponseHeader);
-      UInt32 sc = CFHTTPMessageGetResponseStatusCode(hm);
+      sc = CFHTTPMessageGetResponseStatusCode(hm);
+
+      if (sc == 302) {
+         sr = CFHTTPMessageCopyHeaderFieldValue(hm, CFSTR("Location"));
+         if (sr == NULL) {
+            Fail();
+            goto done_;
+         } else {
+            size_t ln = CFStringGetLength(sr) + 1;
+            free(url);
+            url = static_cast<char *>(malloc(ln));
+
+            if (!CFStringGetCString(sr, url, ln, se)) {
+               Fail();
+               goto done_;
+            }
+
+            CFRelease(sr);
+            goto url;
+         }
+      }
 
       sr = CFHTTPMessageCopyHeaderFieldValue(hm, CFSTR("Content-Range"));
       if (sr != NULL) {
@@ -1309,6 +1333,7 @@ int HttpMethod::Loop()
     done:
       CFReadStreamClose(rs);
       CFRelease(rs);
+      free(url);
 
       FailCounter = 0;
    }