} 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);
}
}
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);
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;
goto done;
}
- CFIndex rd = CFReadStreamRead(rs, data, sizeof(data));
+ rd = CFReadStreamRead(rs, data, sizeof(data));
if (rd == -1) {
CfrsError(rs);
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) {
done:
CFReadStreamClose(rs);
CFRelease(rs);
+ free(url);
FailCounter = 0;
}
} 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);
}
}
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);
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;
goto done;
}
- CFIndex rd = CFReadStreamRead(rs, data, sizeof(data));
+ rd = CFReadStreamRead(rs, data, sizeof(data));
if (rd == -1) {
CfrsError(rs);
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) {
done:
CFReadStreamClose(rs);
CFRelease(rs);
+ free(url);
FailCounter = 0;
}