| 119 | | + |
| 120 | | + uri.Host = inet_ntoa(* (struct in_addr *) he->h_addr_list[0]); |
| 121 | | + |
| 122 | | + std::string urs = uri; |
| 123 | | + |
| 124 | | + CFStringRef sr = CFStringCreateWithCString(kCFAllocatorDefault, urs.c_str(), se); |
| 125 | | + CFURLRef ur = CFURLCreateWithString(kCFAllocatorDefault, sr, NULL); |
| 126 | | + CFRelease(sr); |
| 127 | | + CFHTTPMessageRef hm = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"), ur, kCFHTTPVersion1_1); |
| 128 | | + CFRelease(ur); |
| 129 | | + |
| 130 | | + struct stat SBuf; |
| 131 | | + if (stat(Queue->DestFile.c_str(), &SBuf) >= 0 && SBuf.st_size > 0) { |
| 132 | | + sr = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("bytes=%li-"), (long) SBuf.st_size - 1); |
| 133 | | + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("Range"), sr); |
| 134 | | + CFRelease(sr); |
| 135 | | + |
| 136 | | + sr = CFStringCreateWithCString(kCFAllocatorDefault, TimeRFC1123(SBuf.st_mtime).c_str(), se); |
| 137 | | + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("If-Range"), sr); |
| 138 | | + CFRelease(sr); |
| 139 | | + } else if (Queue->LastModified != 0) { |
| 140 | | + sr = CFStringCreateWithCString(kCFAllocatorDefault, TimeRFC1123(SBuf.st_mtime).c_str(), se); |
| 141 | | + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("If-Modified-Since"), sr); |
| 142 | | + CFRelease(sr); |
| 143 | | } |
| | 106 | - } |
| | 145 | + CFStringEncoding se = kCFStringEncodingUTF8; |
| | 146 | + |
| | 147 | + char *url = strdup(Queue->Uri.c_str()); |
| | 148 | + url: |
| | 149 | + URI uri = std::string(url); |
| | 150 | + std::string hs = uri.Host; |
| | 151 | + |
| | 152 | +#if __ENVIRONMENT_ASPEN_VERSION_MIN_REQUIRED__ >= 10200 |
| | 153 | + struct hostent *he = gethostbyname(hs.c_str()); |
| | 154 | + if (he == NULL || he->h_addr_list[0] == NULL) { |
| | 155 | + _error->Error(hstrerror(h_errno)); |
| | 156 | + Fail(true); |
| | 157 | + free(url); |
| | 158 | + } |
| | 159 | + |
| | 160 | + uri.Host = inet_ntoa(* (struct in_addr *) he->h_addr_list[0]); |
| | 161 | +#endif |
| | 162 | + |
| | 163 | + std::string urs = uri; |
| | 164 | + |
| | 165 | + CFStringRef sr = CFStringCreateWithCString(kCFAllocatorDefault, urs.c_str(), se); |
| | 166 | + CFURLRef ur = CFURLCreateWithString(kCFAllocatorDefault, sr, NULL); |
| | 167 | + CFRelease(sr); |
| | 168 | + CFHTTPMessageRef hm = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"), ur, kCFHTTPVersion1_1); |
| | 169 | + CFRelease(ur); |
| | 170 | + |
| | 171 | + struct stat SBuf; |
| | 172 | + if (stat(Queue->DestFile.c_str(), &SBuf) >= 0 && SBuf.st_size > 0) { |
| | 173 | + sr = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("bytes=%li-"), (long) SBuf.st_size - 1); |
| | 174 | + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("Range"), sr); |
| | 175 | + CFRelease(sr); |
| | 176 | + |
| | 177 | + sr = CFStringCreateWithCString(kCFAllocatorDefault, TimeRFC1123(SBuf.st_mtime).c_str(), se); |
| | 178 | + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("If-Range"), sr); |
| | 179 | + CFRelease(sr); |
| | 180 | + } else if (Queue->LastModified != 0) { |
| | 181 | + sr = CFStringCreateWithCString(kCFAllocatorDefault, TimeRFC1123(SBuf.st_mtime).c_str(), se); |
| | 182 | + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("If-Modified-Since"), sr); |
| | 183 | + CFRelease(sr); |
| | 184 | + } |
| | 185 | + |