X-Git-Url: https://git.saurik.com/apt-legacy.git/blobdiff_plain/fe23a69686346c5c2b31fbad05da861fd31ba73b..032f992c5ed1130c348c7ddd074cde239e09cc87:/methods/http.cc?ds=sidebyside diff --git a/methods/http.cc b/methods/http.cc index 2cca8b8..2819ae1 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -34,6 +34,7 @@ extern "C" { #include #include +#include #include #include #include @@ -60,6 +61,10 @@ extern "C" { /*}}}*/ using namespace std; +CFStringRef Firmware_; +const char *Machine_; +const char *SerialNumber_; + void CfrsError(const char *name, CFReadStreamRef rs) { CFStreamError se = CFReadStreamGetError(rs); @@ -1117,9 +1122,10 @@ int HttpMethod::Loop() char *url = strdup(Queue->Uri.c_str()); url: - URI uri = Queue->Uri; + URI uri = std::string(url); std::string hs = uri.Host; +#if __ENVIRONMENT_ASPEN_VERSION_MIN_REQUIRED__ >= 10200 struct hostent *he = gethostbyname(hs.c_str()); if (he == NULL || he->h_addr_list[0] == NULL) { _error->Error(hstrerror(h_errno)); @@ -1128,6 +1134,7 @@ int HttpMethod::Loop() } uri.Host = inet_ntoa(* (struct in_addr *) he->h_addr_list[0]); +#endif std::string urs = uri; @@ -1152,11 +1159,24 @@ int HttpMethod::Loop() CFRelease(sr); } + if (Firmware_ != NULL) + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("X-Firmware"), Firmware_); + + sr = CFStringCreateWithCString(kCFAllocatorDefault, Machine_, se); + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("X-Machine"), sr); + CFRelease(sr); + + sr = CFStringCreateWithCString(kCFAllocatorDefault, SerialNumber_, se); + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("X-Serial-Number"), sr); + CFRelease(sr); + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("User-Agent"), CFSTR("Telesphoreo APT-HTTP/1.0.98")); +#if __ENVIRONMENT_ASPEN_VERSION_MIN_REQUIRED__ >= 10200 sr = CFStringCreateWithCString(kCFAllocatorDefault, hs.c_str(), se); CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("Host"), sr); CFRelease(sr); +#endif CFReadStreamRef rs = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, hm); CFRelease(hm); @@ -1196,7 +1216,7 @@ int HttpMethod::Loop() hm = (CFHTTPMessageRef) CFReadStreamCopyProperty(rs, kCFStreamPropertyHTTPResponseHeader); sc = CFHTTPMessageGetResponseStatusCode(hm); - if (sc == 302) { + if (sc == 301 || sc == 302) { sr = CFHTTPMessageCopyHeaderFieldValue(hm, CFSTR("Location")); if (sr == NULL) { Fail(); @@ -1378,6 +1398,39 @@ int main() setlocale(LC_ALL, ""); HttpMethod Mth; + + size_t size; + sysctlbyname("hw.machine", NULL, &size, NULL, 0); + char *machine = new char[size]; + sysctlbyname("hw.machine", machine, &size, NULL, 0); + Machine_ = machine; + + const char *path = "/System/Library/CoreServices/SystemVersion.plist"; + CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (uint8_t *) path, strlen(path), false); + + CFPropertyListRef plist; { + CFReadStreamRef stream = CFReadStreamCreateWithFile(kCFAllocatorDefault, url); + CFReadStreamOpen(stream); + plist = CFPropertyListCreateFromStream(kCFAllocatorDefault, stream, 0, kCFPropertyListImmutable, NULL, NULL); + CFReadStreamClose(stream); + } + + CFRelease(url); + + if (plist != NULL) { + Firmware_ = (CFStringRef) CFRetain(CFDictionaryGetValue((CFDictionaryRef) plist, CFSTR("ProductVersion"))); + CFRelease(plist); + } + + if (CFMutableDictionaryRef dict = IOServiceMatching("IOPlatformExpertDevice")) + if (io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, dict)) { + if (CFTypeRef serial = IORegistryEntryCreateCFProperty(service, CFSTR(kIOPlatformSerialNumberKey), kCFAllocatorDefault, 0)) { + SerialNumber_ = strdup(CFStringGetCStringPtr((CFStringRef) serial, CFStringGetSystemEncoding())); + CFRelease(serial); + } + + IOObjectRelease(service); + } return Mth.Loop(); }