From: Jay Freeman (saurik) Date: Sun, 6 Apr 2008 10:28:29 +0000 (+0000) Subject: Drastic, sweeping modifications to support iPhone 1.2.0/2.0. X-Git-Url: https://git.saurik.com/apt-legacy.git/commitdiff_plain/b7a89731f51f1a64423d67c80f8406cea49e1366?ds=inline Drastic, sweeping modifications to support iPhone 1.2.0/2.0. M cfnetwork.diff git-svn-id: http://svn.telesphoreo.org/trunk@199 514c082c-b64e-11dc-b46d-3d985efe055d --- diff --git a/methods/http.cc b/methods/http.cc index b3cea13..578e4e2 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -96,7 +96,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); } } @@ -1114,7 +1114,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); @@ -1143,12 +1145,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; @@ -1161,7 +1165,7 @@ int HttpMethod::Loop() goto done; } - CFIndex rd = CFReadStreamRead(rs, data, sizeof(data)); + rd = CFReadStreamRead(rs, data, sizeof(data)); if (rd == -1) { CfrsError(rs); @@ -1172,7 +1176,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(malloc(ln)); + + if (!CFStringGetCString(sr, url, ln, se)) { + Fail(); + goto done_; + } + + CFRelease(sr); + goto url; + } + } sr = CFHTTPMessageCopyHeaderFieldValue(hm, CFSTR("Content-Range")); if (sr != NULL) { @@ -1313,6 +1337,7 @@ int HttpMethod::Loop() done: CFReadStreamClose(rs); CFRelease(rs); + free(url); FailCounter = 0; } diff --git a/methods/http.cc.orig b/methods/http.cc.orig index 8a9d594..d2762c8 100644 --- a/methods/http.cc.orig +++ b/methods/http.cc.orig @@ -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(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; }