diff options
author | Jay Freeman (saurik) <saurik@saurik.com> | 2011-02-28 07:22:26 -0800 |
---|---|---|
committer | Jay Freeman (saurik) <saurik@saurik.com> | 2011-03-07 02:41:27 -0800 |
commit | 7256476b3a9d920ad5ac69cf5a824f810103cb34 (patch) | |
tree | 8c5bf7d88aa0db5405f05ccfd4fc5e9e1844c651 /MobileCydia.mm | |
parent | f36e5eacd0fe669ad705b101d984228c1a1d55d0 (diff) |
Factor out diversion logic.
Diffstat (limited to 'MobileCydia.mm')
-rw-r--r-- | MobileCydia.mm | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/MobileCydia.mm b/MobileCydia.mm index 6c6719a..3e0d16a 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -4067,6 +4067,8 @@ static NSString *Warning_; @end /* }}} */ +static NSMutableSet *Diversions_; + @interface Diversion : NSObject { Pcre pattern_; _H<NSString> key_; @@ -4089,6 +4091,19 @@ static NSString *Warning_; return !pattern_(url) ? nil : pattern_->*format_; } ++ (NSURL *) divertURL:(NSURL *)url { + divert: + NSString *href([url absoluteString]); + + for (Diversion *diversion in Diversions_) + if (NSString *diverted = [diversion divert:href]) { + url = [NSURL URLWithString:diverted]; + goto divert; + } + + return url; +} + - (NSString *) key { return key_; } @@ -4120,8 +4135,6 @@ static NSString *Warning_; @end -static NSMutableSet *Diversions_; - /* Web Scripting {{{ */ @implementation CydiaObject @@ -4699,15 +4712,7 @@ static NSMutableSet *Diversions_; - (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source { NSMutableURLRequest *copy([[super webView:view resource:resource willSendRequest:request redirectResponse:response fromDataSource:source] mutableCopy]); - divert: - NSURL *url([copy URL]); - NSString *href([url absoluteString]); - - for (Diversion *diversion in Diversions_) - if (NSString *diverted = [diversion divert:href]) { - [copy setURL:[NSURL URLWithString:diverted]]; - goto divert; - } + [copy setURL:[Diversion divertURL:[copy URL]]]; if (System_ != NULL) [copy setValue:System_ forHTTPHeaderField:@"X-System"]; |