| 24 | | + |
| 25 | | + CFStringEncoding se = kCFStringEncodingUTF8; |
| 26 | | + |
| 27 | | + CFStringRef sr = CFStringCreateWithCString(kCFAllocatorDefault, Queue->Uri.c_str(), se); |
| 28 | | + CFURLRef ur = CFURLCreateWithString(kCFAllocatorDefault, sr, NULL); |
| 29 | | + CFRelease(sr); |
| 30 | | + CFHTTPMessageRef hm = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"), ur, kCFHTTPVersion1_1); |
| 31 | | + CFRelease(ur); |
| 32 | | + |
| 33 | | + struct stat SBuf; |
| 34 | | + if (stat(Queue->DestFile.c_str(), &SBuf) >= 0 && SBuf.st_size > 0) { |
| 35 | | + sr = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("bytes=%li-"), (long) SBuf.st_size - 1); |
| 36 | | + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("Range"), sr); |
| 37 | | + CFRelease(sr); |
| 38 | | + |
| 39 | | + sr = CFStringCreateWithCString(kCFAllocatorDefault, TimeRFC1123(SBuf.st_mtime).c_str(), se); |
| 40 | | + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("If-Range"), sr); |
| 41 | | + CFRelease(sr); |
| 42 | | + } else if (Queue->LastModified != 0) { |
| 43 | | + sr = CFStringCreateWithCString(kCFAllocatorDefault, TimeRFC1123(SBuf.st_mtime).c_str(), se); |
| 44 | | + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("If-Modified-Since"), sr); |
| 45 | | + CFRelease(sr); |
| 46 | | } |
| | 24 | - } |
| 67 | | + |
| 68 | | + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("User-Agent"), CFSTR("Telesphoreo APT-HTTP/1.0.98")); |
| 69 | | + CFReadStreamRef rs = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, hm); |
| 70 | | + CFRelease(hm); |
| 71 | | + |
| 72 | | + CFReadStreamSetProperty(rs, kCFStreamPropertyHTTPShouldAutoredirect, kCFBooleanTrue); |
| 73 | | + CFReadStreamSetProperty(rs, kCFStreamPropertyHTTPAttemptPersistentConnection, kCFBooleanTrue); |
| 74 | | + |
| 75 | | + URI uri = Queue->Uri; |
| 76 | | + |
| 77 | | + Status("Connecting to %s", uri.Host.c_str()); |
| 78 | | + |
| 79 | | + if (!CFReadStreamOpen(rs)) { |
| 80 | | + Fail(true); |
| 81 | | + continue; |
| 82 | | } |
| | 45 | - } |
| 121 | | + uint8_t data[10240]; |
| 122 | | + CFIndex rd = CFReadStreamRead(rs, data, sizeof(data)); |
| | 84 | + CFStringEncoding se = kCFStringEncodingUTF8; |
| | 85 | + |
| | 86 | + CFStringRef sr = CFStringCreateWithCString(kCFAllocatorDefault, Queue->Uri.c_str(), se); |
| | 87 | + CFURLRef ur = CFURLCreateWithString(kCFAllocatorDefault, sr, NULL); |
| | 88 | + CFRelease(sr); |
| | 89 | + CFHTTPMessageRef hm = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"), ur, kCFHTTPVersion1_1); |
| | 90 | + CFRelease(ur); |
| | 91 | + |
| | 92 | + struct stat SBuf; |
| | 93 | + if (stat(Queue->DestFile.c_str(), &SBuf) >= 0 && SBuf.st_size > 0) { |
| | 94 | + sr = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("bytes=%li-"), (long) SBuf.st_size - 1); |
| | 95 | + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("Range"), sr); |
| | 96 | + CFRelease(sr); |
| | 97 | + |
| | 98 | + sr = CFStringCreateWithCString(kCFAllocatorDefault, TimeRFC1123(SBuf.st_mtime).c_str(), se); |
| | 99 | + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("If-Range"), sr); |
| | 100 | + CFRelease(sr); |
| | 101 | + } else if (Queue->LastModified != 0) { |
| | 102 | + sr = CFStringCreateWithCString(kCFAllocatorDefault, TimeRFC1123(SBuf.st_mtime).c_str(), se); |
| | 103 | + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("If-Modified-Since"), sr); |
| | 104 | + CFRelease(sr); |
| | 105 | + } |
| | 106 | + |
| | 107 | + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("User-Agent"), CFSTR("Telesphoreo APT-HTTP/1.0.98")); |
| | 108 | + CFReadStreamRef rs = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, hm); |
| | 109 | + CFRelease(hm); |
| | 110 | + |
| | 111 | + CFReadStreamSetProperty(rs, kCFStreamPropertyHTTPShouldAutoredirect, kCFBooleanTrue); |
| | 112 | + CFReadStreamSetProperty(rs, kCFStreamPropertyHTTPAttemptPersistentConnection, kCFBooleanTrue); |
| | 113 | + |
| | 114 | + URI uri = Queue->Uri; |