1 /* Cydia - iPhone UIKit Front-End for Debian APT
2 * Copyright (C) 2008-2015 Jay Freeman (saurik)
5 /* GNU General Public License, Version 3 {{{ */
7 * Cydia is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
12 * Cydia is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Cydia. If not, see <http://www.gnu.org/licenses/>.
22 #include "CyteKit/UCPlatform.h"
24 #include "CyteKit/URLProtocol.h"
26 #include "iPhonePrivate.h"
27 #include <Menes/ObjectHandle.h>
29 @implementation CyteURLProtocol {
32 + (NSString *) scheme {
36 + (BOOL) canInitWithRequest:(NSURLRequest *)request {
37 NSURL *url([request URL]);
41 auto local([self scheme]);
42 _assert(local != NULL);
44 NSString *scheme([[url scheme] lowercaseString]);
45 if (scheme != nil && [scheme isEqualToString:local])
47 if ([[url absoluteString] hasPrefix:[NSString stringWithFormat:@"about:%@-", local]])
53 + (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request {
57 - (void) _returnPNGWithImage:(UIImage *)icon forRequest:(NSURLRequest *)request {
58 id<NSURLProtocolClient> client([self client]);
60 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]];
62 NSData *data(UIImagePNGRepresentation(icon));
64 NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:@"image/png" expectedContentLength:-1 textEncodingName:nil] autorelease]);
65 [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
66 [client URLProtocol:self didLoadData:data];
67 [client URLProtocolDidFinishLoading:self];
71 - (bool) loadForPath:(NSString *)path ofRequest:(NSURLRequest *)request {
75 - (void) startLoading {
76 id<NSURLProtocolClient> client([self client]);
77 NSURLRequest *request([self request]);
79 NSURL *url([request URL]);
80 NSString *href([url absoluteString]);
81 NSString *scheme([[url scheme] lowercaseString]);
85 if ([scheme isEqualToString:@"cydia"])
86 path = [href substringFromIndex:8];
87 else if ([scheme isEqualToString:@"about"])
88 path = [href substringFromIndex:12];
91 if (![self loadForPath:path ofRequest:request])
92 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]];
95 - (void) stopLoading {