#define _end }
/* }}} */
+#include "Version.h"
#define Cydia_ CYDIA_VERSION
#define lprintf(args...) fprintf(stderr, args)
notify_post("com.saurik.Cydia.status");
}
+static CGFloat CYStatusBarHeight(UIInterfaceOrientation orientation) {
+ CGSize size([[UIApplication sharedApplication] statusBarFrame].size);
+ return UIInterfaceOrientationIsPortrait(orientation) ? size.height : size.width;
+}
+
/* NSForcedOrderingSearch doesn't work on the iPhone */
static const NSStringCompareOptions MatchCompareOptions_ = NSLiteralSearch | NSCaseInsensitiveSearch;
static const NSStringCompareOptions LaxCompareOptions_ = NSNumericSearch | NSDiacriticInsensitiveSearch | NSWidthInsensitiveSearch | NSCaseInsensitiveSearch;
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];
-
- WebView *webview([[webview_ _documentView] webView]);
+- (NSString *) applicationNameForUserAgent {
+ NSString *application([NSString stringWithFormat:@"Cydia/%@", @ Cydia_]);
- 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];
- 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 {
[self resizeForKeyboardBounds:bounds duration:0];
}
+- (void) getKeyboardCurve:(UIViewAnimationCurve *)curve duration:(NSTimeInterval *)duration forNotification:(NSNotification *)notification {
+ if (&UIKeyboardAnimationCurveUserInfoKey == NULL)
+ *curve = UIViewAnimationCurveEaseInOut;
+ else
+ [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:curve];
+
+ if (&UIKeyboardAnimationDurationUserInfoKey == NULL)
+ *duration = 0.3;
+ else
+ [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:duration];
+}
+
- (void) keyboardWillShow:(NSNotification *)notification {
CGRect bounds;
CGPoint center;
- NSTimeInterval duration;
- UIViewAnimationCurve curve;
[[[notification userInfo] objectForKey:UIKeyboardBoundsUserInfoKey] getValue:&bounds];
[[[notification userInfo] objectForKey:UIKeyboardCenterEndUserInfoKey] getValue:¢er];
- [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&curve];
- [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&duration];
+
+ NSTimeInterval duration;
+ UIViewAnimationCurve curve;
+ [self getKeyboardCurve:&curve duration:&duration forNotification:notification];
CGRect kbframe = CGRectMake(round(center.x - bounds.size.width / 2.0), round(center.y - bounds.size.height / 2.0), bounds.size.width, bounds.size.height);
UIViewController *base = self;
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];
}
- (void) keyboardWillHide:(NSNotification *)notification {
NSTimeInterval duration;
UIViewAnimationCurve curve;
- [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&curve];
- [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&duration];
+ [self getKeyboardCurve:&curve duration:&duration forNotification:notification];
[self resizeForKeyboardBounds:CGRectZero 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 {
updatedelegate_ = delegate;
}
-- (CGFloat) statusBarHeight {
- if (UIInterfaceOrientationIsPortrait([self interfaceOrientation])) {
- return [[UIApplication sharedApplication] statusBarFrame].size.height;
- } else {
- return [[UIApplication sharedApplication] statusBarFrame].size.width;
- }
-}
-
- (UIView *) transitionView {
if ([self respondsToSelector:@selector(_transitionView)])
return [self _transitionView];
CGRect barframe([refreshbar_ frame]);
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iPhoneOS_3_0) // XXX: _UIApplicationLinkedOnOrAfter(4)
- barframe.origin.y = [self statusBarHeight];
+ barframe.origin.y = CYStatusBarHeight([self interfaceOrientation]);
else
barframe.origin.y = 0;
- (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
/* }}} */
}
}
- NSLog(@"changes:#%u", changes);
-
UITabBarItem *changesItem = [[[tabbar_ viewControllers] objectAtIndex:2] tabBarItem];
if (changes != 0) {
_trace();
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];
}