]> git.saurik.com Git - apt-legacy.git/blobdiff - methods/http.cc.orig
Added diff as a requirement of apt.
[apt-legacy.git] / methods / http.cc.orig
index 27454b97b8cd825a3d3608e6278d7c562833de7e..3410a3e1f1b6de1b734b2ef788f3b4733875ffa4 100644 (file)
@@ -30,6 +30,7 @@
 #include <apt-pkg/error.h>
 #include <apt-pkg/hashes.h>
 
+#include <sys/sysctl.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <utime.h>
@@ -56,6 +57,9 @@
                                                                        /*}}}*/
 using namespace std;
 
+const char *Machine_;
+const char *SerialNumber_;
+
 void CfrsError(const char *name, CFReadStreamRef rs) {
     CFStreamError se = CFReadStreamGetError(rs);
 
@@ -1113,9 +1117,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));
@@ -1124,6 +1129,7 @@ int HttpMethod::Loop()
       }
 
       uri.Host = inet_ntoa(* (struct in_addr *) he->h_addr_list[0]);
+#endif
 
       std::string urs = uri;
 
@@ -1148,11 +1154,21 @@ int HttpMethod::Loop()
          CFRelease(sr);
       }
 
+      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);
@@ -1192,7 +1208,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();
@@ -1365,6 +1381,22 @@ 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;
+
+    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();
 }