X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/d458596e0138c5094097a45442828cbc087be403..947a8eefa4cc11fbccdb9b1495ec0f0f28663bd9:/MobileCydia.mm diff --git a/MobileCydia.mm b/MobileCydia.mm index 5c657a86..05486472 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -120,12 +120,14 @@ extern "C" { #include +#include "Menes/Menes.h" + #include "CyteKit/PerlCompatibleRegEx.hpp" #include "CyteKit/WebScriptObject-Cyte.h" #include "CyteKit/WebViewController.h" #include "CyteKit/stringWithUTF8Bytes.h" -#include "Menes/Menes.h" +#include "Cydia/ProgressEvent.h" #include "SDURLCache/SDURLCache.h" @@ -271,57 +273,6 @@ static _finline void UpdateExternalStatus(uint64_t newStatus) { notify_post("com.saurik.Cydia.status"); } - -/* Cydia Alert View {{{ */ -@interface CYAlertView : UIAlertView { - unsigned button_; -} - -- (int) yieldToPopupAlertAnimated:(BOOL)animated; - -@end - -@implementation CYAlertView - -- (id) initWithTitle:(NSString *)title buttons:(NSArray *)buttons defaultButtonIndex:(int)index { - if ((self = [super init]) != nil) { - [self setTitle:title]; - [self setDelegate:self]; - for (NSString *button in buttons) [self addButtonWithTitle:button]; - [self setCancelButtonIndex:index]; - } return self; -} - -- (void) _updateFrameForDisplay { - [super _updateFrameForDisplay]; - if ([self cancelButtonIndex] == -1) { - NSArray *buttons = [self buttons]; - if ([buttons count]) { - UIImage *background = [[buttons objectAtIndex:0] backgroundForState:0]; - for (UIThreePartButton *button in buttons) - [button setBackground:background forState:0]; - } - } -} - -- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { - button_ = buttonIndex + 1; -} - -- (void) dismiss { - [self dismissWithClickedButtonIndex:-1 animated:YES]; -} - -- (int) yieldToPopupAlertAnimated:(BOOL)animated { - [self setRunsModal:YES]; - button_ = 0; - [self show]; - return button_; -} - -@end -/* }}} */ - /* NSForcedOrderingSearch doesn't work on the iPhone */ static const NSStringCompareOptions MatchCompareOptions_ = NSLiteralSearch | NSCaseInsensitiveSearch; static const NSStringCompareOptions LaxCompareOptions_ = NSNumericSearch | NSDiacriticInsensitiveSearch | NSWidthInsensitiveSearch | NSCaseInsensitiveSearch; @@ -508,21 +459,6 @@ void CFArrayInsertionSortValues(CFMutableArrayRef array, CFRange range, CFCompar @end /* }}} */ -@interface NSInvocation (Cydia) -+ (NSInvocation *) invocationWithSelector:(SEL)selector forTarget:(id)target; -@end - -@implementation NSInvocation (Cydia) - -+ (NSInvocation *) invocationWithSelector:(SEL)selector forTarget:(id)target { - NSInvocation *invocation([NSInvocation invocationWithMethodSignature:[target methodSignatureForSelector:selector]]); - [invocation setTarget:target]; - [invocation setSelector:selector]; - return invocation; -} - -@end - NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *self, SEL sel, NSFastEnumerationState *state, id *objects, NSUInteger count) { size_t length([self length] - state->state); if (length <= 0) @@ -1003,6 +939,34 @@ bool isSectionVisible(NSString *section) { return hidden == nil || ![hidden boolValue]; } +static id CYIOGetValue(const char *path, NSString *property) { + io_registry_entry_t entry(IORegistryEntryFromPath(kIOMasterPortDefault, path)); + if (entry == MACH_PORT_NULL) + return nil; + + CFTypeRef value(IORegistryEntryCreateCFProperty(entry, (CFStringRef) property, kCFAllocatorDefault, 0)); + IOObjectRelease(entry); + + if (value == NULL) + return nil; + return [(id) value autorelease]; +} + +static NSString *CYHex(NSData *data, bool reverse, bool capital) { + if (data == nil) + return nil; + + size_t length([data length]); + uint8_t bytes[length]; + [data getBytes:bytes]; + + char string[length * 2 + 1]; + for (size_t i(0); i != length; ++i) + sprintf(string + i * 2, capital ? "%.2X" : "%.2x", bytes[reverse ? length - i - 1 : i]); + + return [NSString stringWithUTF8String:string]; +} + @class Cydia; /* Delegate Prototypes {{{ */ @@ -1035,57 +999,12 @@ bool isSectionVisible(NSString *section) { - (void) showSettings; - (UIProgressHUD *) addProgressHUD; - (void) removeProgressHUD:(UIProgressHUD *)hud; -- (CYViewController *) pageForPackage:(NSString *)name; +- (CyteViewController *) pageForPackage:(NSString *)name; - (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item; - (void) reloadDataWithInvocation:(NSInvocation *)invocation; @end /* }}} */ -/* ProgressEvent Interface/Delegate {{{ */ -@interface CydiaProgressEvent : NSObject { - _H message_; - _H type_; - - _H item_; - _H package_; - _H url_; - _H version_; -} - -+ (CydiaProgressEvent *) eventWithMessage:(NSString *)message ofType:(NSString *)type; -+ (CydiaProgressEvent *) eventWithMessage:(NSString *)message ofType:(NSString *)type forPackage:(NSString *)package; -+ (CydiaProgressEvent *) eventWithMessage:(NSString *)message ofType:(NSString *)type forItem:(pkgAcquire::ItemDesc &)item; - -- (id) initWithMessage:(NSString *)message ofType:(NSString *)type; - -- (NSString *) message; -- (NSString *) type; - -- (NSArray *) item; -- (NSString *) package; -- (NSString *) url; -- (NSString *) version; - -- (void) setItem:(NSArray *)item; -- (void) setPackage:(NSString *)package; -- (void) setURL:(NSString *)url; -- (void) setVersion:(NSString *)version; - -- (NSString *) compound:(NSString *)value; -- (NSString *) compoundMessage; -- (NSString *) compoundTitle; - -@end - -@protocol ProgressDelegate -- (void) addProgressEvent:(CydiaProgressEvent *)event; -- (void) setProgressPercent:(NSNumber *)percent; -- (void) setProgressStatus:(NSDictionary *)status; -- (void) setProgressCancellable:(NSNumber *)cancellable; -- (bool) isProgressCancelled; -- (void) setTitle:(NSString *)title; -@end -/* }}} */ /* Status Delegation {{{ */ class Status : public pkgAcquireStatus @@ -4064,14 +3983,14 @@ static NSMutableSet *Diversions_; if (false); else if (selector == @selector(addBridgedHost:)) return @"addBridgedHost"; + else if (selector == @selector(addInternalRedirect::)) + return @"addInternalRedirect"; else if (selector == @selector(addPipelinedHost:scheme:)) return @"addPipelinedHost"; else if (selector == @selector(addTrivialSource:)) return @"addTrivialSource"; else if (selector == @selector(close)) return @"close"; - else if (selector == @selector(divert::)) - return @"divert"; else if (selector == @selector(du:)) return @"du"; else if (selector == @selector(stringWithFormat:arguments:)) @@ -4148,7 +4067,7 @@ static NSMutableSet *Diversions_; return [feature isEqualToString:@"window.open"]; } -- (void) divert:(NSString *)from :(NSString *)to { +- (void) addInternalRedirect:(NSString *)from :(NSString *)to { [CydiaWebViewController performSelectorOnMainThread:@selector(addDiversion:) withObject:[[[Diversion alloc] initWithFrom:from to:to] autorelease] waitUntilDone:NO]; } @@ -4490,7 +4409,7 @@ static NSMutableSet *Diversions_; @end /* }}} */ /* Emulated Loading Controller {{{ */ -@interface CYEmulatedLoadingController : CYViewController { +@interface CYEmulatedLoadingController : CyteViewController { _transient Database *database_; _H indicator_; _H tabbar_; @@ -5211,7 +5130,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (UIBarButtonItem *) rightButton { - return [[progress_ running] boolValue] ? nil : [[[UIBarButtonItem alloc] + return [[progress_ running] boolValue] ? [super rightButton] : [[[UIBarButtonItem alloc] initWithTitle:UCLocalize("CLOSE") style:UIBarButtonItemStylePlain target:self @@ -5795,7 +5714,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* File Table {{{ */ -@interface FileTable : CYViewController < +@interface FileTable : CyteViewController < UITableViewDataSource, UITableViewDelegate > { @@ -6099,7 +6018,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* Package List Controller {{{ */ -@interface PackageListController : CYViewController < +@interface PackageListController : CyteViewController < UITableViewDataSource, UITableViewDelegate > { @@ -6495,7 +6414,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [alert setCancelButtonIndex:0]; [alert setMessage: - @"Copyright (C) 2008-2011\n" + @"Copyright \u00a9 2008-2011\n" + "SaurikIT, LLC\n" + "\n" "Jay Freeman (saurik)\n" "saurik@saurik.com\n" "http://www.saurik.com/" @@ -6551,46 +6472,31 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { target:self action:@selector(settingsButtonClicked) ] autorelease]]; - - [self queueStatusDidChange]; } - (void) settingsButtonClicked { [delegate_ showSettings]; } -#if !AlwaysReload - (void) queueButtonClicked { [delegate_ queue]; } -- (void) applyLoadingTitle { - // Disable "Loading" title. -} - -- (void) applyRightButton { - // Disable right button. +- (UIBarButtonItem *) customButton { + return Queuing_ ? [[[UIBarButtonItem alloc] + initWithTitle:UCLocalize("QUEUE") + style:UIBarButtonItemStyleDone + target:self + action:@selector(queueButtonClicked) + ] autorelease] : [super customButton]; } -#endif - (void) queueStatusDidChange { -#if !AlwaysReload - if (!IsWildcat_ && Queuing_) { - [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc] - initWithTitle:UCLocalize("QUEUE") - style:UIBarButtonItemStyleDone - target:self - action:@selector(queueButtonClicked) - ] autorelease]]; - } else { - [[self navigationItem] setRightBarButtonItem:nil]; - } -#endif + [self applyRightButton]; } - (bool) isLoading { - // Never show as loading. - return false; + return !Queuing_ && [super isLoading]; } @end @@ -7024,7 +6930,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (NSArray *) navigationURLCollection { NSMutableArray *stack([NSMutableArray array]); - for (CYViewController *controller in [self viewControllers]) { + for (CyteViewController *controller in [self viewControllers]) { NSString *url = [[controller navigationURL] absoluteString]; if (url != nil) [stack addObject:url]; @@ -7041,7 +6947,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) unloadData { - for (CYViewController *page in [self viewControllers]) + for (CyteViewController *page in [self viewControllers]) [page unloadData]; [super unloadData]; @@ -7199,7 +7105,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Sections Controller {{{ */ -@interface SectionsController : CYViewController < +@interface SectionsController : CyteViewController < UITableViewDataSource, UITableViewDelegate > { @@ -7409,7 +7315,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* Changes Controller {{{ */ -@interface ChangesController : CYViewController < +@interface ChangesController : CyteViewController < UITableViewDataSource, UITableViewDelegate > { @@ -7742,7 +7648,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Package Settings Controller {{{ */ -@interface PackageSettingsController : CYViewController < +@interface PackageSettingsController : CyteViewController < UITableViewDataSource, UITableViewDelegate > { @@ -8136,7 +8042,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Sources Controller {{{ */ -@interface SourcesController : CYViewController < +@interface SourcesController : CyteViewController < UITableViewDataSource, UITableViewDelegate > { @@ -8593,7 +8499,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* Settings Controller {{{ */ -@interface SettingsController : CYViewController < +@interface SettingsController : CyteViewController < UITableViewDataSource, UITableViewDelegate > { @@ -8793,7 +8699,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Stash Controller {{{ */ -@interface StashController : CYViewController { +@interface StashController : CyteViewController { UIActivityIndicatorView *spinner_; UILabel *status_; UILabel *caption_; @@ -8867,6 +8773,35 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ +@interface CYURLCache : SDURLCache { +} + +@end + +@implementation CYURLCache + +- (void) logEvent:(NSString *)event forRequest:(NSURLRequest *)request { +#if !ForRelease + if (false); + else if ([event isEqualToString:@"no-cache"]) + event = @"!!!"; + else if ([event isEqualToString:@"store"]) + event = @">>>"; + else if ([event isEqualToString:@"invalid"]) + event = @"???"; + else if ([event isEqualToString:@"memory"]) + event = @"mem"; + else if ([event isEqualToString:@"disk"]) + event = @"ssd"; + else if ([event isEqualToString:@"miss"]) + event = @"---"; + + NSLog(@"%@: %@", event, [[request URL] absoluteString]); +#endif +} + +@end + @interface Cydia : UIApplication < ConfirmationControllerDelegate, DatabaseDelegate, @@ -9461,11 +9396,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [window_ setUserInteractionEnabled:YES]; } -- (CYViewController *) pageForPackage:(NSString *)name { +- (CyteViewController *) pageForPackage:(NSString *)name { return [[[CYPackageController alloc] initWithDatabase:database_ forPackage:name] autorelease]; } -- (CYViewController *) pageForURL:(NSURL *)url forExternal:(BOOL)external { +- (CyteViewController *) pageForURL:(NSURL *)url forExternal:(BOOL)external { NSString *scheme([[url scheme] lowercaseString]); if ([[url absoluteString] length] <= [scheme length] + 3) return nil; @@ -9480,7 +9415,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { NSString *base([components objectAtIndex:0]); - CYViewController *controller = nil; + CyteViewController *controller = nil; if ([base isEqualToString:@"url"]) { // This kind of URL can contain slashes in the argument, so we can't parse them below. @@ -9566,7 +9501,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (BOOL) openCydiaURL:(NSURL *)url forExternal:(BOOL)external { - CYViewController *page([self pageForURL:url forExternal:external]); + CyteViewController *page([self pageForURL:url forExternal:external]); if (page != nil) { UINavigationController *nav = [[[UINavigationController alloc] init] autorelease]; @@ -9694,7 +9629,7 @@ _trace(); [BridgedHosts_ addObject:[[NSURL URLWithString:CydiaURL(@"")] host]]; } - [NSURLCache setSharedURLCache:[[[SDURLCache alloc] + [NSURLCache setSharedURLCache:[[[CYURLCache alloc] initWithMemoryCapacity:524288 diskCapacity:10485760 diskPath:[NSString stringWithFormat:@"%@/Library/Caches/com.saurik.Cydia/SDURLCache", @"/var/root"] @@ -9704,6 +9639,9 @@ _trace(); [NSURLProtocol registerClass:[CydiaURLProtocol class]]; + // this would disallow http{,s} URLs from accessing this data + //[WebView registerURLSchemeAsLocal:@"cydia"]; + Font12_ = [[UIFont systemFontOfSize:12] retain]; Font12Bold_ = [[UIFont boldSystemFontOfSize:12] retain]; Font14_ = [[UIFont systemFontOfSize:14] retain]; @@ -9836,7 +9774,7 @@ _trace(); for (unsigned int nav = 0; nav < [stack count]; nav++) { NSString *addr = [stack objectAtIndex:nav]; NSURL *url = [NSURL URLWithString:addr]; - CYViewController *page = [self pageForURL:url forExternal:NO]; + CyteViewController *page = [self pageForURL:url forExternal:NO]; if (page != nil) [current addObject:page]; } @@ -10133,28 +10071,8 @@ int main(int argc, char *argv[]) { _pooled else 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_ = [NSString stringWithString:(NSString *)serial]; - CFRelease(serial); - } - - if (CFTypeRef ecid = IORegistryEntrySearchCFProperty(service, kIODeviceTreePlane, CFSTR("unique-chip-id"), kCFAllocatorDefault, kIORegistryIterateRecursively)) { - NSData *data((NSData *) ecid); - size_t length([data length]); - uint8_t bytes[length]; - [data getBytes:bytes]; - char string[length * 2 + 1]; - for (size_t i(0); i != length; ++i) - sprintf(string + i * 2, "%.2X", bytes[length - i - 1]); - ChipID_ = [NSString stringWithUTF8String:string]; - CFRelease(ecid); - } - - IOObjectRelease(service); - } - } + SerialNumber_ = CYIOGetValue("IOService:/", @"IOPlatformSerialNumber"); + ChipID_ = CYHex(CYIOGetValue("IODeviceTree:/chosen", @"unique-chip-id"), true, true); UniqueID_ = [[UIDevice currentDevice] uniqueIdentifier];