X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/57daa971cb88b48e747968e4279b195fc199c4c8..1d678719bf238263796da048ff173824c5aa05fa:/MobileCydia.mm diff --git a/MobileCydia.mm b/MobileCydia.mm index 23a94029..776c31ce 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -206,6 +206,7 @@ void PrintTimes() { #define _end } /* }}} */ +#include "Version.h" #define Cydia_ CYDIA_VERSION #define lprintf(args...) fprintf(stderr, args) @@ -708,6 +709,8 @@ static NSString *Idiom_; static _H SessionData_; static _H HostConfig_; static _H BridgedHosts_; +static _H TokenHosts_; +static _H InsecureHosts_; static _H PipelinedHosts_; static _H CachedURLs_; @@ -3836,10 +3839,14 @@ static _H Diversions_; if (false); else if (selector == @selector(addBridgedHost:)) return @"addBridgedHost"; + else if (selector == @selector(addInsecureHost:)) + return @"addInsecureHost"; else if (selector == @selector(addInternalRedirect::)) return @"addInternalRedirect"; else if (selector == @selector(addPipelinedHost:scheme:)) return @"addPipelinedHost"; + else if (selector == @selector(addTokenHost:)) + return @"addTokenHost"; else if (selector == @selector(addTrivialSource:)) return @"addTrivialSource"; else if (selector == @selector(close)) @@ -3994,6 +4001,16 @@ static _H Diversions_; [BridgedHosts_ addObject:host]; } } +- (void) addInsecureHost:(NSString *)host { +@synchronized (HostConfig_) { + [InsecureHosts_ addObject:host]; +} } + +- (void) addTokenHost:(NSString *)host { +@synchronized (HostConfig_) { + [TokenHosts_ addObject:host]; +} } + - (void) addPipelinedHost:(NSString *)host scheme:(NSString *)scheme { @synchronized (HostConfig_) { if (scheme != (id) [WebUndefined undefined]) @@ -4212,6 +4229,24 @@ static _H Diversions_; @end /* }}} */ +@interface NSURL (CydiaSecure) +@end + +@implementation NSURL (CydiaSecure) + +- (bool) isCydiaSecure { + if ([[[self scheme] lowercaseString] isEqualToString:@"https"]) + return true; + + @synchronized (HostConfig_) { + if ([InsecureHosts_ containsObject:[self host]]) + return true; + } + + return false; +} + +@end /* Cydia Browser Controller {{{ */ @implementation CydiaWebViewController @@ -4262,14 +4297,25 @@ static _H Diversions_; } - (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source { + NSURL *url([request URL]); + NSString *host([url host]); + NSMutableURLRequest *copy([[super webView:view resource:resource willSendRequest:request redirectResponse:response fromDataSource:source] mutableCopy]); - if (System_ != NULL) + if (System_ != NULL && [copy valueForHTTPHeaderField:@"X-System"] == nil) [copy setValue:System_ forHTTPHeaderField:@"X-System"]; - if (Machine_ != NULL) + if (Machine_ != NULL && [copy valueForHTTPHeaderField:@"X-Machine"] == nil) [copy setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"]; - if (Token_ != nil) - [copy setValue:Token_ forHTTPHeaderField:@"X-Cydia-Token"]; + + bool token; + @synchronized (HostConfig_) { + token = [TokenHosts_ containsObject:host] || [BridgedHosts_ containsObject:host]; + } + + if ([url isCydiaSecure] && token) { + if (Token_ != nil && [copy valueForHTTPHeaderField:@"X-Cydia-Token"] == nil) + [copy setValue:Token_ forHTTPHeaderField:@"X-Cydia-Token"]; + } return copy; } @@ -4279,22 +4325,22 @@ static _H Diversions_; [cydia_ setDelegate:delegate]; } -- (id) init { - if ((self = [super initWithWidth:0 ofClass:[CydiaWebViewController class]]) != nil) { - cydia_ = [[[CydiaObject alloc] initWithDelegate:indirect_] autorelease]; +- (NSString *) applicationNameForUserAgent { + NSString *application([NSString stringWithFormat:@"Cydia/%@", @ Cydia_]); - WebView *webview([[webview_ _documentView] webView]); + if (Safari_ != nil) + application = [NSString stringWithFormat:@"Safari/%@ %@", Safari_, application]; + if (Build_ != nil) + application = [NSString stringWithFormat:@"Mobile/%@ %@", Build_, application]; + if (Product_ != nil) + application = [NSString stringWithFormat:@"Version/%@ %@", Product_, application]; - NSString *application([NSString stringWithFormat:@"Cydia/%@", @ Cydia_]); - - if (Safari_ != nil) - application = [NSString stringWithFormat:@"Safari/%@ %@", Safari_, application]; - if (Build_ != nil) - application = [NSString stringWithFormat:@"Mobile/%@ %@", Build_, application]; - if (Product_ != nil) - application = [NSString stringWithFormat:@"Version/%@ %@", Product_, application]; + return application; +} - [webview setApplicationNameForUserAgent:application]; +- (id) init { + if ((self = [super initWithWidth:0 ofClass:[CydiaWebViewController class]]) != nil) { + cydia_ = [[[CydiaObject alloc] initWithDelegate:indirect_] autorelease]; } return self; } @@ -5092,12 +5138,19 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { Source *source = [package source]; icon_ = [package icon]; - name_ = [package name]; - if (IsWildcat_) - description_ = [package longDescription]; - if (description_ == nil) - description_ = [package shortDescription]; + if (NSString *name = [package name]) + name_ = [NSString stringWithString:name]; + + NSString *description(nil); + + if (description == nil && IsWildcat_) + description = [package longDescription]; + if (description == nil) + description = [package shortDescription]; + + if (description != nil) + description_ = [NSString stringWithString:description]; commercial_ = [package isCommercial]; @@ -5438,6 +5491,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) releaseSubviews { list_ = nil; + + [super releaseSubviews]; } - (id) initWithDatabase:(Database *)database { @@ -5747,6 +5802,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { CGRect viewframe = [[base view] convertRect:[list_ frame] fromView:[list_ superview]]; CGRect intersection = CGRectIntersection(viewframe, kbframe); + if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) // XXX: _UIApplicationLinkedOnOrAfter(4) + intersection.size.height += CYStatusBarHeight([self interfaceOrientation]); + [self resizeForKeyboardBounds:intersection duration:duration curve:curve]; } @@ -5871,19 +5929,29 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { packages_ = [NSArray array]; sections_ = [NSMutableArray arrayWithCapacity:16]; + } return self; +} - list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain] autorelease]; - [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [[self view] addSubview:list_]; +- (void) loadView { + [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]]; - // XXX: is 20 the most optimal number here? - [list_ setSectionIndexMinimumDisplayRowCount:20]; + list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain] autorelease]; + [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [[self view] addSubview:list_]; - [(UITableView *) list_ setDataSource:self]; - [list_ setDelegate:self]; + // XXX: is 20 the most optimal number here? + [list_ setSectionIndexMinimumDisplayRowCount:20]; - [self updateHeight]; - } return self; + [(UITableView *) list_ setDataSource:self]; + [list_ setDelegate:self]; + + [self updateHeight]; +} + +- (void) releaseSubviews { + list_ = nil; + + [super releaseSubviews]; } - (void) setDelegate:(id)delegate { @@ -6929,6 +6997,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) releaseSubviews { list_ = nil; + + [super releaseSubviews]; } - (id) initWithDatabase:(Database *)database { @@ -7106,6 +7176,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) releaseSubviews { list_ = nil; + + [super releaseSubviews]; } - (id) initWithDatabase:(Database *)database { @@ -7535,6 +7607,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { table_ = nil; ignoredSwitch_ = nil; subscribedSwitch_ = nil; + + [super releaseSubviews]; } - (id) initWithDatabase:(Database *)database package:(NSString *)package { @@ -8003,8 +8077,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (NSURLConnection *) _requestHRef:(NSString *)href method:(NSString *)method { + NSURL *url([NSURL URLWithString:href]); + NSMutableURLRequest *request = [NSMutableURLRequest - requestWithURL:[NSURL URLWithString:href] + requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:120.0 ]; @@ -8013,8 +8089,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if (Machine_ != NULL) [request setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"]; - if (UniqueID_ != nil) - [request setValue:UniqueID_ forHTTPHeaderField:@"X-Unique-ID"]; + + if ([url isCydiaSecure]) { + if (UniqueID_ != nil) + [request setValue:UniqueID_ forHTTPHeaderField:@"X-Unique-ID"]; + } return [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease]; } @@ -8096,6 +8175,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) releaseSubviews { list_ = nil; + + [super releaseSubviews]; } - (id) initWithDatabase:(Database *)database { @@ -8259,6 +8340,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { table_ = nil; segment_ = nil; container_ = nil; + + [super releaseSubviews]; } - (id) initWithDatabase:(Database *)database delegate:(id)delegate { @@ -8442,6 +8525,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [[self view] addSubview:status_]; } +- (void) releaseSubviews { + spinner_ = nil; + status_ = nil; + caption_ = nil; + + [super releaseSubviews]; +} + @end /* }}} */ @@ -9631,6 +9722,8 @@ int main(int argc, char *argv[]) { HostConfig_ = [[[NSObject alloc] init] autorelease]; @synchronized (HostConfig_) { BridgedHosts_ = [NSMutableSet setWithCapacity:4]; + TokenHosts_ = [NSMutableSet setWithCapacity:4]; + InsecureHosts_ = [NSMutableSet setWithCapacity:4]; PipelinedHosts_ = [NSMutableSet setWithCapacity:4]; CachedURLs_ = [NSMutableSet setWithCapacity:32]; }