#define _end }
/* }}} */
+#include "Version.h"
#define Cydia_ CYDIA_VERSION
#define lprintf(args...) fprintf(stderr, args)
static _H<NSMutableDictionary> SessionData_;
static _H<NSObject> HostConfig_;
static _H<NSMutableSet> BridgedHosts_;
+static _H<NSMutableSet> TokenHosts_;
+static _H<NSMutableSet> InsecureHosts_;
static _H<NSMutableSet> PipelinedHosts_;
static _H<NSMutableSet> CachedURLs_;
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))
[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])
@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
}
- (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;
}
[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;
}
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];
- (void) releaseSubviews {
list_ = nil;
+
+ [super releaseSubviews];
}
- (id) initWithDatabase:(Database *)database {
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];
}
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 {
- (void) releaseSubviews {
list_ = nil;
+
+ [super releaseSubviews];
}
- (id) initWithDatabase:(Database *)database {
- (void) releaseSubviews {
list_ = nil;
+
+ [super releaseSubviews];
}
- (id) initWithDatabase:(Database *)database {
table_ = nil;
ignoredSwitch_ = nil;
subscribedSwitch_ = nil;
+
+ [super releaseSubviews];
}
- (id) initWithDatabase:(Database *)database package:(NSString *)package {
}
- (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
];
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];
}
- (void) releaseSubviews {
list_ = nil;
+
+ [super releaseSubviews];
}
- (id) initWithDatabase:(Database *)database {
table_ = nil;
segment_ = nil;
container_ = nil;
+
+ [super releaseSubviews];
}
- (id) initWithDatabase:(Database *)database delegate:(id)delegate {
[[self view] addSubview:status_];
}
+- (void) releaseSubviews {
+ spinner_ = nil;
+ status_ = nil;
+ caption_ = nil;
+
+ [super releaseSubviews];
+}
+
@end
/* }}} */
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];
}