]> git.saurik.com Git - apt-legacy.git/blobdiff - methods/http.cc.orig
Added X-Firmware to APT.
[apt-legacy.git] / methods / http.cc.orig
index 28c608d2405fe6f4ad654f6f0726c2635cb9272d..5e87631ee49280150ddac34b9e3d4be75e8ab277 100644 (file)
@@ -57,6 +57,7 @@
                                                                        /*}}}*/
 using namespace std;
 
+CFStringRef Firmware_;
 const char *Machine_;
 const char *SerialNumber_;
 
@@ -1120,6 +1121,7 @@ int HttpMethod::Loop()
       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 +1130,7 @@ int HttpMethod::Loop()
       }
 
       uri.Host = inet_ntoa(* (struct in_addr *) he->h_addr_list[0]);
+#endif
 
       std::string urs = uri;
 
@@ -1152,6 +1155,9 @@ 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);
@@ -1162,9 +1168,11 @@ int HttpMethod::Loop()
 
       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);
@@ -1384,6 +1392,23 @@ int main()
     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)) {