From 300a26c1c0cdcc6f86880b6d70e7bdf81d210b4b Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Sat, 4 Mar 2017 20:53:33 -0800 Subject: Move cyte diversions and user agents into CyteKit. --- MobileCydia.mm | 80 +++------------------------------------------------------- 1 file changed, 3 insertions(+), 77 deletions(-) (limited to 'MobileCydia.mm') diff --git a/MobileCydia.mm b/MobileCydia.mm index 99b2b57..a661436 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -667,7 +667,6 @@ static NSString *SerialNumber_ = nil; static NSString *ChipID_ = nil; static NSString *BBSNum_ = nil; static _H UniqueID_; -static _H UserAgent_; static _H Product_; static _H Safari_; @@ -4257,60 +4256,6 @@ class CydiaLogCleaner : @end /* }}} */ -static _H Diversions_; - -@interface Diversion : NSObject { - RegEx pattern_; - _H key_; - _H 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 indirect_; _transient id delegate_; @@ -4326,7 +4271,6 @@ static _H Diversions_; _H cydia_; } -+ (void) addDiversion:(Diversion *)diversion; + (NSURLRequest *) requestWithHeaders:(NSURLRequest *)request; + (void) didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame withCydia:(CydiaObject *)cydia; - (void) setDelegate:(id)delegate; @@ -4605,7 +4549,7 @@ static _H 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 { @@ -4953,16 +4897,6 @@ static _H 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_]; @@ -4995,10 +4929,6 @@ static _H 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]]; } @@ -5047,10 +4977,6 @@ static _H 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]; @@ -9681,7 +9607,7 @@ _trace(); [BridgedHosts_ addObject:[[NSURL URLWithString:CydiaURL(@"")] host]]; } - [CydiaWebViewController _initialize]; + [CyteWebViewController _initialize]; [NSURLProtocol registerClass:[CydiaURLProtocol class]]; @@ -10121,7 +10047,7 @@ int main(int argc, char *argv[]) { if (RegEx match = RegEx("([0-9]+(\\.[0-9]+)+).*", Product_)) agent = [NSString stringWithFormat:@"Version/%@ %@", match[1], agent]; - UserAgent_ = agent; + [CyteWebViewController setApplicationNameForUserAgent:agent]; /* }}} */ /* Load Database {{{ */ SectionMap_ = [[[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Sections" ofType:@"plist"]] autorelease]; -- cgit v1.2.3