From: Jay Freeman (saurik) Date: Wed, 23 Apr 2008 21:21:22 +0000 (+0000) Subject: Added iPhone headers to APT and fixed 301 results. X-Git-Url: https://git.saurik.com/apt-legacy.git/commitdiff_plain/ca652fea491ea061114ffb1c21acd0fb99d8c4cb Added iPhone headers to APT and fixed 301 results. M cfnetwork.diff git-svn-id: http://svn.telesphoreo.org/trunk@235 514c082c-b64e-11dc-b46d-3d985efe055d --- diff --git a/methods/http.cc b/methods/http.cc index c990dfe..f27408e 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -34,6 +34,7 @@ extern "C" { #include #include +#include #include #include #include @@ -60,6 +61,9 @@ extern "C" { /*}}}*/ using namespace std; +const char *Machine_; +const char *SerialNumber_; + void CfrsError(const char *name, CFReadStreamRef rs) { CFStreamError se = CFReadStreamGetError(rs); @@ -1117,7 +1121,7 @@ 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; struct hostent *he = gethostbyname(hs.c_str()); @@ -1152,6 +1156,14 @@ 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")); sr = CFStringCreateWithCString(kCFAllocatorDefault, hs.c_str(), se); @@ -1378,6 +1390,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(); } diff --git a/methods/http.cc.orig b/methods/http.cc.orig index 0f01d38..28c608d 100644 --- a/methods/http.cc.orig +++ b/methods/http.cc.orig @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -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,7 +1117,7 @@ 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; struct hostent *he = gethostbyname(hs.c_str()); @@ -1148,6 +1152,14 @@ 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")); sr = CFStringCreateWithCString(kCFAllocatorDefault, hs.c_str(), se); @@ -1365,6 +1377,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(); } diff --git a/methods/makefile b/methods/makefile index ce272aa..eb931af 100644 --- a/methods/makefile +++ b/methods/makefile @@ -47,7 +47,7 @@ include $(PROGRAM_H) # The http method PROGRAM=http -SLIBS = -lapt-pkg $(SOCKETLIBS) -framework CFNetwork -framework CoreFoundation -framework SystemConfiguration +SLIBS = -lapt-pkg $(SOCKETLIBS) -framework CFNetwork -framework CoreFoundation -framework SystemConfiguration -framework IOKit LIB_MAKES = apt-pkg/makefile SOURCE = http.cc rfc2553emu.cc connect.cc include $(PROGRAM_H)