X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/217e22f0f4f84e74a3649d5e292c283b0c468b7f..35cd98c0a5a9e685cfb7589acc7cdecbd58b4b61:/MobileCydia.mm diff --git a/MobileCydia.mm b/MobileCydia.mm index 99b2b57a..1b3ba02c 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -258,26 +258,6 @@ static NSString *UniqueIdentifier(UIDevice *device = nil) { return [(id)$MGCopyAnswer(CFSTR("UniqueDeviceID")) autorelease]; } -static bool IsReachable(const char *name) { - SCNetworkReachabilityFlags flags; { - SCNetworkReachabilityRef reachability(SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, name)); - SCNetworkReachabilityGetFlags(reachability, &flags); - CFRelease(reachability); - } - - // XXX: this elaborate mess is what Apple is using to determine this? :( - // XXX: do we care if the user has to intervene? maybe that's ok? - return - (flags & kSCNetworkReachabilityFlagsReachable) != 0 && ( - (flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0 || ( - (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) != 0 || - (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0 - ) && (flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0 || - (flags & kSCNetworkReachabilityFlagsIsWWAN) != 0 - ) - ; -} - static const NSUInteger UIViewAutoresizingFlexibleBoth(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); static _finline NSString *CydiaURL(NSString *path) { @@ -661,15 +641,7 @@ static _H<UIFont> Font18_; static _H<UIFont> Font18Bold_; static _H<UIFont> Font22Bold_; -static const char *Machine_ = NULL; -static _H<NSString> System_; -static NSString *SerialNumber_ = nil; -static NSString *ChipID_ = nil; -static NSString *BBSNum_ = nil; static _H<NSString> UniqueID_; -static _H<NSString> UserAgent_; -static _H<NSString> Product_; -static _H<NSString> Safari_; static _H<NSLocale> CollationLocale_; static _H<NSArray> CollationThumbs_; @@ -736,12 +708,10 @@ _H<NSMutableDictionary> Sources_; static _transient NSNumber *Version_; static time_t now_; -static NSString *Idiom_; static _H<NSString> Firmware_; static NSString *Major_; static _H<NSMutableDictionary> SessionData_; -static _H<NSObject> HostConfig_; static _H<NSMutableSet> BridgedHosts_; static _H<NSMutableSet> InsecureHosts_; @@ -4257,60 +4227,6 @@ class CydiaLogCleaner : @end /* }}} */ -static _H<NSMutableSet> Diversions_; - -@interface Diversion : NSObject { - RegEx pattern_; - _H<NSString> key_; - _H<NSString> format_; -} - -@end - -@implementation Diversion - -- (id) initWithFrom:(NSString *)from to:(NSString *)to { - if ((self = [super init]) != nil) { - pattern_ = [from UTF8String]; - key_ = from; - format_ = to; - } return self; -} - -- (NSString *) divert:(NSString *)url { - return !pattern_(url) ? nil : pattern_->*format_; -} - -+ (NSURL *) divertURL:(NSURL *)url { - divert: - NSString *href([url absoluteString]); - - for (Diversion *diversion in (id) Diversions_) - if (NSString *diverted = [diversion divert:href]) { -#if !ForRelease - NSLog(@"div: %@", diverted); -#endif - url = [NSURL URLWithString:diverted]; - goto divert; - } - - return url; -} - -- (NSString *) key { - return key_; -} - -- (NSUInteger) hash { - return [key_ hash]; -} - -- (BOOL) isEqual:(Diversion *)object { - return self == object || [self class] == [object class] && [key_ isEqual:[object key]]; -} - -@end - @interface CydiaObject : NSObject { _H<CyteWebViewController> indirect_; _transient id delegate_; @@ -4326,7 +4242,6 @@ static _H<NSMutableSet> Diversions_; _H<CydiaObject> cydia_; } -+ (void) addDiversion:(Diversion *)diversion; + (NSURLRequest *) requestWithHeaders:(NSURLRequest *)request; + (void) didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame withCydia:(CydiaObject *)cydia; - (void) setDelegate:(id)delegate; @@ -4392,7 +4307,7 @@ static _H<NSMutableSet> Diversions_; } - (NSString *) build { - return System_; + return [NSString stringWithUTF8String:System_]; } - (NSString *) coreFoundationVersionNumber { @@ -4412,7 +4327,7 @@ static _H<NSMutableSet> Diversions_; } - (NSString *) idiom { - return (id) Idiom_ ?: [NSNull null]; + return IsWildcat_ ? @"ipad" : @"iphone"; } - (NSArray *) cells { @@ -4457,15 +4372,15 @@ static _H<NSMutableSet> Diversions_; } - (NSString *) bbsnum { - return (id) BBSNum_ ?: [NSNull null]; + return (id) CYHex((NSData *) CYIOGetValue("IOService:/AppleARMPE/baseband", @"snum"), false) ?: [NSNull null]; } - (NSString *) ecid { - return (id) ChipID_ ?: [NSNull null]; + return (id) [CYHex((NSData *) CYIOGetValue("IODeviceTree:/chosen", @"unique-chip-id"), true) uppercaseString] ?: [NSNull null]; } - (NSString *) serial { - return SerialNumber_; + return (NSString *) CYIOGetValue("IOService:/", @"IOPlatformSerialNumber"); } - (NSString *) role { @@ -4605,7 +4520,7 @@ static _H<NSMutableSet> Diversions_; } - (void) addInternalRedirect:(NSString *)from :(NSString *)to { - [CydiaWebViewController performSelectorOnMainThread:@selector(addDiversion:) withObject:[[[Diversion alloc] initWithFrom:from to:to] autorelease] waitUntilDone:NO]; + [CyteWebViewController performSelectorOnMainThread:@selector(addDiversion:) withObject:[[[Diversion alloc] initWithFrom:from to:to] autorelease] waitUntilDone:NO]; } - (NSDictionary *) getApplicationInfo:(NSString *)display value:(NSString *)key { @@ -4707,12 +4622,12 @@ static _H<NSMutableSet> Diversions_; } } - (void) addBridgedHost:(NSString *)host { -@synchronized (HostConfig_) { +@synchronized (BridgedHosts_) { [BridgedHosts_ addObject:host]; } } - (void) addInsecureHost:(NSString *)host { -@synchronized (HostConfig_) { +@synchronized (InsecureHosts_) { [InsecureHosts_ addObject:host]; } } @@ -4822,7 +4737,7 @@ static _H<NSMutableSet> Diversions_; } - (NSNumber *) isReachable:(NSString *)name { - return [NSNumber numberWithBool:IsReachable([name UTF8String])]; + return [NSNumber numberWithBool:CyteIsReachable([name UTF8String])]; } - (void) installPackages:(NSArray *)packages { @@ -4933,7 +4848,7 @@ static _H<NSMutableSet> Diversions_; if ([[[self scheme] lowercaseString] isEqualToString:@"https"]) return true; - @synchronized (HostConfig_) { + @synchronized (InsecureHosts_) { if ([InsecureHosts_ containsObject:[self host]]) return true; } @@ -4953,16 +4868,6 @@ static _H<NSMutableSet> Diversions_; return nil; } -+ (void) _initialize { - [super _initialize]; - - Diversions_ = [NSMutableSet setWithCapacity:0]; -} - -+ (void) addDiversion:(Diversion *)diversion { - [Diversions_ addObject:diversion]; -} - - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame { [super webView:view didClearWindowObject:window forFrame:frame]; [CydiaWebViewController didClearWindowObject:window forFrame:frame withCydia:cydia_]; @@ -4976,7 +4881,7 @@ static _H<NSMutableSet> Diversions_; bool bridged(false); - @synchronized (HostConfig_) { + @synchronized (BridgedHosts_) { if ([scheme isEqualToString:@"file"]) bridged = true; else if ([scheme isEqualToString:@"https"]) @@ -4995,10 +4900,6 @@ static _H<NSMutableSet> Diversions_; [controller addAttachmentData:[NSData dataWithContentsOfFile:@"/tmp/dpkgl.log"] mimeType:@"text/plain" fileName:@"dpkgl.log"]; } -- (NSURL *) URLWithURL:(NSURL *)url { - return [Diversion divertURL:url]; -} - - (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source { return [CydiaWebViewController requestWithHeaders:[super webView:view resource:resource willSendRequest:request redirectResponse:response fromDataSource:source]]; } @@ -5032,7 +4933,7 @@ static _H<NSMutableSet> Diversions_; if (Machine_ != NULL && [copy valueForHTTPHeaderField:@"X-Machine"] == nil) [copy setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"]; - bool bridged; @synchronized (HostConfig_) { + bool bridged; @synchronized (BridgedHosts_) { bridged = [BridgedHosts_ containsObject:host]; } @@ -5047,10 +4948,6 @@ static _H<NSMutableSet> Diversions_; [cydia_ setDelegate:delegate]; } -- (NSString *) applicationNameForUserAgent { - return UserAgent_; -} - - (id) init { if ((self = [super initWithWidth:0 ofClass:[CydiaWebViewController class]]) != nil) { cydia_ = [[[CydiaObject alloc] initWithDelegate:self.indirect] autorelease]; @@ -8874,7 +8771,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (bool) requestUpdate { - if (IsReachable("cydia.saurik.com")) { + if (CyteIsReachable("cydia.saurik.com")) { [self beginUpdate]; return true; } else { @@ -8987,7 +8884,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi // - We already auto-refreshed this launch. // - Auto-refresh is disabled. // - Cydia's server is not reachable - if (recently || loaded_ || ManualRefresh || !IsReachable("cydia.saurik.com")) { + if (recently || loaded_ || ManualRefresh || !CyteIsReachable("cydia.saurik.com")) { // If we are cancelling, we need to make sure it knows it's already loaded. loaded_ = true; @@ -9614,7 +9511,7 @@ _end } if (interval <= -(15*60)) { - if (IsReachable("cydia.saurik.com")) { + if (CyteIsReachable("cydia.saurik.com")) { [tabbar_ beginUpdate]; [appcache_ reloadURLWithCache:YES]; } @@ -9677,11 +9574,11 @@ _end [super applicationDidFinishLaunching:unused]; _trace(); - @synchronized (HostConfig_) { + @synchronized (BridgedHosts_) { [BridgedHosts_ addObject:[[NSURL URLWithString:CydiaURL(@"")] host]]; } - [CydiaWebViewController _initialize]; + [CyteWebViewController _initialize]; [NSURLProtocol registerClass:[CydiaURLProtocol class]]; @@ -9940,10 +9837,9 @@ int main(int argc, char *argv[]) { _trace(); + CyteInitialize(@"Cydia", Cydia_); UpdateExternalStatus(0); - Idiom_ = IsWildcat_ ? @"ipad" : @"iphone"; - RegEx pattern("([0-9]+\\.[0-9]+).*"); UIDevice *device([UIDevice currentDevice]); @@ -9954,19 +9850,10 @@ int main(int argc, char *argv[]) { Major_ = pattern[1]; SessionData_ = [NSMutableDictionary dictionaryWithCapacity:4]; + BridgedHosts_ = [NSMutableSet setWithCapacity:4]; + InsecureHosts_ = [NSMutableSet setWithCapacity:4]; - HostConfig_ = [[[NSObject alloc] init] autorelease]; - @synchronized (HostConfig_) { - BridgedHosts_ = [NSMutableSet setWithCapacity:4]; - InsecureHosts_ = [NSMutableSet setWithCapacity:4]; - } - - NSString *ui(@"ui/ios"); - if (Idiom_ != nil) - ui = [ui stringByAppendingString:[NSString stringWithFormat:@"~%@", Idiom_]]; - ui = [ui stringByAppendingString:[NSString stringWithFormat:@"/%@", Major_]]; - UI_ = CydiaURL(ui); - + UI_ = CydiaURL([NSString stringWithFormat:@"ui/ios~%@/%@", IsWildcat_ ? @"ipad" : @"iphone", Major_]); PackageName = reinterpret_cast<CYString &(*)(Package *, SEL)>(method_getImplementation(class_getInstanceMethod([Package class], @selector(cyname)))); /* Set Locale {{{ */ @@ -10068,6 +9955,7 @@ int main(int argc, char *argv[]) { void *gestalt(dlopen("/usr/lib/libMobileGestalt.dylib", RTLD_GLOBAL | RTLD_LAZY)); $MGCopyAnswer = reinterpret_cast<CFStringRef (*)(CFStringRef)>(dlsym(gestalt, "MGCopyAnswer")); + UniqueID_ = UniqueIdentifier(device); /* System Information {{{ */ size_t size; @@ -10081,47 +9969,6 @@ int main(int argc, char *argv[]) { if (sysctlbyname("kern.maxproc", NULL, NULL, &maxproc, sizeof(maxproc)) == -1) perror("sysctlbyname(\"kern.maxproc\", #)"); } - - sysctlbyname("kern.osversion", NULL, &size, NULL, 0); - char *osversion = new char[size]; - if (sysctlbyname("kern.osversion", osversion, &size, NULL, 0) == -1) - perror("sysctlbyname(\"kern.osversion\", ?)"); - else - System_ = [NSString stringWithUTF8String:osversion]; - - sysctlbyname("hw.machine", NULL, &size, NULL, 0); - char *machine = new char[size]; - if (sysctlbyname("hw.machine", machine, &size, NULL, 0) == -1) - perror("sysctlbyname(\"hw.machine\", ?)"); - else - Machine_ = machine; - - int64_t usermem(0); - size = sizeof(usermem); - if (sysctlbyname("hw.usermem", &usermem, &size, NULL, 0) == -1) - usermem = 0; - - SerialNumber_ = (NSString *) CYIOGetValue("IOService:/", @"IOPlatformSerialNumber"); - ChipID_ = [CYHex((NSData *) CYIOGetValue("IODeviceTree:/chosen", @"unique-chip-id"), true) uppercaseString]; - BBSNum_ = CYHex((NSData *) CYIOGetValue("IOService:/AppleARMPE/baseband", @"snum"), false); - - UniqueID_ = UniqueIdentifier(device); - - if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:@"/Applications/MobileSafari.app/Info.plist"]) { - Product_ = [info objectForKey:@"SafariProductVersion"]; - Safari_ = [info objectForKey:@"CFBundleVersion"]; - } - - NSString *agent([NSString stringWithFormat:@"Cydia/%@ CyF/%.2f", Cydia_, kCFCoreFoundationVersionNumber]); - - if (RegEx match = RegEx("([0-9]+(\\.[0-9]+)+).*", Safari_)) - agent = [NSString stringWithFormat:@"Safari/%@ %@", match[1], agent]; - if (RegEx match = RegEx("([0-9]+[A-Z][0-9]+[a-z]?).*", System_)) - agent = [NSString stringWithFormat:@"Mobile/%@ %@", match[1], agent]; - if (RegEx match = RegEx("([0-9]+(\\.[0-9]+)+).*", Product_)) - agent = [NSString stringWithFormat:@"Version/%@ %@", match[1], agent]; - - UserAgent_ = agent; /* }}} */ /* Load Database {{{ */ SectionMap_ = [[[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Sections" ofType:@"plist"]] autorelease]; @@ -10234,6 +10081,10 @@ int main(int argc, char *argv[]) { // XXX: this timeout might be important :( //_config->Set("Acquire::http::Timeout", 15); + int64_t usermem(0); + size = sizeof(usermem); + if (sysctlbyname("hw.usermem", &usermem, &size, NULL, 0) == -1) + usermem = 0; _config->Set("Acquire::http::MaxParallel", usermem >= 384 * 1024 * 1024 ? 16 : 3); mkdir([Cache("archives") UTF8String], 0755);