+ if (!CFStringGetCString(sr, url, ln, se)) {
+ Fail();
+ goto done_;
+ }
+
+ CFRelease(sr);
+ goto url;
+ }
+ }
+
+ sr = CFHTTPMessageCopyHeaderFieldValue(hm, CFSTR("Content-Range"));
+ if (sr != NULL) {
+ size_t ln = CFStringGetLength(sr) + 1;
+ char cr[ln];
+
+ if (!CFStringGetCString(sr, cr, ln, se)) {
+ Fail();
+ goto done_;
+ }
+
+ CFRelease(sr);
+
+ if (sscanf(cr, "bytes %lu-%*u/%lu", &offset, &Res.Size) != 2) {
+ _error->Error(_("The HTTP server sent an invalid Content-Range header"));
+ Fail();
+ goto done_;
+ }
+
+ if (offset > Res.Size) {
+ _error->Error(_("This HTTP server has broken range support"));
+ Fail();
+ goto done_;
+ }
+ } else {
+ sr = CFHTTPMessageCopyHeaderFieldValue(hm, CFSTR("Content-Length"));
+ if (sr != NULL) {
+ Res.Size = CFStringGetIntValue(sr);
+ CFRelease(sr);
+ }
+ }
+
+ time(&Res.LastModified);
+
+ sr = CFHTTPMessageCopyHeaderFieldValue(hm, CFSTR("Last-Modified"));
+ if (sr != NULL) {
+ size_t ln = CFStringGetLength(sr) + 1;
+ char cr[ln];
+
+ if (!CFStringGetCString(sr, cr, ln, se)) {
+ Fail();
+ goto done_;
+ }
+
+ CFRelease(sr);
+
+ if (!StrToTime(cr, Res.LastModified)) {
+ _error->Error(_("Unknown date format"));
+ Fail();
+ goto done_;
+ }
+ }
+
+ CFRelease(hm);
+
+ if (sc == 304) {
+ unlink(Queue->DestFile.c_str());
+ Res.IMSHit = true;
+ Res.LastModified = Queue->LastModified;
+ URIDone(Res);
+ } else if (sc < 200 || sc >= 300)
+ Fail();
+ else {
+ Hashes hash;
+
+ File = new FileFd(Queue->DestFile, FileFd::WriteAny);
+ if (_error->PendingError() == true) {
+ delete File;
+ File = NULL;
+ Fail();
+ goto done;
+ }
+
+ FailFile = Queue->DestFile;
+ FailFile.c_str(); // Make sure we dont do a malloc in the signal handler
+ FailFd = File->Fd();
+ FailTime = Res.LastModified;
+
+ Res.ResumePoint = offset;
+ ftruncate(File->Fd(), offset);
+
+ if (offset != 0) {
+ lseek(File->Fd(), 0, SEEK_SET);
+ if (!hash.AddFD(File->Fd(), offset)) {
+ _error->Errno("read", _("Problem hashing file"));
+ delete File;
+ File = NULL;
+ Fail();
+ goto done;
+ }
+ }
+
+ lseek(File->Fd(), 0, SEEK_END);
+
+ URIStart(Res);
+
+ read: if (rd == -1) {
+ CfrsError("rd", rs);
+ Fail(true);
+ } else if (rd == 0) {